1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-21 01:38:51 +00:00

fix: 修复开发版本无法自动更新的问题 添加单元测试

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-08-22 19:24:32 +08:00
parent e578f33608
commit d767dba2e6
8 changed files with 189 additions and 160 deletions

15
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<version>1.8.3</version>
<version>1.8.5</version>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
@ -66,7 +66,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
<version>[1.12.1-R0.1-SNAPSHOT,)</version>
<exclusions>
<exclusion>
<artifactId>gson</artifactId>
@ -81,7 +81,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.11-SNAPSHOT</version>
<version>[1.12-SNAPSHOT,)</version>
<exclusions>
<exclusion>
<artifactId>snakeyaml</artifactId>
@ -92,7 +92,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.5.1</version>
<version>[2.5.1,)</version>
<exclusions>
<exclusion>
<artifactId>spigot-api</artifactId>
@ -108,7 +108,7 @@
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.5.6</version>
<version>[1.5.6,)</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
@ -130,6 +130,11 @@
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.5</version>
</dependency>
<dependency>
<groupId>io.puharesource.mc</groupId>
<artifactId>TitleManager</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>

View File

@ -2,7 +2,7 @@ package pw.yumc.YumCore.bukkit;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -27,6 +27,7 @@ public class Log {
private static Logger logger;
private static CommandSender console;
private static String prefix;
static {
try {
debug = globalDebug || P.getDescription().getVersion().contains("DEV");
@ -36,7 +37,6 @@ public class Log {
} catch (Throwable ex) {
logger = Logger.getLogger("YumCore");
debug = true;
d(ex);
}
}
@ -51,10 +51,10 @@ public class Log {
* that essentially act as default handlers for all loggers.
*
* @param handler
* a logging Handler
* a logging Handler
* @throws SecurityException
* if a security manager exists and if
* the caller does not have LoggingPermission("control").
* if a security manager exists and if
* the caller does not have LoggingPermission("control").
*/
public static void addHandler(Handler handler) throws SecurityException {
logger.addHandler(handler);
@ -64,7 +64,7 @@ public class Log {
* Sends console a message
*
* @param message
* Message to be displayed
* Message to be displayed
*/
public static void console(String message) {
console.sendMessage(prefix + message);
@ -74,9 +74,9 @@ public class Log {
* Sends console a message
*
* @param message
* 消息
* 消息
* @param object
* 格式化参数
* 格式化参数
*/
public static void console(String message, Object... object) {
console.sendMessage(prefix + String.format(message, object));
@ -86,7 +86,7 @@ public class Log {
* Sends console a message
*
* @param msg
* Message to be displayed
* Message to be displayed
*/
public static void console(String[] msg) {
for (String str : msg) {
@ -98,7 +98,7 @@ public class Log {
* 调试消息
*
* @param msg
* 消息
* 消息
*/
public static void d(String msg) {
if (debug) {
@ -110,9 +110,9 @@ public class Log {
* 调试消息
*
* @param msg
* 消息
* 消息
* @param object
* 参数
* 参数
*/
public static void d(String msg, Object... object) {
if (debug) {
@ -124,7 +124,7 @@ public class Log {
* 调试消息
*
* @param e
* 异常
* 异常
*/
public static void d(Throwable e) {
if (debug) {
@ -136,9 +136,9 @@ public class Log {
* 调试消息
*
* @param msg
* 消息
* 消息
* @param e
* 异常
* 异常
*/
public static void d(String msg, Throwable e) {
if (debug) {
@ -151,7 +151,7 @@ public class Log {
* 完全调试消息
*
* @param msg
* 消息
* 消息
*/
public static void fd(String msg) {
if (fullDebug) {
@ -163,9 +163,9 @@ public class Log {
* 完全调试消息
*
* @param msg
* 消息
* 消息
* @param object
* 参数
* 参数
*/
public static void fd(String msg, Object... object) {
if (fullDebug) {
@ -177,7 +177,7 @@ public class Log {
* 完全调试消息
*
* @param e
* 异常
* 异常
*/
public static void fd(Throwable e) {
if (fullDebug) {
@ -189,9 +189,9 @@ public class Log {
* 完全调试消息
*
* @param msg
* 消息
* 消息
* @param e
* 异常
* 异常
*/
public static void fd(String msg, Throwable e) {
if (fullDebug) {
@ -224,9 +224,9 @@ public class Log {
* <p>
*
* @param level
* One of the message level identifiers, e.g., SEVERE
* One of the message level identifiers, e.g., SEVERE
* @param msg
* The string message (or a key in the message catalog)
* The string message (or a key in the message catalog)
*/
public static void log(Level level, String msg) {
logger.log(level, msg);
@ -241,11 +241,11 @@ public class Log {
* <p>
*
* @param level
* One of the message level identifiers, e.g., SEVERE
* One of the message level identifiers, e.g., SEVERE
* @param msg
* The string message (or a key in the message catalog)
* The string message (or a key in the message catalog)
* @param param1
* parameter to the message
* parameter to the message
*/
public static void log(Level level, String msg, Object param1) {
logger.log(level, msg, param1);
@ -260,11 +260,11 @@ public class Log {
* <p>
*
* @param level
* One of the message level identifiers, e.g., SEVERE
* One of the message level identifiers, e.g., SEVERE
* @param msg
* The string message (or a key in the message catalog)
* The string message (or a key in the message catalog)
* @param params
* array of parameters to the message
* array of parameters to the message
*/
public static void log(Level level, String msg, Object[] params) {
logger.log(level, msg, params);
@ -284,11 +284,11 @@ public class Log {
* <p>
*
* @param level
* One of the message level identifiers, e.g., SEVERE
* One of the message level identifiers, e.g., SEVERE
* @param msg
* The string message (or a key in the message catalog)
* The string message (or a key in the message catalog)
* @param thrown
* Throwable associated with log message.
* Throwable associated with log message.
*/
public static void log(Level level, String msg, Throwable thrown) {
logger.log(level, msg, thrown);
@ -296,7 +296,7 @@ public class Log {
/**
* @param prefix
* 插件前缀
* 插件前缀
*/
public static void setPrefix(String prefix) {
Log.prefix = ChatColor.translateAlternateColorCodes('&', prefix);
@ -309,7 +309,7 @@ public class Log {
* given message is forwarded to all the registered output Handler objects.
*
* @param msg
* The string message (or a key in the message catalog)
* The string message (or a key in the message catalog)
*/
public static void severe(String msg) {
logger.severe(msg);
@ -319,9 +319,9 @@ public class Log {
* Sends this sender a message
*
* @param sender
* 命令发送者
* 命令发送者
* @param msg
* 消息
* 消息
*/
public static void sender(CommandSender sender, String msg) {
sender.sendMessage(prefix + msg);
@ -331,11 +331,11 @@ public class Log {
* Sends this sender a message
*
* @param sender
* 命令发送者
* 命令发送者
* @param msg
* 消息
* 消息
* @param objs
* 参数
* 参数
*/
public static void sender(CommandSender sender, String msg, Object... objs) {
sender.sendMessage(prefix + String.format(msg, objs));
@ -345,9 +345,9 @@ public class Log {
* Sends this sender a message
*
* @param sender
* 命令发送者
* 命令发送者
* @param msg
* 消息
* 消息
*/
public static void sender(CommandSender sender, String[] msg) {
Arrays.stream(msg).forEach(str -> sender(sender, str));
@ -357,7 +357,7 @@ public class Log {
* 格式化警告消息
*
* @param string
* 消息
* 消息
*/
public static void w(String string) {
logger.warning(string);
@ -367,14 +367,21 @@ public class Log {
* 格式化警告消息
*
* @param string
* 消息
* 消息
* @param objects
* 参数
* 参数
*/
public static void w(String string, Object... objects) {
w(String.format(string, objects));
}
/**
* @return 是否为调试模式
*/
public static boolean isDebug() {
return debug;
}
/**
* @return 是否为全局调试模式
*/
@ -382,23 +389,20 @@ public class Log {
return globalDebug;
}
public static String osn(List<?> classes) {
/**
* 打印对象简易名称
*
* @param objects
* 对象
* @return
*/
public static String getSimpleNames(Object... objects) {
StringBuilder str = new StringBuilder("[");
classes.forEach(c -> str.append(c == null ? null : c.getClass().getSimpleName()).append(", "));
return classes.isEmpty() ? "[]" : str.substring(0, str.length() - 2) + "]";
}
public static String osn(Object... classes) {
return osn(Arrays.asList(classes));
}
public static String csn(List<Class> classes) {
StringBuilder str = new StringBuilder("[");
classes.forEach(c -> str.append(c == null ? null : c.getSimpleName()).append(", "));
return classes.isEmpty() ? "[]" : str.substring(0, str.length() - 2) + "]";
}
public static String csn(Class[] classes) {
return csn(Arrays.asList(classes));
Arrays.stream(objects)
.forEach(o -> str.append(Optional.ofNullable(o)
.map(obj -> obj instanceof Class ? (Class) obj : obj.getClass())
.map(Class::getSimpleName)
.orElse(null)).append(", "));
return objects.length == 0 ? "[]" : str.substring(0, str.length() - 2) + "]";
}
}

View File

@ -7,18 +7,21 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
/**
* 插件Instance获取类
*
* @since 2016年7月23日 上午9:09:57
* @author
* @since 2016年7月23日 上午9:09:57
*/
public class P {
/**
@ -48,8 +51,7 @@ public class P {
/**
* @param name
* 命令名称
*
* 命令名称
* @return 插件命令
*/
public static PluginCommand getCommand(String name) {
@ -58,7 +60,7 @@ public class P {
/**
* @param <FC>
* 配置源类型
* 配置源类型
* @return 获得插件配置文件
*/
public static <FC> FC getConfig() {
@ -67,7 +69,7 @@ public class P {
/**
* @param <FC>
* 注入配置源类型
* 注入配置源类型
* @return 获得插件注入配置
*/
public static <FC> FC getInjectConfig() {
@ -108,7 +110,7 @@ public class P {
/**
* @param <PI>
* 插件源类型
* 插件源类型
* @return 获得插件
*/
public static <PI> PI getPlugin() {
@ -122,11 +124,21 @@ public class P {
return instance.isEnabled();
}
/**
* 批量注册监听器
*
* @param listeners
* 监听器
*/
public static void registerEvents(Listener... listeners) {
Arrays.stream(listeners).forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, instance));
}
/**
* 保存文件
*
* @param dirs
* 目录
* 目录
*/
public static void saveFile(final String... dirs) {
saveFile(false, dirs);
@ -134,11 +146,11 @@ public class P {
/**
* 保存文件
*
*
* @param replace
* 是否替换
* 是否替换
* @param dirs
* 目录
* 目录
*/
public static void saveFile(boolean replace, final String... dirs) {
URL url = instance.getClass().getClassLoader().getResource("plugin.yml");

View File

@ -21,7 +21,7 @@ import pw.yumc.YumCore.commands.interfaces.HelpGenerator;
/**
* 主类命令管理
*
*
* @author
* @since 2016/11/18 0018
*/
@ -46,9 +46,9 @@ public class CommandMain implements CommandExecutor {
/**
* 主类命令管理类
*
*
* @param clazzs
* 命令类
* 命令类
*/
public CommandMain(Executor... clazzs) {
register(clazzs);
@ -56,12 +56,12 @@ public class CommandMain implements CommandExecutor {
/**
* 注册命令
*
*
* @param clazzs
* 命令类
* 命令类
* @return {@link CommandMain}
*/
public CommandMain register(Executor... clazzs) {
public void register(Executor... clazzs) {
for (Executor clazz : clazzs) {
Method[] methods = clazz.getClass().getDeclaredMethods();
for (Method method : methods) {
@ -70,30 +70,29 @@ public class CommandMain implements CommandExecutor {
}
help = new CommandHelp(cmds);
help.setHelpGenerator(helpGenerator);
return this;
}
private boolean registerCommand(Method method, Executor clazz) {
private void registerCommand(Method method, Executor clazz) {
CommandInfo ci = CommandInfo.parse(method, clazz);
if (ci != null) {
injectPluginCommand(ci);
Class[] params = method.getParameterTypes();
Log.d("注册主命令 %s 参数类型: %s", ci.getName(), Log.csn(params));
Log.d("注册主命令 %s 参数类型: %s", ci.getName(), Log.getSimpleNames((Object[]) params));
try {
Class<? extends CommandSender> sender = params[0];
cmds.add(ci);
return true;
} catch (ArrayIndexOutOfBoundsException | ClassCastException ignored) {
Log.w(argumentTypeError, method.getName(), clazz.getClass().getName());
}
Log.w(argumentTypeError, method.getName(), clazz.getClass().getName());
}
return false;
}
private void injectPluginCommand(CommandInfo ci) {
PluginCommand cmd = P.getCommand(ci.getName());
if (cmd == null) {
if ((cmd = CommandKit.create(ci.getName(), ci.getAliases().toArray(new String[] {}))) == 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.setExecutor(this);
}
@ -102,7 +101,7 @@ public class CommandMain implements CommandExecutor {
* 检查缓存并获得命令
*
* @param cmd
* 子命令
* 子命令
* @return 命令信息
*/
private CommandInfo getByCache(String cmd) {

View File

@ -29,6 +29,7 @@ public class CommandParse {
private static Map<String, Class> primitiveMap = new HashMap<>();
private boolean isMain;
private List<Parse> parses = new LinkedList<>();
static {
register(File.class, FileParse.class);
register(Player.class, PlayerParse.class);
@ -68,7 +69,7 @@ public class CommandParse {
if (parse == null) { throw new ParseException(String.format("存在无法解析的参数类型 %s", clazz.getName())); }
this.parses.add(parse.parseAnnotation(annotations).handleAttrs());
}
Log.d("命令解析器 %s", Log.osn(parses));
Log.d("命令解析器 %s", Log.getSimpleNames(parses));
}
public static CommandParse get(Method method) {
@ -79,9 +80,9 @@ public class CommandParse {
* 转化数组为字符串
*
* @param arr
* 数组
* 数组
* @param split
* 分割符
* 分割符
* @return 字符串
*/
public static String join(Object[] arr, String split) {
@ -114,7 +115,7 @@ public class CommandParse {
throw new ParseException(String.format("第 %s 个参数 %s", isMain ? 1 : 2 + i, e.getMessage()));
}
}
Log.d("解析参数: %s => %s", Arrays.toString(args), Log.osn(pobjs));
Log.d("解析参数: %s => %s", Arrays.toString(args), Log.getSimpleNames(pobjs));
return pobjs.toArray();
}

View File

@ -74,7 +74,7 @@ public class CommandSub implements TabExecutor {
* 命令管理器
*
* @param name
* 注册的命令
* 注册的命令
*/
public CommandSub(String name) {
cmd = plugin.getCommand(name);
@ -90,9 +90,9 @@ public class CommandSub implements TabExecutor {
* 命令管理器
*
* @param name
* 注册的命令
* 注册的命令
* @param executor
* 命令执行类
* 命令执行类
*/
public CommandSub(String name, Executor... executor) {
this(name);
@ -115,7 +115,7 @@ public class CommandSub implements TabExecutor {
* 检查缓存并获得命令
*
* @param subcmd
* 子命令
* 子命令
* @return 命令信息
*/
private CommandInfo getByCache(String subcmd) {
@ -137,21 +137,25 @@ public class CommandSub implements TabExecutor {
* 获取玩家命令补全
*
* @param sender
* 命令发送者
* 命令发送者
* @param command
* 命令
* 命令
* @param alias
* 别名
* 别名
* @param args
* 数组
* 数组
* @return 在线玩家数组
*/
private List<String> getPlayerTabComplete(CommandSender sender, Command command, String alias, String[] args) {
String lastWord = args[args.length - 1];
Player senderPlayer = sender instanceof Player ? (Player) sender : null;
List<String> matchedPlayers = new ArrayList<>();
C.Player.getOnlinePlayers().stream().filter(player -> (senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(player.getName(), lastWord)).forEach(
player -> matchedPlayers.add(player.getName()));
C.Player.getOnlinePlayers()
.stream()
.filter(player -> (senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(player.getName(),
lastWord))
.forEach(
player -> matchedPlayers.add(player.getName()));
return matchedPlayers;
}
@ -159,7 +163,7 @@ public class CommandSub implements TabExecutor {
* 转移数组
*
* @param args
* 原数组
* 原数组
* @return 转移后的数组字符串
*/
private String[] moveStrings(String[] args) {
@ -203,10 +207,10 @@ public class CommandSub implements TabExecutor {
* 通过注解读取命令并注册
*
* @param clazzs
* 子命令处理类
* 子命令处理类
* @return {@link CommandSub}
*/
public CommandSub register(Executor... clazzs) {
public void register(Executor... clazzs) {
for (Executor clazz : clazzs) {
Log.d("解析执行类: %s", clazz.getClass().getName());
Method[] methods = clazz.getClass().getDeclaredMethods();
@ -219,23 +223,22 @@ public class CommandSub implements TabExecutor {
}
help = new CommandHelp(defCmd, cmds);
buildCmdNameCache();
return this;
}
/**
* 注册命令
*
* @param method
* 方法
* 方法
* @param clazz
* 调用对象
* 调用对象
* @return 是否成功
*/
private boolean registerCommand(Method method, Executor clazz) {
CommandInfo ci = CommandInfo.parse(method, clazz);
if (ci != null) {
Class[] params = method.getParameterTypes();
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.csn(params));
Log.d("注册子命令: %s 参数类型: %s", ci.getName(), Log.getSimpleNames((Object[]) params));
try {
Class<? extends CommandSender> sender = params[0];
// 用于消除unuse警告
@ -257,29 +260,28 @@ public class CommandSub implements TabExecutor {
* 注册Tab补全
*
* @param method
* 方法
* 方法
* @param clazz
* 调用对象
* 调用对象
* @return 是否成功
*/
private boolean registerTab(Method method, Executor clazz) {
private void registerTab(Method method, Executor clazz) {
CommandTabInfo ti = CommandTabInfo.parse(method, clazz);
if (ti != null) {
if (method.getReturnType().equals(List.class)) {
Log.d("注册子命令补全: %s ", method.getName());
tabs.add(ti);
return true;
} else {
Log.w(returnTypeError, method.getName(), clazz.getClass().getName());
}
Log.w(returnTypeError, method.getName(), clazz.getClass().getName());
}
return false;
}
/**
* 设置命令错误处理器
*
*
* @param commandErrorHanlder
* 命令错误处理器
* 命令错误处理器
* @return {@link CommandSub}
*/
public CommandSub setCommandErrorHanlder(ErrorHanlder commandErrorHanlder) {
@ -291,7 +293,7 @@ public class CommandSub implements TabExecutor {
* 设置帮助生成器
*
* @param helpGenerator
* 帮助生成器
* 帮助生成器
* @return {@link CommandSub}
*/
public CommandSub setHelpGenerator(HelpGenerator helpGenerator) {
@ -303,7 +305,7 @@ public class CommandSub implements TabExecutor {
* 设置帮助解析器
*
* @param helpParse
* 帮助解析器
* 帮助解析器
* @return {@link CommandSub}
*/
public CommandSub setHelpParse(HelpParse helpParse) {

View File

@ -3,7 +3,6 @@ package pw.yumc.YumCore.update;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLClassLoader;
@ -30,31 +29,21 @@ import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.tellraw.Tellraw;
import pw.yumc.YumCore.text.Encrypt;
/**
* 自动更新程序
*
* @since 2016年8月3日 上午11:20:21
* @author
* @since 2016年8月3日 上午11:20:21
*/
public class SubscribeTask implements Runnable, Listener {
/**
* 插件实例
*/
private static JavaPlugin instance;
static {
try {
Object pluginClassLoader = SubscribeTask.class.getClassLoader();
Field field = pluginClassLoader.getClass().getDeclaredField("plugin");
field.setAccessible(true);
instance = (JavaPlugin) field.get(pluginClassLoader);
} catch (Exception e) {
Log.d(e);
}
}
private static JavaPlugin instance = P.instance;
/**
* 检查间隔
@ -82,7 +71,7 @@ public class SubscribeTask implements Runnable, Listener {
* 自动更新
*
* @param type
* 是否为Maven
* 是否为Maven
*/
public SubscribeTask(UpdateType type) {
this(false, type);
@ -92,9 +81,9 @@ public class SubscribeTask implements Runnable, Listener {
* 自动更新
*
* @param isSecret
* 是否为私有
* 是否为私有
* @param type
* 更新类型
* 更新类型
*/
public SubscribeTask(boolean isSecret, UpdateType type) {
this("master", isSecret, type);
@ -104,13 +93,14 @@ public class SubscribeTask implements Runnable, Listener {
* 自动更新
*
* @param branch
* 更新分支
* 更新分支
* @param isSecret
* 是否为私有
* 是否为私有
* @param type
* 更新类型
* 更新类型
*/
public SubscribeTask(String branch, boolean isSecret, UpdateType type) {
Log.d("订阅更新 分支 %s 是否加密 %s 更新类型 %s", branch, isSecret, type.name());
updateFile = new UpdateFile(instance);
versionInfo = new VersionInfo(instance, branch, isSecret);
updateType = type;
@ -180,11 +170,11 @@ public class SubscribeTask implements Runnable, Listener {
public String getDownloadUrl(Plugin instance, String version) {
switch (this) {
case DIRECT:
case WS:
return String.format(url, instance.getName());
case MAVEN:
return String.format(url, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), version, instance.getName());
case DIRECT:
case WS:
return String.format(url, instance.getName());
case MAVEN:
return String.format(url, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), version, instance.getName());
}
throw new UnsupportedOperationException();
}
@ -216,7 +206,7 @@ public class SubscribeTask implements Runnable, Listener {
* 获得插件绝对路径
*
* @param plugin
* - 插件
* - 插件
* @return 插件的绝对路径
*/
public File getPluginFile(Plugin plugin) {
@ -287,11 +277,11 @@ public class SubscribeTask implements Runnable, Listener {
/**
* 获得插件信息
*
*
* @param tag
* 数据标签
* 数据标签
* @param def
* 默认值
* 默认值
* @return 信息
*/
public String getPluginInfo(String tag, String def) {
@ -313,11 +303,11 @@ public class SubscribeTask implements Runnable, Listener {
*/
public String[] getUpdateChanges() {
final String des = getPluginInfo("update.changes", null);
if (des == null) { return new String[] {}; }
if (des == null) { return new String[]{}; }
String[] temp = ChatColor.translateAlternateColorCodes('&', des).replaceAll("\n", "").replaceAll("\u0009", "").split(";");
List<String> ltemp = new ArrayList<>();
Arrays.stream(temp).forEach(s -> ltemp.add(s.trim()));
return ltemp.toArray(new String[] {});
return ltemp.toArray(new String[]{});
}
/**
@ -341,9 +331,9 @@ public class SubscribeTask implements Runnable, Listener {
/**
* 通知更新信息
*
*
* @param sender
* 命令接受者
* 命令接受者
*/
public void notify(CommandSender sender) {
Log.sender(sender, "§a插件更新: §b" + name + " §a已更新到最新版本 §bv" + getLastestVersion());
@ -367,9 +357,9 @@ public class SubscribeTask implements Runnable, Listener {
* 比较版本号
*
* @param v1
* 新版本
* 新版本
* @param v2
* 旧版本
* 旧版本
* @return 是否需要更新
*/
public boolean needUpdate(String v1, String v2) {
@ -379,7 +369,7 @@ public class SubscribeTask implements Runnable, Listener {
int minLength = Math.min(va1.length, va2.length);// 取最小长度值
int diff = 0;
while (idx < minLength && (diff = va1[idx].length() - va2[idx].length()) == 0// 先比较长度
&& (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符
&& (diff = va1[idx].compareTo(va2[idx])) == 0) {// 再比较字符
++idx;
}
// 如果已经分出大小 则直接返回 如果未分出大小 则再比较位数 有子版本的为大
@ -390,12 +380,11 @@ public class SubscribeTask implements Runnable, Listener {
public String getNewVersion() {
try {
String result = getLastestVersion();
if (version.contains("DEV") && !Log.isGlobalDebug()) {
if (Log.isDebug() && !Log.isGlobalDebug()) {
Log.console("§4注意: §c当前版本为开发版本 且未开启全局调试 已自动下载最新稳定版!");
return result;
}
String current = version.split("-")[0];
if (needUpdate(result, current)) { return result; }
if (needUpdate(result, version)) { return result; }
} catch (Exception e) {
Log.d(e);
}

View File

@ -0,0 +1,17 @@
package pw.yumc.YumCore.bukkit;
import org.junit.Assert;
import org.junit.Test;
/**
* Created with IntelliJ IDEA
*
* @author
* Created on 2017/8/22 15:16.
*/
public class LogTest {
@Test
public void testSimpleNames() {
Assert.assertTrue("[LogTest, LogTest, null]".equals(Log.getSimpleNames(this, this.getClass(), null)));
}
}