下面列出了怎么用org.bukkit.command.defaults.BukkitCommand的API类实例代码及写法,或者点击链接到github查看源代码。
public Collection<BukkitCommand> getRootCommands(){
Collection<BukkitCommand> rootCommands = new ArrayList<>();
for (CommandNode<CommandSender> node : this.dispatcher.getRoot().getChildren()) {
rootCommands.add(new CommandProxy(node.getName()));
}
return rootCommands;
}
private String getCommandPluginName(Command command) {
if (command instanceof VanillaCommandWrapper) {
return "Minecraft";
}
if (command instanceof BukkitCommand) {
return "Bukkit";
}
if (command instanceof PluginIdentifiableCommand) {
return ((PluginIdentifiableCommand) command).getPlugin().getName();
}
return null;
}
private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) {
if ((command instanceof BukkitCommand) && ignoredPlugins.contains("Bukkit")) {
return true;
}
if (command instanceof PluginIdentifiableCommand && ignoredPlugins.contains(((PluginIdentifiableCommand) command).getPlugin().getName())) {
return true;
}
return false;
}
private String getCommandPluginName(Command command) {
if (command instanceof VanillaCommandWrapper) {
return "Minecraft";
}
if (command instanceof BukkitCommand || command instanceof VanillaCommand) {
return "Bukkit";
}
if (command instanceof PluginIdentifiableCommand) {
return ((PluginIdentifiableCommand)command).getPlugin().getName();
}
return null;
}
private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) {
if ((command instanceof BukkitCommand || command instanceof VanillaCommand) && ignoredPlugins.contains("Bukkit")) {
return true;
}
if (command instanceof PluginIdentifiableCommand && ignoredPlugins.contains(((PluginIdentifiableCommand)command).getPlugin().getName())) {
return true;
}
return false;
}
@Override
public void onEnable() {
new MetricsLite(this);
//save world so the level.dat is present on new worlds
Logger.global.logInfo("Saving all worlds once, to make sure the level.dat is present...");
for (World world : getServer().getWorlds()) {
world.save();
}
//register events
getServer().getPluginManager().registerEvents(eventForwarder, this);
//register commands
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
for (BukkitCommand command : commands.getRootCommands()) {
commandMap.register(command.getLabel(), command);
}
} catch(NoSuchFieldException | SecurityException | IllegalAccessException e) {
Logger.global.logError("Failed to register commands!", e);
}
//tab completions
getServer().getPluginManager().registerEvents(commands, this);
//load bluemap
getServer().getScheduler().runTaskAsynchronously(this, () -> {
try {
Logger.global.logInfo("Loading...");
this.bluemap.load();
if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!");
} catch (Throwable t) {
Logger.global.logError("Failed to load!", t);
}
});
}