Async mod #1
@ -6,11 +6,16 @@ import java.io.File;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.nemez.cmdmgr.component.ArgumentComponent;
|
import com.nemez.cmdmgr.component.ArgumentComponent;
|
||||||
@ -103,6 +108,7 @@ public class CommandManager {
|
|||||||
|
|
||||||
/* List of all commands that can be invoked async */
|
/* List of all commands that can be invoked async */
|
||||||
public static ArrayList<Executable> asyncExecutables = new ArrayList<Executable>();
|
public static ArrayList<Executable> asyncExecutables = new ArrayList<Executable>();
|
||||||
|
public static HashMap<Object, ArrayList<String>> commands = new HashMap<Object, ArrayList<String>>();
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,6 +188,28 @@ public class CommandManager {
|
|||||||
return registerCommand(src.toString(), commandHandler, plugin);
|
return registerCommand(src.toString(), commandHandler, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void unregisterAll(String[] commands)
|
||||||
|
{
|
||||||
|
for (String name : commands)
|
||||||
|
{
|
||||||
|
EmptyCommand emptyCommand = new EmptyCommand(name);
|
||||||
|
try {
|
||||||
|
final Field cmdMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
|
cmdMap.setAccessible(true);
|
||||||
|
CommandMap map = (CommandMap) cmdMap.get(Bukkit.getServer());
|
||||||
|
final Field knownCommandsField = map.getClass().getDeclaredField("knownCommands");
|
||||||
|
knownCommandsField.setAccessible(true);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Command> knownCommands = (Map<String, Command>) knownCommandsField.get(map);
|
||||||
|
knownCommands.remove(name);
|
||||||
|
map.register(name, emptyCommand);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the source code into an abstract command syntax
|
* Parses the source code into an abstract command syntax
|
||||||
*
|
*
|
||||||
|
20
src/main/java/com/nemez/cmdmgr/EmptyCommand.java
Normal file
20
src/main/java/com/nemez/cmdmgr/EmptyCommand.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.nemez.cmdmgr;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.nemez.cmdmgr.util.Executable;
|
||||||
|
|
||||||
|
public class EmptyCommand extends Executable
|
||||||
|
{
|
||||||
|
public EmptyCommand(String name)
|
||||||
|
{
|
||||||
|
super(name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(CommandSender sender, String name, String[] args_)
|
||||||
|
{
|
||||||
|
sender.sendMessage("§cUnknown command. Use §e/help§c, §e/plugins§c or ask a mod.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user