mirror of
				https://e.coding.net/circlecloud/YumCore.git
				synced 2025-11-03 23:06:02 +00:00 
			
		
		
		
	
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@@ -6,7 +6,7 @@
 | 
				
			|||||||
	<version>1.1</version>
 | 
						<version>1.1</version>
 | 
				
			||||||
	<name>YumCore</name>
 | 
						<name>YumCore</name>
 | 
				
			||||||
	<build>
 | 
						<build>
 | 
				
			||||||
		<Name>${project.name}</Name>
 | 
							<finalName>${project.name}</finalName>
 | 
				
			||||||
		<resources>
 | 
							<resources>
 | 
				
			||||||
			<resource>
 | 
								<resource>
 | 
				
			||||||
				<directory>src/main/resources</directory>
 | 
									<directory>src/main/resources</directory>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,8 +36,8 @@ import pw.yumc.YumCore.commands.interfaces.CommandHelpParse;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * 命令管理类
 | 
					 * 命令管理类
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @since 2016年7月23日 上午9:06:03
 | 
					 | 
				
			||||||
 * @author 喵♂呜
 | 
					 * @author 喵♂呜
 | 
				
			||||||
 | 
					 * @since 2016年7月23日 上午9:06:03
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class CommandManager implements TabExecutor {
 | 
					public class CommandManager implements TabExecutor {
 | 
				
			||||||
    private static String argumentTypeError = "注解命令方法 %s 位于 %s 的参数错误 第一个参数应实现 CommandSender 接口!";
 | 
					    private static String argumentTypeError = "注解命令方法 %s 位于 %s 的参数错误 第一个参数应实现 CommandSender 接口!";
 | 
				
			||||||
@@ -45,6 +45,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    private static Constructor<PluginCommand> PluginCommandConstructor;
 | 
					    private static Constructor<PluginCommand> PluginCommandConstructor;
 | 
				
			||||||
    private static Map<String, Command> knownCommands;
 | 
					    private static Map<String, Command> knownCommands;
 | 
				
			||||||
    private static Map<String, Plugin> lookupNames;
 | 
					    private static Map<String, Plugin> lookupNames;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static {
 | 
					    static {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            PluginManager pluginManager = Bukkit.getPluginManager();
 | 
					            PluginManager pluginManager = Bukkit.getPluginManager();
 | 
				
			||||||
@@ -67,6 +68,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
            Log.debug(e);
 | 
					            Log.debug(e);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 插件实例类
 | 
					     * 插件实例类
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@@ -103,8 +105,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 命令管理器
 | 
					     * 命令管理器
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param name
 | 
					     * @param name 注册的命令
 | 
				
			||||||
     *            注册的命令
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public CommandManager(String name) {
 | 
					    public CommandManager(String name) {
 | 
				
			||||||
        cmd = plugin.getCommand(name);
 | 
					        cmd = plugin.getCommand(name);
 | 
				
			||||||
@@ -112,7 +113,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
            try {
 | 
					            try {
 | 
				
			||||||
                knownCommands.put(name, PluginCommandConstructor.newInstance(name, plugin));
 | 
					                knownCommands.put(name, PluginCommandConstructor.newInstance(name, plugin));
 | 
				
			||||||
                lookupNames.put(name, plugin);
 | 
					                lookupNames.put(name, plugin);
 | 
				
			||||||
            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
 | 
					            } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if ((cmd = plugin.getCommand(name)) == null) {
 | 
					            if ((cmd = plugin.getCommand(name)) == null) {
 | 
				
			||||||
                throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!");
 | 
					                throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!");
 | 
				
			||||||
@@ -125,10 +126,8 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 命令管理器
 | 
					     * 命令管理器
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param name
 | 
					     * @param name     注册的命令
 | 
				
			||||||
     *            注册的命令
 | 
					     * @param executor 命令执行类
 | 
				
			||||||
     * @param executor
 | 
					 | 
				
			||||||
     *            命令执行类
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public CommandManager(String name, CommandExecutor... executor) {
 | 
					    public CommandManager(String name, CommandExecutor... executor) {
 | 
				
			||||||
        this(name);
 | 
					        this(name);
 | 
				
			||||||
@@ -169,8 +168,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 通过注解读取命令并注册
 | 
					     * 通过注解读取命令并注册
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param clazzs
 | 
					     * @param clazzs 子命令处理类
 | 
				
			||||||
     *            子命令处理类
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void register(CommandExecutor... clazzs) {
 | 
					    public void register(CommandExecutor... clazzs) {
 | 
				
			||||||
        for (CommandExecutor clazz : clazzs) {
 | 
					        for (CommandExecutor clazz : clazzs) {
 | 
				
			||||||
@@ -189,8 +187,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 设置帮助解析器
 | 
					     * 设置帮助解析器
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param helpParse
 | 
					     * @param helpParse 帮助解析器
 | 
				
			||||||
     *            帮助解析器
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void setHelpParse(CommandHelpParse helpParse) {
 | 
					    public void setHelpParse(CommandHelpParse helpParse) {
 | 
				
			||||||
        help.setHelpParse(helpParse);
 | 
					        help.setHelpParse(helpParse);
 | 
				
			||||||
@@ -211,8 +208,7 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 检查缓存并获得命令
 | 
					     * 检查缓存并获得命令
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param subcmd
 | 
					     * @param subcmd 子命令
 | 
				
			||||||
     *            子命令
 | 
					 | 
				
			||||||
     * @return 命令信息
 | 
					     * @return 命令信息
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private CommandInfo getByCache(String subcmd) {
 | 
					    private CommandInfo getByCache(String subcmd) {
 | 
				
			||||||
@@ -233,14 +229,10 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 获取玩家命令补全
 | 
					     * 获取玩家命令补全
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param sender
 | 
					     * @param sender  命令发送者
 | 
				
			||||||
     *            命令发送者
 | 
					     * @param command 命令
 | 
				
			||||||
     * @param command
 | 
					     * @param alias   别名
 | 
				
			||||||
     *            命令
 | 
					     * @param args    数组
 | 
				
			||||||
     * @param alias
 | 
					 | 
				
			||||||
     *            别名
 | 
					 | 
				
			||||||
     * @param args
 | 
					 | 
				
			||||||
     *            数组
 | 
					 | 
				
			||||||
     * @return 在线玩家数组
 | 
					     * @return 在线玩家数组
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private List<String> getPlayerTabComplete(CommandSender sender, Command command, String alias, String[] args) {
 | 
					    private List<String> getPlayerTabComplete(CommandSender sender, Command command, String alias, String[] args) {
 | 
				
			||||||
@@ -259,10 +251,8 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 转移数组
 | 
					     * 转移数组
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param args
 | 
					     * @param args  原数组
 | 
				
			||||||
     *            原数组
 | 
					     * @param start 数组开始位置
 | 
				
			||||||
     * @param start
 | 
					 | 
				
			||||||
     *            数组开始位置
 | 
					 | 
				
			||||||
     * @return 转移后的数组字符串
 | 
					     * @return 转移后的数组字符串
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private String[] moveStrings(String[] args, int start) {
 | 
					    private String[] moveStrings(String[] args, int start) {
 | 
				
			||||||
@@ -274,10 +264,8 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 注册命令
 | 
					     * 注册命令
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param method
 | 
					     * @param method 方法
 | 
				
			||||||
     *            方法
 | 
					     * @param clazz  调用对象
 | 
				
			||||||
     * @param clazz
 | 
					 | 
				
			||||||
     *            调用对象
 | 
					 | 
				
			||||||
     * @return 是否成功
 | 
					     * @return 是否成功
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean registerCommand(Method method, CommandExecutor clazz) {
 | 
					    private boolean registerCommand(Method method, CommandExecutor clazz) {
 | 
				
			||||||
@@ -302,10 +290,8 @@ public class CommandManager implements TabExecutor {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 注册Tab补全
 | 
					     * 注册Tab补全
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param method
 | 
					     * @param method 方法
 | 
				
			||||||
     *            方法
 | 
					     * @param clazz  调用对象
 | 
				
			||||||
     * @param clazz
 | 
					 | 
				
			||||||
     *            调用对象
 | 
					 | 
				
			||||||
     * @return 是否成功
 | 
					     * @return 是否成功
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private boolean registerTab(Method method, CommandExecutor clazz) {
 | 
					    private boolean registerTab(Method method, CommandExecutor clazz) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -70,7 +70,7 @@ public class CommandParse {
 | 
				
			|||||||
            try {
 | 
					            try {
 | 
				
			||||||
                Parse p = parse.get(i);
 | 
					                Parse p = parse.get(i);
 | 
				
			||||||
                String param = i < args.length ? args[i] : p.def;
 | 
					                String param = i < args.length ? args[i] : p.def;
 | 
				
			||||||
                pobjs.add(param == null ? param : p.parse(cmdArgs.getSender(), param));
 | 
					                pobjs.add(param == null ? null : p.parse(cmdArgs.getSender(), param));
 | 
				
			||||||
            } catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
                Log.debug(e);
 | 
					                Log.debug(e);
 | 
				
			||||||
                throw new CommandParseException(String.format("第 %s 个参数 ", isMain ? 1 : 2 + i) + e.getMessage());
 | 
					                throw new CommandParseException(String.format("第 %s 个参数 ", isMain ? 1 : 2 + i) + e.getMessage());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user