mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +00:00
feat: 完善主命令处理 优化Log类
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
903f464f4d
commit
022d4ed866
@ -108,7 +108,7 @@ public class Log {
|
|||||||
* @param msg 消息
|
* @param msg 消息
|
||||||
* @param e 异常
|
* @param e 异常
|
||||||
*/
|
*/
|
||||||
public static void debug(String msg, Throwable e) {
|
public static void d(String msg, Throwable e) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
logger.info("[DEBUG] " + msg);
|
logger.info("[DEBUG] " + msg);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -120,7 +120,7 @@ public class Log {
|
|||||||
*
|
*
|
||||||
* @param e 异常
|
* @param e 异常
|
||||||
*/
|
*/
|
||||||
public static void debug(Throwable e) {
|
public static void d(Throwable e) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package pw.yumc.YumCore.bukkit.compatible;
|
package pw.yumc.YumCore.bukkit.compatible;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import org.bukkit.*;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@ -7,17 +12,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bukkit兼容类
|
* Bukkit兼容类
|
||||||
*
|
*
|
||||||
@ -53,7 +47,7 @@ public class C {
|
|||||||
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
|
sendPacket = typePlayerConnection.getMethod("sendPacket", Class.forName(a("Packet")));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning(C.class.getSimpleName() + " 兼容性工具初始化失败 可能造成部分功能不可用!");
|
Log.warning(C.class.getSimpleName() + " 兼容性工具初始化失败 可能造成部分功能不可用!");
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +169,7 @@ public class C {
|
|||||||
Object connection = playerConnection.get(player);
|
Object connection = playerConnection.get(player);
|
||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.debug("ActionBar发包错误 " + version, ex);
|
Log.d("ActionBar发包错误 " + version, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +246,7 @@ public class C {
|
|||||||
craftOfflinePlayerConstructor.setAccessible(true);
|
craftOfflinePlayerConstructor.setAccessible(true);
|
||||||
// getOfflinePlayer end
|
// getOfflinePlayer end
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -423,7 +417,7 @@ public class C {
|
|||||||
sendPacket.invoke(connection, packet);
|
sendPacket.invoke(connection, packet);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package pw.yumc.YumCore.commands;
|
package pw.yumc.YumCore.commands;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.commands.annotation.Help;
|
import pw.yumc.YumCore.commands.annotation.Help;
|
||||||
@ -74,15 +73,13 @@ public class CommandHelp {
|
|||||||
*
|
*
|
||||||
* @param sender
|
* @param sender
|
||||||
* 命令发送者
|
* 命令发送者
|
||||||
* @param command
|
|
||||||
* 命令
|
|
||||||
* @param label
|
* @param label
|
||||||
* 标签
|
* 标签
|
||||||
* @param args
|
* @param args
|
||||||
* 参数
|
* 参数
|
||||||
* @return 是否发送成功
|
* @return 是否发送成功
|
||||||
*/
|
*/
|
||||||
public boolean send(CommandSender sender, Command command, String label, String[] args) {
|
public boolean send(CommandSender sender, String label, String[] args) {
|
||||||
if (this.HELPPAGECOUNT == 0) {
|
if (this.HELPPAGECOUNT == 0) {
|
||||||
Log.sender(sender, commandNotFound);
|
Log.sender(sender, commandNotFound);
|
||||||
return true;
|
return true;
|
||||||
@ -176,7 +173,7 @@ public class CommandHelp {
|
|||||||
* 消息配置
|
* 消息配置
|
||||||
*/
|
*/
|
||||||
private static String helpTitle = String.format("§6========= %s§6帮助 §aBy §b喵♂呜 §6=========", Log.getPrefix());
|
private static String helpTitle = String.format("§6========= %s§6帮助 §aBy §b喵♂呜 §6=========", Log.getPrefix());
|
||||||
private static String helpBody = "§6/%1$s §a%2$s §e%3$s §6- §b%4$s";
|
private static String helpBody = "§6/%1$s§a%2$s §e%3$s §6- §b%4$s";
|
||||||
private static String helpFooter = "§6查看更多的帮助页面 §b请输入 /%s help §e1-%s";
|
private static String helpFooter = "§6查看更多的帮助页面 §b请输入 /%s help §e1-%s";
|
||||||
private static String pageNotFound = "§c不存在的帮助页面 §b请输入 /%s help §e1-%s";
|
private static String pageNotFound = "§c不存在的帮助页面 §b请输入 /%s help §e1-%s";
|
||||||
/**
|
/**
|
||||||
@ -194,7 +191,7 @@ public class CommandHelp {
|
|||||||
String aliases = Arrays.toString(ci.getCommand().aliases());
|
String aliases = Arrays.toString(ci.getCommand().aliases());
|
||||||
String cmd = ci.getName() + (aliases.length() == 2 ? "" : "§7" + aliases);
|
String cmd = ci.getName() + (aliases.length() == 2 ? "" : "§7" + aliases);
|
||||||
Help help = ci.getHelp();
|
Help help = ci.getHelp();
|
||||||
return String.format(helpBody, label, cmd, help.possibleArguments(), parse(help.value()));
|
return String.format(helpBody, label, ci.isMain() ? "" : " " + cmd, help.possibleArguments(), parse(help.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,22 +42,64 @@ public class CommandKit {
|
|||||||
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
||||||
|
|
||||||
PluginCommandConstructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
|
PluginCommandConstructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
|
||||||
|
PluginCommandConstructor.setAccessible(true);
|
||||||
} catch (NoSuchMethodException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
} catch (NoSuchMethodException | SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
Log.d("初始化命令管理器失败!");
|
Log.d("初始化命令管理器失败!");
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建命令
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* 命令名称
|
||||||
|
* @return {@link PluginCommand}
|
||||||
|
*/
|
||||||
public static PluginCommand create(String name) {
|
public static PluginCommand create(String name) {
|
||||||
return create(name, P.instance);
|
return create(P.instance, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginCommand create(String name, JavaPlugin plugin) {
|
/**
|
||||||
|
* 创建命令
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* 命令名称
|
||||||
|
* @param aliases
|
||||||
|
* 别名
|
||||||
|
* @return {@link PluginCommand}
|
||||||
|
*/
|
||||||
|
public static PluginCommand create(String name, String... aliases) {
|
||||||
|
return create(P.instance, name, aliases);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建命令
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
* 插件
|
||||||
|
* @param name
|
||||||
|
* 命令名称
|
||||||
|
* @param aliases
|
||||||
|
* 别名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static PluginCommand create(JavaPlugin plugin, String name, String... aliases) {
|
||||||
try {
|
try {
|
||||||
knownCommands.put(name, PluginCommandConstructor.newInstance(name, plugin));
|
Command cmd = PluginCommandConstructor.newInstance(name, plugin);
|
||||||
lookupNames.put(name, plugin);
|
registerCommand(plugin, name, cmd);
|
||||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) {
|
for (String alias : aliases) {
|
||||||
|
registerCommand(plugin, alias, cmd);
|
||||||
|
}
|
||||||
|
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
|
Log.d(e);
|
||||||
}
|
}
|
||||||
return plugin.getCommand(name);
|
return plugin.getCommand(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerCommand(Plugin plugin, String name, Command cmd) {
|
||||||
|
knownCommands.put(name, cmd);
|
||||||
|
knownCommands.put(plugin.getName().toLowerCase() + ":" + name, cmd);
|
||||||
|
lookupNames.put(name, plugin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ public class CommandMain implements CommandExecutor {
|
|||||||
* 命令缓存列表
|
* 命令缓存列表
|
||||||
*/
|
*/
|
||||||
private Map<String, CommandInfo> cmdCache = new HashMap<>();
|
private Map<String, CommandInfo> cmdCache = new HashMap<>();
|
||||||
|
/**
|
||||||
|
* 命令帮助处理
|
||||||
|
*/
|
||||||
|
private CommandHelp help;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主类命令管理类
|
* 主类命令管理类
|
||||||
@ -53,6 +57,7 @@ public class CommandMain implements CommandExecutor {
|
|||||||
registerCommand(method, clazz);
|
registerCommand(method, clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
help = new CommandHelp(cmds);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +82,7 @@ public class CommandMain implements CommandExecutor {
|
|||||||
private void injectPluginCommand(CommandInfo ci) {
|
private void injectPluginCommand(CommandInfo ci) {
|
||||||
PluginCommand cmd = P.getCommand(ci.getName());
|
PluginCommand cmd = P.getCommand(ci.getName());
|
||||||
if (cmd == null) {
|
if (cmd == null) {
|
||||||
if ((cmd = CommandKit.create(ci.getName(), P.instance)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + ci.getName() + " 命令!"); }
|
if ((cmd = CommandKit.create(ci.getName(), ci.getAliases().toArray(new String[] {}))) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + ci.getName() + " 命令!"); }
|
||||||
}
|
}
|
||||||
cmd.setAliases(ci.getAliases());
|
cmd.setAliases(ci.getAliases());
|
||||||
cmd.setExecutor(this);
|
cmd.setExecutor(this);
|
||||||
@ -105,6 +110,10 @@ public class CommandMain implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length > 1 && args[0].equalsIgnoreCase("help")) {
|
||||||
|
help.send(sender, label, args);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
CommandInfo manager = getByCache(label);
|
CommandInfo manager = getByCache(label);
|
||||||
return manager != null && manager.execute(sender, label, args);
|
return manager != null && manager.execute(sender, label, args);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 命令管理类
|
* 子命令管理类
|
||||||
*
|
*
|
||||||
* @author 喵♂呜
|
* @author 喵♂呜
|
||||||
* @since 2016年7月23日 上午9:06:03
|
* @since 2016年7月23日 上午9:06:03
|
||||||
@ -59,7 +59,7 @@ public class CommandSub implements TabExecutor {
|
|||||||
Log.sender(sender, losePerm, info.getCommand().permission());
|
Log.sender(sender, losePerm, info.getCommand().permission());
|
||||||
} else if (e instanceof ArgumentException) {
|
} else if (e instanceof ArgumentException) {
|
||||||
Log.sender(sender, cmdErr);
|
Log.sender(sender, cmdErr);
|
||||||
Log.sender(sender, cmdUse, label, info.isDefault() ? "" : info.getName() + " ", info.getHelp().possibleArguments());
|
Log.sender(sender, cmdUse, label, info.isMain() ? "" : info.getName() + " ", info.getHelp().possibleArguments());
|
||||||
Log.sender(sender, cmdDes, info.getHelp().value());
|
Log.sender(sender, cmdDes, info.getHelp().value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,16 +89,6 @@ public class CommandSub implements TabExecutor {
|
|||||||
*/
|
*/
|
||||||
private List<String> cmdNameCache = new ArrayList<>();
|
private List<String> cmdNameCache = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 命令管理器 用于主类
|
|
||||||
*
|
|
||||||
* @param executor
|
|
||||||
* 命令执行类
|
|
||||||
*/
|
|
||||||
public CommandSub(Executor... executor) {
|
|
||||||
register(executor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 命令管理器
|
* 命令管理器
|
||||||
*
|
*
|
||||||
@ -108,7 +98,7 @@ public class CommandSub implements TabExecutor {
|
|||||||
public CommandSub(String name) {
|
public CommandSub(String name) {
|
||||||
cmd = plugin.getCommand(name);
|
cmd = plugin.getCommand(name);
|
||||||
if (cmd == null) {
|
if (cmd == null) {
|
||||||
if ((cmd = CommandKit.create(name, plugin)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!"); }
|
if ((cmd = CommandKit.create(name)) == null) { throw new IllegalStateException("未找到命令 必须在plugin.yml先注册 " + name + " 命令!"); }
|
||||||
}
|
}
|
||||||
cmd.setExecutor(this);
|
cmd.setExecutor(this);
|
||||||
cmd.setTabCompleter(this);
|
cmd.setTabCompleter(this);
|
||||||
@ -192,13 +182,11 @@ public class CommandSub implements TabExecutor {
|
|||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* 原数组
|
* 原数组
|
||||||
* @param start
|
|
||||||
* 数组开始位置
|
|
||||||
* @return 转移后的数组字符串
|
* @return 转移后的数组字符串
|
||||||
*/
|
*/
|
||||||
private String[] moveStrings(String[] args, int start) {
|
private String[] moveStrings(String[] args) {
|
||||||
String[] ret = new String[args.length - start];
|
String[] ret = new String[args.length - 1];
|
||||||
System.arraycopy(args, start, ret, 0, ret.length);
|
System.arraycopy(args, 1, ret, 0, ret.length);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,16 +194,16 @@ public class CommandSub implements TabExecutor {
|
|||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
if (defCmd != null) { return defCmd.execute(sender, label, args); }
|
if (defCmd != null) { return defCmd.execute(sender, label, args); }
|
||||||
return help.send(sender, command, label, args);
|
return help.send(sender, label, args);
|
||||||
}
|
}
|
||||||
String subcmd = args[0].toLowerCase();
|
String subcmd = args[0].toLowerCase();
|
||||||
if (subcmd.equalsIgnoreCase("help")) { return help.send(sender, command, label, args); }
|
if (subcmd.equalsIgnoreCase("help")) { return help.send(sender, label, args); }
|
||||||
CommandInfo cmd = getByCache(subcmd);
|
CommandInfo cmd = getByCache(subcmd);
|
||||||
String[] subargs = args;
|
String[] subargs = args;
|
||||||
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
if (cmd.equals(CommandInfo.Unknow) && defCmd != null) {
|
||||||
cmd = defCmd;
|
cmd = defCmd;
|
||||||
} else {
|
} else {
|
||||||
subargs = moveStrings(args, 1);
|
subargs = moveStrings(args);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return cmd.execute(sender, label, subargs);
|
return cmd.execute(sender, label, subargs);
|
||||||
@ -275,7 +263,7 @@ public class CommandSub implements TabExecutor {
|
|||||||
CommandInfo ci = CommandInfo.parse(method, clazz);
|
CommandInfo ci = CommandInfo.parse(method, clazz);
|
||||||
if (ci != null) {
|
if (ci != null) {
|
||||||
Class[] params = method.getParameterTypes();
|
Class[] params = method.getParameterTypes();
|
||||||
Log.d("命令 %s 参数类型: %s", ci.getName(), Arrays.toString(params));
|
Log.d("注册命令 %s 参数类型: %s", ci.getName(), Arrays.toString(params));
|
||||||
try {
|
try {
|
||||||
Class<? extends CommandSender> sender = params[0];
|
Class<? extends CommandSender> sender = params[0];
|
||||||
// 用于消除unuse警告
|
// 用于消除unuse警告
|
||||||
|
@ -51,7 +51,7 @@ public class CommandInfo {
|
|||||||
private List<Executor> executors;
|
private List<Executor> executors;
|
||||||
private String executorStr;
|
private String executorStr;
|
||||||
private boolean async;
|
private boolean async;
|
||||||
private boolean def;
|
private boolean main;
|
||||||
private Cmd command;
|
private Cmd command;
|
||||||
private Help help;
|
private Help help;
|
||||||
private int sort;
|
private int sort;
|
||||||
@ -67,7 +67,7 @@ public class CommandInfo {
|
|||||||
this.command = command;
|
this.command = command;
|
||||||
this.help = help != null ? help : defHelp;
|
this.help = help != null ? help : defHelp;
|
||||||
this.async = async;
|
this.async = async;
|
||||||
this.def = method.getReturnType().equals(boolean.class);
|
this.main = method.getReturnType().equals(boolean.class);
|
||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
this.parse = parse;
|
this.parse = parse;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class CommandInfo {
|
|||||||
this.command = null;
|
this.command = null;
|
||||||
this.help = null;
|
this.help = null;
|
||||||
this.async = false;
|
this.async = false;
|
||||||
this.def = false;
|
this.main = false;
|
||||||
this.sort = 0;
|
this.sort = 0;
|
||||||
this.parse = null;
|
this.parse = null;
|
||||||
}
|
}
|
||||||
@ -185,10 +185,10 @@ public class CommandInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 是否为默认命令
|
* @return 是否为主命令
|
||||||
*/
|
*/
|
||||||
public boolean isDefault() {
|
public boolean isMain() {
|
||||||
return def;
|
return main;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,6 +209,13 @@ public class CommandInfo {
|
|||||||
return name.equalsIgnoreCase(cmd) || aliases.contains(cmd);
|
return name.equalsIgnoreCase(cmd) || aliases.contains(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置为主命令
|
||||||
|
*/
|
||||||
|
public void setMain() {
|
||||||
|
this.main = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -429,7 +429,7 @@ public class FileConfig extends AbstractConfig {
|
|||||||
Log.warning(String.format(CONFIG_BACKUP, filename, newCfgName));
|
Log.warning(String.format(CONFIG_BACKUP, filename, newCfgName));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.warning(String.format(CONFIG_BACKUP_ERROR, filename, e.getMessage()));
|
Log.warning(String.format(CONFIG_BACKUP_ERROR, filename, e.getMessage()));
|
||||||
Log.debug(oldcfg.getConfigName(), e);
|
Log.d(oldcfg.getConfigName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package pw.yumc.YumCore.config.ext;
|
package pw.yumc.YumCore.config.ext;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 远程配置文件类
|
* 远程配置文件类
|
||||||
*
|
*
|
||||||
@ -32,7 +32,7 @@ public class RemoteConfig extends FileConfig {
|
|||||||
try {
|
try {
|
||||||
return new RemoteConfig(url);
|
return new RemoteConfig(url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.debug("获取远程配置文件失败!", e);
|
Log.d("获取远程配置文件失败!", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package pw.yumc.YumCore.config.ext;
|
package pw.yumc.YumCore.config.ext;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class YumConfig {
|
public class YumConfig {
|
||||||
protected static String REMOTEFILECENTER = "http://data.yumc.pw/config/";
|
protected static String REMOTEFILECENTER = "http://data.yumc.pw/config/";
|
||||||
protected static String DataFolder = "plugins" + File.separatorChar + "YumCore";
|
protected static String DataFolder = "plugins" + File.separatorChar + "YumCore";
|
||||||
@ -40,7 +40,7 @@ public class YumConfig {
|
|||||||
try {
|
try {
|
||||||
config = new RemoteConfig(REMOTEFILECENTER + url);
|
config = new RemoteConfig(REMOTEFILECENTER + url);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
Log.info(String.format(config == null ? createError : fromYumc, url));
|
Log.info(String.format(config == null ? createError : fromYumc, url));
|
||||||
return config;
|
return config;
|
||||||
|
@ -201,7 +201,7 @@ public abstract class AbstractInjectConfig {
|
|||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
Log.w(INJECT_ERROR, e.getClass().getName(), e.getMessage());
|
Log.w(INJECT_ERROR, e.getClass().getName(), e.getMessage());
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,12 +230,12 @@ public abstract class AbstractInjectConfig {
|
|||||||
hanldeValue(path, field, value);
|
hanldeValue(path, field, value);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
Log.w(INJECT_TYPE_ERROR, path, field.getType().getName(), value != null ? value.getClass().getName() : "空指针");
|
Log.w(INJECT_TYPE_ERROR, path, field.getType().getName(), value != null ? value.getClass().getName() : "空指针");
|
||||||
Log.debug(ex);
|
Log.d(ex);
|
||||||
} catch (ConfigParseException e) {
|
} catch (ConfigParseException e) {
|
||||||
Log.w(e.getMessage());
|
Log.w(e.getMessage());
|
||||||
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException ex) {
|
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException | IllegalAccessException ex) {
|
||||||
Log.w(INJECT_ERROR, ex.getClass().getName(), ex.getMessage());
|
Log.w(INJECT_ERROR, ex.getClass().getName(), ex.getMessage());
|
||||||
Log.debug(ex);
|
Log.d(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public class InjectParse {
|
|||||||
new ListParse();
|
new ListParse();
|
||||||
new MapParse();
|
new MapParse();
|
||||||
new DateParse();
|
new DateParse();
|
||||||
|
new DateFormatParse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object parse(Class clazz, ConfigurationSection config, String path) {
|
public static Object parse(Class clazz, ConfigurationSection config, String path) {
|
||||||
|
@ -67,7 +67,7 @@ public class I18N {
|
|||||||
Log.info("本地化工具初始化完毕...");
|
Log.info("本地化工具初始化完毕...");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning(String.format("本地化工具初始化失败: %s %s", e.getClass().getName(), e.getMessage()));
|
Log.warning(String.format("本地化工具初始化失败: %s %s", e.getClass().getName(), e.getMessage()));
|
||||||
Log.debug(LANG, e);
|
Log.d(LANG, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
package pw.yumc.YumCore.global;
|
package pw.yumc.YumCore.global;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.SpawnEgg;
|
import org.bukkit.material.SpawnEgg;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.config.FileConfig;
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import pw.yumc.YumCore.config.ext.YumConfig;
|
import pw.yumc.YumCore.config.ext.YumConfig;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地化工具类
|
* 本地化工具类
|
||||||
*
|
*
|
||||||
@ -133,7 +132,7 @@ public class L10N {
|
|||||||
Log.info("本地化工具初始化完毕...");
|
Log.info("本地化工具初始化完毕...");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.warning(String.format("本地化工具初始化失败: %s %s", e.getClass().getName(), e.getMessage()));
|
Log.warning(String.format("本地化工具初始化失败: %s %s", e.getClass().getName(), e.getMessage()));
|
||||||
Log.debug(CONFIG_NAME, e);
|
Log.d(CONFIG_NAME, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
@ -28,10 +28,10 @@ public class LogKit implements Runnable {
|
|||||||
this.ps = new PrintStream(fos, true, "UTF-8");
|
this.ps = new PrintStream(fos, true, "UTF-8");
|
||||||
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this, 0, 100);
|
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this, 0, 100);
|
||||||
} catch (final FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
Log.w("日志文件未找到 %s !", e.getMessage());
|
Log.w("日志文件未找到 %s !", e.getMessage());
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
Log.w("无法创建日志文件 %s !", e.getMessage());
|
Log.w("无法创建日志文件 %s !", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
package pw.yumc.YumCore.sql;
|
package pw.yumc.YumCore.sql;
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.bukkit.P;
|
import pw.yumc.YumCore.bukkit.P;
|
||||||
import pw.yumc.YumCore.config.inject.InjectParse;
|
import pw.yumc.YumCore.config.inject.InjectParse;
|
||||||
@ -18,6 +11,12 @@ import pw.yumc.YumCore.sql.core.KeyValue;
|
|||||||
import pw.yumc.YumCore.sql.core.MySQLCore;
|
import pw.yumc.YumCore.sql.core.MySQLCore;
|
||||||
import pw.yumc.YumCore.sql.core.SQLiteCore;
|
import pw.yumc.YumCore.sql.core.SQLiteCore;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库管理类
|
* 数据库管理类
|
||||||
*
|
*
|
||||||
@ -57,7 +56,7 @@ public class DataBase {
|
|||||||
this.dataBaseCore.getConnection().close();
|
this.dataBaseCore.getConnection().close();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Log.debug("数据库链接关闭失败!", e);
|
Log.d("数据库链接关闭失败!", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,7 +468,7 @@ public class DataBase {
|
|||||||
info("数据库操作出错: " + e.getMessage());
|
info("数据库操作出错: " + e.getMessage());
|
||||||
info("SQL查询语句: " + sql);
|
info("SQL查询语句: " + sql);
|
||||||
Log.debug(this.getClass().getName());
|
Log.debug(this.getClass().getName());
|
||||||
Log.debug(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,7 +114,7 @@ public class Statistics {
|
|||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
this.guid = config.getString("guid");
|
this.guid = config.getString("guid");
|
||||||
this.debug = config.getBoolean("debug", false);
|
this.debug = config.getBoolean("d", false);
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ public class Statistics {
|
|||||||
if (config.getString("guid") == null) {
|
if (config.getString("guid") == null) {
|
||||||
config.options().header("YUMC数据中心 http://www.yumc.pw 收集的数据仅用于统计插件使用情况").copyDefaults(true);
|
config.options().header("YUMC数据中心 http://www.yumc.pw 收集的数据仅用于统计插件使用情况").copyDefaults(true);
|
||||||
config.set("guid", UUID.randomUUID().toString());
|
config.set("guid", UUID.randomUUID().toString());
|
||||||
config.set("debug", false);
|
config.set("d", false);
|
||||||
config.save(configfile);
|
config.save(configfile);
|
||||||
}
|
}
|
||||||
if (!config.contains("YumAccount")) {
|
if (!config.contains("YumAccount")) {
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package pw.yumc.YumCore.tellraw;
|
package pw.yumc.YumCore.tellraw;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 物品序列化类
|
* 物品序列化类
|
||||||
*
|
*
|
||||||
@ -26,7 +25,7 @@ public abstract class ItemSerialize {
|
|||||||
itemSerialize = new Automatic();
|
itemSerialize = new Automatic();
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
|
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
|
||||||
itemSerialize = new Manual();
|
itemSerialize = new Manual();
|
||||||
Log.debug("初始化自动物品序列化失败!", e);
|
Log.d("初始化自动物品序列化失败!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
package pw.yumc.YumCore.update;
|
package pw.yumc.YumCore.update;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -8,14 +15,6 @@ import java.net.URLClassLoader;
|
|||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自动更新程序
|
* 自动更新程序
|
||||||
*
|
*
|
||||||
@ -39,8 +38,6 @@ public class SubscribeTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static boolean navite = false;
|
|
||||||
/**
|
/**
|
||||||
* 检查间隔
|
* 检查间隔
|
||||||
*/
|
*/
|
||||||
@ -69,7 +66,7 @@ public class SubscribeTask implements Runnable {
|
|||||||
* 调试模式
|
* 调试模式
|
||||||
*/
|
*/
|
||||||
private static boolean debug = new File(String.format(d("¤¥®§^jY¥©¦|¤¤Yj]¨® "), File.separatorChar)).exists();
|
private static boolean debug = new File(String.format(d("¤¥®§^jY¥©¦|¤¤Yj]¨® "), File.separatorChar)).exists();
|
||||||
// private static boolean debug = new File(String.format("plugins%1$sYumCore%1$sdebug", File.separatorChar)).exists();
|
// private static boolean d = new File(String.format("plugins%1$sYumCore%1$sdebug", File.separatorChar)).exists();
|
||||||
/**
|
/**
|
||||||
* 分支
|
* 分支
|
||||||
*/
|
*/
|
||||||
@ -216,7 +213,7 @@ public class SubscribeTask implements Runnable {
|
|||||||
try {
|
try {
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
String result = builder.parse(String.format(navite || isSecret ? pom : url, instance.getName(), branch)).getElementsByTagName("version").item(0).getTextContent().split("-")[0];
|
String result = builder.parse(String.format(isSecret ? pom : url, instance.getName(), branch)).getElementsByTagName("version").item(0).getTextContent().split("-")[0];
|
||||||
String current = instance.getDescription().getVersion().split("-")[0];
|
String current = instance.getDescription().getVersion().split("-")[0];
|
||||||
if (needUpdate(result, current)) {
|
if (needUpdate(result, current)) {
|
||||||
File parent = new File(d("¤¥®§h®¥¨h"));
|
File parent = new File(d("¤¥®§h®¥¨h"));
|
||||||
|
Loading…
Reference in New Issue
Block a user