当前位置: 首页>>代码示例>>Java>>正文


Java CommandExecutor类代码示例

本文整理汇总了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;
}
 
开发者ID:lucko,项目名称:helper,代码行数:32,代码来源:CommandMapUtil.java

示例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;
}
 
开发者ID:lucko,项目名称:helper,代码行数:32,代码来源:CommandMapUtil.java

示例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();
		}
	}
}
 
开发者ID:GelandiAssociation,项目名称:EscapeLag,代码行数:27,代码来源:CommandInjector.java

示例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();
		}
	}
}
 
开发者ID:GelandiAssociation,项目名称:EscapeLag,代码行数:27,代码来源:CommandInjector.java

示例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;
}
 
开发者ID:jiongjionger,项目名称:NeverLag,代码行数:27,代码来源:MonitorUtils.java

示例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);
}
 
开发者ID:HimaJyun,项目名称:BukkitPluginDevelopment,代码行数:21,代码来源:Command.java

示例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);

}
 
开发者ID:ase34,项目名称:flyingblocksapi,代码行数:26,代码来源:ExamplesCommandExecutor.java

示例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!");
}
 
开发者ID:illegalprime,项目名称:Zeus,代码行数:23,代码来源:Zeus.java

示例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;
}
 
开发者ID:GelandiAssociation,项目名称:EscapeLag,代码行数:30,代码来源:MonitorUtils.java

示例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));
}
 
开发者ID:EpticMC,项目名称:Mob-AI,代码行数:10,代码来源:Main.java

示例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);
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:33,代码来源:HiveCommandExecutor.java

示例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());
    });
}
 
开发者ID:Twister915,项目名称:pl,代码行数:40,代码来源:JPl.java

示例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 = "";
}
 
开发者ID:HuliPvP,项目名称:Chambers,代码行数:13,代码来源:BukkitCommand.java

示例14: getExecutor

import org.bukkit.command.CommandExecutor; //导入依赖的package包/类
@Override
public CommandExecutor getExecutor() {
  return (commandSender, command, s, strings) -> {
    commandSender.sendMessage("command is working ~~");
    return true;
  };
}
 
开发者ID:Rires-Magica,项目名称:Bukkit-Utilities,代码行数:8,代码来源:TestCommand.java

示例15: getExecutor

import org.bukkit.command.CommandExecutor; //导入依赖的package包/类
@Override
public CommandExecutor getExecutor() {
  return ((commandSender, command, s, strings) -> {
    commandSender.sendMessage("test2");
    return true;
  });
}
 
开发者ID:Rires-Magica,项目名称:Bukkit-Utilities,代码行数:8,代码来源:TestCommand2.java


注:本文中的org.bukkit.command.CommandExecutor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。