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:
parent
e578f33608
commit
d767dba2e6
15
pom.xml
15
pom.xml
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,6 +375,13 @@ public class Log {
|
||||
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) + "]";
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
/**
|
||||
@ -49,7 +52,6 @@ public class P {
|
||||
/**
|
||||
* @param name
|
||||
* 命令名称
|
||||
*
|
||||
* @return 插件命令
|
||||
*/
|
||||
public static PluginCommand getCommand(String name) {
|
||||
@ -122,6 +124,16 @@ public class P {
|
||||
return instance.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量注册监听器
|
||||
*
|
||||
* @param listeners
|
||||
* 监听器
|
||||
*/
|
||||
public static void registerEvents(Listener... listeners) {
|
||||
Arrays.stream(listeners).forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, instance));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存文件
|
||||
*
|
||||
|
@ -61,7 +61,7 @@ public class CommandMain implements CommandExecutor {
|
||||
* 命令类
|
||||
* @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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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) {
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,11 @@ public class CommandSub implements TabExecutor {
|
||||
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(
|
||||
C.Player.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> (senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(player.getName(),
|
||||
lastWord))
|
||||
.forEach(
|
||||
player -> matchedPlayers.add(player.getName()));
|
||||
return matchedPlayers;
|
||||
}
|
||||
@ -206,7 +210,7 @@ public class CommandSub implements TabExecutor {
|
||||
* 子命令处理类
|
||||
* @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,7 +223,6 @@ public class CommandSub implements TabExecutor {
|
||||
}
|
||||
help = new CommandHelp(defCmd, cmds);
|
||||
buildCmdNameCache();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +238,7 @@ public class CommandSub implements TabExecutor {
|
||||
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警告
|
||||
@ -262,17 +265,16 @@ public class CommandSub implements TabExecutor {
|
||||
* 调用对象
|
||||
* @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());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* 检查间隔
|
||||
@ -111,6 +100,7 @@ public class SubscribeTask implements Runnable, Listener {
|
||||
* 更新类型
|
||||
*/
|
||||
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;
|
||||
@ -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[]{});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
}
|
||||
|
17
src/test/java/pw/yumc/YumCore/bukkit/LogTest.java
Normal file
17
src/test/java/pw/yumc/YumCore/bukkit/LogTest.java
Normal 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)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user