本文整理匯總了Java中org.bukkit.command.CommandExecutor類的典型用法代碼示例。如果您正苦於以下問題:Java CommandExecutor類的具體用法?Java CommandExecutor怎麽用?Java CommandExecutor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommandExecutor類屬於org.bukkit.command包,在下文中一共展示了CommandExecutor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
/**
* Registers a CommandExecutor with the server
*
* @param plugin the plugin instance
* @param command the command instance
* @param aliases the command aliases
* @param <T> the command executor class type
* @return the command executor
*/
@Nonnull
public static <T extends CommandExecutor> T registerCommand(@Nonnull Plugin plugin, @Nonnull T command, @Nonnull String... aliases) {
Preconditions.checkArgument(aliases.length != 0, "No aliases");
for (String alias : aliases) {
try {
PluginCommand cmd = COMMAND_CONSTRUCTOR.newInstance(alias, plugin);
getCommandMap().register(plugin.getDescription().getName(), cmd);
getKnownCommandMap().put(plugin.getDescription().getName().toLowerCase() + ":" + alias.toLowerCase(), cmd);
getKnownCommandMap().put(alias.toLowerCase(), cmd);
cmd.setLabel(alias.toLowerCase());
cmd.setExecutor(command);
if (command instanceof TabCompleter) {
cmd.setTabCompleter((TabCompleter) command);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return command;
}
示例2: unregisterCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
/**
* Unregisters a CommandExecutor with the server
*
* @param command the command instance
* @param <T> the command executor class type
* @return the command executor
*/
@Nonnull
public static <T extends CommandExecutor> T unregisterCommand(@Nonnull T command) {
CommandMap map = getCommandMap();
try {
//noinspection unchecked
Map<String, Command> knownCommands = (Map<String, Command>) KNOWN_COMMANDS_FIELD.get(map);
Iterator<Command> iterator = knownCommands.values().iterator();
while (iterator.hasNext()) {
Command cmd = iterator.next();
if (cmd instanceof PluginCommand) {
CommandExecutor executor = ((PluginCommand) cmd).getExecutor();
if (command == executor) {
cmd.unregister(map);
iterator.remove();
}
}
}
} catch (Exception e) {
throw new RuntimeException("Could not unregister command", e);
}
return command;
}
示例3: inject
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
/**
*
* @author jiongjionger,Vlvxingze
*/
public static void inject(Plugin plg) {
if (plg != null) {
try {
SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandInjector commandInjector = new CommandInjector(plg, commandField.get(pluginCommand), tabField.get(pluginCommand));
commandField.set(pluginCommand, commandInjector);
tabField.set(pluginCommand, commandInjector);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例4: uninject
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
public static void uninject(Plugin plg) {
if (plg != null) {
try {
SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
FieldAccessor<TabCompleter> tabField = Reflection.getField(PluginCommand.class, "completer", TabCompleter.class);
CommandExecutor executor = commandField.get(pluginCommand);
if (executor instanceof CommandInjector) {
commandField.set(pluginCommand, ((CommandInjector) executor).getCommandExecutor());
}
TabCompleter completer = tabField.get(pluginCommand);
if (completer instanceof CommandInjector) {
tabField.set(pluginCommand, ((CommandInjector) executor).getTabCompleter());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例5: getCommandTimingsByPlugin
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
Map<String, MonitorRecord> record = new HashMap<>();
if (plg == null) {
return record;
}
try {
SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
CommandExecutor executor = commandField.get(pluginCommand);
if (executor instanceof CommandInjector) {
CommandInjector commandInjector = (CommandInjector) executor;
record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return record;
}
示例6: onCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
if (0 < args.length) { // 引數がある
// 1つめの引數(args[0])を小文字に変換する(/hoge fugaでも/hoge FUGAでも実行出來る様に)
String subCommand = args[0].toLowerCase(Locale.ENGLISH);
// そのサブコマンドに対応したExecutorを取得する
CommandExecutor executor = sub.get(subCommand);
// 非null == サブコマンドが登録されていたなら実行する
// containsKeyでチェックする必要はない(HashMapのcontainsKey自體がgetして非nullならtrue、みたいな実裝になっている)
if (command != null) {
// 実行して終了する
return executor.onCommand(sender, command, label, args);
}
}
// ここまで來た==サブコマンドがなかったか、登録されていなかった時は
// 引數がない時の処理(helpを表示)を実行する
return sub.get(NO_ARGS).onCommand(sender, command, label, args);
}
示例7: onCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 1) {
return false;
}
String example = args[0];
CommandExecutor executor;
if (example.equalsIgnoreCase("flag")) {
executor = new FlagCommandExecutor();
} else if (example.equalsIgnoreCase("rising")) {
executor = new RisingBlockCommandExecutor();
} else if (example.equalsIgnoreCase("static")) {
executor = new StaticBlockCommandExecutor();
} else if (example.equalsIgnoreCase("sinewave")) {
executor = new SineWaveBlockCommandExecutor();
} else {
return false;
}
String[] newargs = Arrays.copyOfRange(args, 1, args.length);
return executor.onCommand(sender, command, label, newargs);
}
示例8: onDisable
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public void onDisable() {
getCommand("zeus").setExecutor((CommandExecutor)null);
getCommand("autosave").setExecutor((CommandExecutor)null);
getCommand("jailtime").setExecutor((CommandExecutor)null);
getCommand("jail").setExecutor((CommandExecutor)null);
getCommand("invite").setExecutor((CommandExecutor)null);
getCommand("goto").setExecutor((CommandExecutor)null);
getCommand("tactical").setExecutor((CommandExecutor)null);
if (this.WorldEditExists)
getCommand("regionedit").setExecutor((CommandExecutor)null);
this.getServer().getScheduler().cancelTask(this.jailID);
this.getConfig().set("Autosave.enabled", this.autosaveActive);
this.getConfig().set("Autosave.time", this.autosaveTime);
jailMan.saveDATA();
tactical.saveDATA();
checkMan.saveDATA();
this.saveConfig();
getLogger().info("Zeus Data Saved!");
}
示例9: getCommandTimingsByPlugin
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
Map<String, MonitorRecord> record = new HashMap<>();
if (plg == null) {
return record;
}
try {
SimpleCommandMap simpleCommandMap = Reflection
.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class)
.get(Bukkit.getPluginManager());
for (Command command : simpleCommandMap.getCommands()) {
if (command instanceof PluginCommand) {
PluginCommand pluginCommand = (PluginCommand) command;
if (plg.equals(pluginCommand.getPlugin())) {
FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class,
"executor", CommandExecutor.class);
CommandExecutor executor = commandField.get(pluginCommand);
if (executor instanceof CommandInjector) {
CommandInjector commandInjector = (CommandInjector) executor;
record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return record;
}
示例10: onEnable
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
public void onEnable() {
PluginDescriptionFile pdfFile = this.getDescription();
this.logger.info(String.valueOf(String.valueOf(pdfFile.getName())) + " Version: " + pdfFile.getVersion() + " by NullDev [EpticMC] has been enabled!");
this.generateFiles();
instance = this;
String[] cmd = {"mob", "mobai"};
for (int i = 0; i < cmd.length; i++) this.getCommand(cmd[i]).setExecutor((CommandExecutor) new CommandHandler(this));
}
示例11: onCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
CommandExecutor command = null;
for (Entry<String, CommandExecutor> e : commands.entrySet()) {
if (e.getKey().equalsIgnoreCase(cmd.getName())) {
command = e.getValue();
if (e.getValue() instanceof Permissible) {
Permissible perm = (Permissible) e.getValue();
if (perm.hasPermission(Gamer.get(sender))) {
command = e.getValue();
break;
}
else {
Chat.player(sender, "&cYou do not have permission to use that command.");
return true;
}
}
else {
command = e.getValue();
break;
}
}
}
if (command == null) {
return false;
}
return command.onCommand(sender, cmd, label, args);
}
示例12: loadCommands
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private void loadCommands() {
InputStream resource = getResource("META-INF/.pl.commands.yml");
if (resource == null)
return;
yamlParser.parse(resource, CommandsFile.class).blockingGet().getCommands().forEach((command, handler) -> {
PluginCommand bukkitCmd = getCommand(command);
if (bukkitCmd == null)
throw new IllegalStateException("could not find command '" + command + "' for plugin...");
Class<?> handlerType;
try {
handlerType = Class.forName(handler.handler);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("could not find class " + handler + " for command " + command + "!", e);
}
if (!JCmd.class.isAssignableFrom(handlerType)) {
if (!CommandExecutor.class.isAssignableFrom(handlerType))
throw new IllegalStateException(handlerType.getName() + " is not a valid handler class, does not extend JCmd");
CommandExecutor instance = (CommandExecutor) injector.get().getInstance(handlerType);
bukkitCmd.setExecutor(instance);
if (instance instanceof TabCompleter)
bukkitCmd.setTabCompleter((TabCompleter) instance);
} else {
Class<? extends JCmd> commandType = (Class<? extends JCmd>) handlerType;
JCommandExecutor executor = new JCommandExecutor(commandType, injector);
bukkitCmd.setExecutor(executor);
bukkitCmd.setTabCompleter(executor);
}
getLogger().info("loaded command /" + command + " => " + handlerType.getSimpleName());
});
}
示例13: BukkitCommand
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
/**
* A slimmed down PluginCommand
*
* @param name
* @param owner
*/
protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
super(label);
this.executor = executor;
this.owningPlugin = owner;
this.usageMessage = "";
}
示例14: getExecutor
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public CommandExecutor getExecutor() {
return (commandSender, command, s, strings) -> {
commandSender.sendMessage("command is working ~~");
return true;
};
}
示例15: getExecutor
import org.bukkit.command.CommandExecutor; //導入依賴的package包/類
@Override
public CommandExecutor getExecutor() {
return ((commandSender, command, s, strings) -> {
commandSender.sendMessage("test2");
return true;
});
}