1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-12-25 07:08:52 +00:00

feat: 添加工作区更新方式(未测试)

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-04-22 14:26:15 +08:00
parent 46503e2c06
commit e8571c7269
5 changed files with 175 additions and 105 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<version>1.7</version>
<version>1.8</version>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
@ -50,10 +50,6 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>

View File

@ -70,8 +70,8 @@ public class CommandHelp {
public CommandHelp(CommandInfo defCmd, Collection<? extends CommandInfo> list) {
this.defCmd = defCmd;
cmdlist = new LinkedList<>(list);
cmdlist.sort(new CommandNameComparator());
cmdlist.sort(new CommandComparator());
cmdlist.sort(Comparator.comparing(CommandInfo::getName));
cmdlist.sort(Comparator.comparing(CommandInfo::getSort));
HELPPAGECOUNT = (int) Math.ceil((double) cmdlist.size() / LINES_PER_PAGE);
}
@ -143,38 +143,6 @@ public class CommandHelp {
return helpGenerator;
}
/**
* 命令名称比较器
*
* @since 2016年7月23日 下午4:17:18
* @author
*/
static class CommandNameComparator implements Comparator<CommandInfo> {
@Override
public int compare(CommandInfo o1, CommandInfo o2) {
return o1.getName().compareTo(o2.getName());
}
}
/**
* 命令排序比较器
*
* @since 2016年7月23日 下午4:17:18
* @author
*/
static class CommandComparator implements Comparator<CommandInfo> {
@Override
public int compare(CommandInfo o1, CommandInfo o2) {
if (o1.getSort() > o2.getSort()) {
return 1;
} else if (o1.getSort() == o2.getSort()) {
return 0;
} else {
return -1;
}
}
}
static class DefaultHelpGenerator implements HelpGenerator {
/**
* 消息配置

View File

@ -58,7 +58,7 @@ public class CommandInfo {
private boolean main;
private Cmd command;
private Help help;
private int sort;
private Integer sort;
private CommandParse parse;
/**
* 命令错误处理
@ -179,7 +179,7 @@ public class CommandInfo {
/**
* @return 命令排序
*/
public int getSort() {
public Integer getSort() {
return sort;
}

View File

@ -0,0 +1,109 @@
package pw.yumc.YumCore.text;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.junit.Test;
/**
* 加密工具类
*
* @author
* @since 2017/4/22
*/
public class Encrypt {
private static String key;
static {
try {
key = URLDecoder.decode("%E5%96%B5%E2%99%82%E5%91%9C", "UTF-8");
} catch (UnsupportedEncodingException ignored) {
}
}
/**
* 解密地址
*
* @param s
* 密串
* @return 解密后的地址
*/
public static String decode(String s) {
return decode(key, s);
}
/**
* 加密地址
*
* @param s
* 密串
* @return 加密后的地址
*/
public static String encode(String s) {
return encode(key, s);
}
/**
* 解密地址
*
* @param key
* 密钥
* @param s
* 密串
* @return 解密后的地址
*/
public static String decode(String key, String s) {
return process(key, s, false);
}
/**
* 加密地址
*
* @param key
* 密钥
* @param s
* 密串
* @return 加密后的地址
*/
public static String encode(String key, String s) {
return process(key, s, true);
}
private static String process(String key, String s, boolean isEncode) {
StringBuilder str = new StringBuilder();
int ch;
for (int i = 0, j = 0; i < s.length(); i++, j++) {
if (j > key.length() - 1) {
j = j % key.length();
}
if (isEncode) {
ch = s.codePointAt(i) + key.codePointAt(j);
} else {
ch = s.codePointAt(i) + 65535 - key.codePointAt(j);
}
if (ch > 65535) {
ch = ch % 65535;// ch - 33 = (ch - 33) % 95 ;
}
str.append((char) ch);
}
return str.toString();
}
@Test
public void test() {
//String src = "http://ci.yumc.pw/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
//String dest = "œ­­¥l`cœ¢c«¦¡œg¥©`ž¨›dWbX¬h¡“¤¨Œ®˜•–§¬Ÿªžs©¢¥™a’¦­¢›“”¨h­–¤˜™­hZcU§g£–¤";
//private static String direct = d("œ­­¥l`cœ¢c«¦¡œg¥©`ž¨›dWbX¬h¡“¤¨Œ®˜•–§¬Ÿªžs©¢¥™a’¦­¢›“”¨h­–¤˜™­hZcU§g£–¤");
// private static String direct = "http://ci.yumc.pw/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
//private static String maven = d("œ­­¥l`cœ¢c«¦¡œg¥©`¤¥®œ›Ÿž¥¡¤­¨§«`™¯ž§«¥œ¢§œaVe]¬dWcX¬hZeU§f^gV¤b£š§");
// private static String maven = "http://ci.yumc.pw/plugin/repository/everything/%1$s/%2$s/%3$s-%2$s.jar";
String src = "Authorization";
//String dest = "嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘟⚱咾嗤⚏哅嘖⚱咮嘚⚲哈嘖⚥品嗤⚹哏嗤⚶咽嘧⚩品嘩♱咩嘞⚣哋嘇⚧哌嘡⚣咿嘚♰哆嘖⚴";
System.out.println("\"" + encode(src) + "\"");
//System.out.println("\"" + decode(dest) + "\"");
}
@Test
public void t() {
System.out.println(decode("499521", "b¨¬ £šž ˜"));
}
}

View File

@ -4,6 +4,7 @@ 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;
import java.net.URLDecoder;
@ -30,6 +31,7 @@ import org.xml.sax.SAXException;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.tellraw.Tellraw;
import pw.yumc.YumCore.text.Encrypt;
/**
* 自动更新程序
@ -61,21 +63,7 @@ public class SubscribeTask implements Runnable, Listener {
*/
private static int interval = 25;
/**
* 直链下载
*/
private static String direct = d("œ­­¥l`cœ¢c«¦¡œg¥©`ž¨›dWbX¬h¡“¤¨Œ®˜•–§¬Ÿªžs©¢¥™a’¦­¢›“”¨h­–¤˜™­hZcU§g£–¤");
// private static String direct = "http://ci.yumc.pw/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
/**
* 构建下载
*/
private static String maven = d("œ­­¥l`cœ¢c«¦¡œg¥©`¤¥®œ›Ÿž¥¡¤­¨§«`™¯ž§«¥œ¢§œaVe]¬dWcX¬hZeU§f^gV¤b£š§");
// private static String maven = "http://ci.yumc.pw/plugin/repository/everything/%1$s/%2$s/%3$s-%2$s.jar";
/**
* 是否为Maven
*/
private boolean isMaven;
private UpdateType updateType;
/**
* 更新文件
*/
@ -89,17 +77,17 @@ public class SubscribeTask implements Runnable, Listener {
* 自动更新
*/
public SubscribeTask() {
this(false);
this(UpdateType.DIRECT);
}
/**
* 自动更新
*
* @param isMaven
* @param type
* 是否为Maven
*/
public SubscribeTask(boolean isMaven) {
this(false, isMaven);
public SubscribeTask(UpdateType type) {
this(false, type);
}
/**
@ -107,11 +95,11 @@ public class SubscribeTask implements Runnable, Listener {
*
* @param isSecret
* 是否为私有
* @param isMaven
* 是否为Maven
* @param type
* 更新类型
*/
public SubscribeTask(boolean isSecret, boolean isMaven) {
this("master", isSecret, isMaven);
public SubscribeTask(boolean isSecret, UpdateType type) {
this("master", isSecret, type);
}
/**
@ -121,13 +109,13 @@ public class SubscribeTask implements Runnable, Listener {
* 更新分支
* @param isSecret
* 是否为私有
* @param isMaven
* 是否为Maven
* @param type
* 更新类型
*/
public SubscribeTask(String branch, boolean isSecret, boolean isMaven) {
public SubscribeTask(String branch, boolean isSecret, UpdateType type) {
updateFile = new UpdateFile(instance);
versionInfo = new VersionInfo(branch, isSecret);
this.isMaven = isMaven;
updateType = type;
if (instance.isEnabled()) {
Bukkit.getPluginManager().registerEvents(this, instance);
Bukkit.getScheduler().runTaskTimerAsynchronously(instance, this, 0, interval * 1200);
@ -142,30 +130,6 @@ public class SubscribeTask implements Runnable, Listener {
}
}
/**
* 解密地址
*
* @param s
* 密串
* @return 解密后的地址
*/
public static String d(String s) {
String key = "499521";
StringBuilder str = new StringBuilder();
int ch;
for (int i = 0, j = 0; i < s.length(); i++, j++) {
if (j > key.length() - 1) {
j = j % key.length();
}
ch = (s.codePointAt(i) + 65535 - key.codePointAt(j));
if (ch > 65535) {
ch = ch % 65535;// ch - 33 = (ch - 33) % 95 ;
}
str.append((char) ch);
}
return str.toString();
}
@Override
public void run() {
update();
@ -185,14 +149,8 @@ public class SubscribeTask implements Runnable, Listener {
Log.d(e);
}
}
String download;
if (isMaven) {
download = String.format(maven, instance.getClass().getPackage().getName().replaceAll("\\.", "/"), result, instance.getName());
} else {
download = String.format(direct, instance.getName());
}
updateFile.update(download);
Log.d(d("‰©–¦š¢ sUW¤T¯^¨R…£Y¯Z¥Qbgg"), instance.getName(), version.split("-")[0], result);
updateFile.update(updateType.getDownloadUrl(instance, result));
Log.d(Encrypt.decode("嘊⚲哀嘖⚶哅嘣⚩咖嗕♧哏嗕⚸咁嘨♢咰嘤♢哒嗚⚵呼嗣♰咊"), instance.getName(), version.split("-")[0], result);
versionInfo.notify(Bukkit.getConsoleSender());
}
} catch (Exception e) {
@ -200,19 +158,56 @@ public class SubscribeTask implements Runnable, Listener {
}
}
public enum UpdateType {
/**
* 下载直连
*/
DIRECT(Encrypt.decode("嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘟⚱咾嗤♧咍嗙⚵咋嘡⚣哏嘩⚕哑嘘⚥品嘨⚵哂嘪⚮咞嘪⚫哈嘙♱咽嘧⚶哅嘛⚣咿嘩♱哐嘖⚴哃嘚⚶咋嗚♳咀嘨♰哆嘖⚴")),
// "http://ci.yumc.pw/job/%1$s/lastSuccessfulBuild/artifact/target/%1$s.jar";
/**
* Maven下载
*/
MAVEN(Encrypt.decode("嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘥⚮哑嘜⚫哊嗤⚴品嘥⚱哏嘞⚶哋嘧⚻咋嘚⚸品嘧⚻哐嘝⚫哊嘜♱咁嗦♦哏嗤♧咎嗙⚵咋嗚♵咀嘨♯咁嗧♦哏嗣⚬咽嘧")),
// "http://ci.yumc.pw/plugin/repository/everything/%1$s/%2$s/%3$s-%2$s.jar";
/**
* 工作区下载
*/
WS(Encrypt.decode("嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘟⚱咾嗤♧咍嗙⚵咋嘬⚵咋嘩⚣哎嘜⚧哐嗤♧咍嗙⚵咊嘟⚣哎"));
// "http://ci.yumc.pw/job/%1$s/ws/target/%1$s.jar"
String url;
UpdateType(String url) {
this.url = url;
}
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());
}
throw new UnsupportedOperationException();
}
}
public static class UpdateFile {
public File parent;
public File target;
public File temp;
private String k = Encrypt.decode("嗶⚷哐嘝⚱哎嘞⚼咽嘩⚫哋嘣");
private String v = Encrypt.decode("嗷⚣哏嘞⚥呼嘖⚰咮嘞⚑哆嘂⚻咪嘉⚏哕嘃⚓咙嗲");
public UpdateFile(Plugin plugin) {
String name = getPluginFile(plugin).getName();
parent = new File(d("¤¥®œ›Ÿ§h®¥–’¨žh"));
parent = new File(Encrypt.decode("嘥⚮哑嘜⚫哊嘨♱哑嘥⚦咽嘩⚧咋"));
if (!parent.exists()) {
parent.mkdirs();
}
target = new File(parent, name);
temp = new File(parent, name + d("b¨¬ £šž ˜"));
temp = new File(parent, name + Encrypt.decode("嗣⚦哋嘬⚰哈嘤⚣哀嘞⚰哃"));
}
public boolean isUpdated() {
@ -242,7 +237,9 @@ public class SubscribeTask implements Runnable, Listener {
}
public void update(String url) throws IOException {
Files.copy(new URL(url).openStream(), temp.toPath());
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestProperty(k, v);
Files.copy(conn.getInputStream(), temp.toPath());
temp.renameTo(target);
}
}
@ -251,12 +248,12 @@ public class SubscribeTask implements Runnable, Listener {
/**
* 直链POM
*/
private String url = d("œ­­¥¥kchœ¤–š¢ —¥c®hjbcjmpekcc©hZ¥`›¢­’«h^¨a¡£¦g­Ÿ");
private String url = Encrypt.decode("嘝⚶哐嘥⚵咖嗤♱咿嘤⚦哅嘣⚩咊嘣⚧哐嗤⚷咋嗪♲咎嗫♶咓嗥♻咎嗤⚲咋嗚⚵咋嘜⚫哐嗤⚴咽嘬♱咁嘨♱哌嘤⚯咊嘭⚯哈");
// private static String url = "https://coding.net/u/502647092/p/%s/git/raw/%s/pom.xml";
/**
* 构建POM
*/
private String pom = d("œ­­¥l`cœ¢c«¦¡œg¥©`ž¨›dW¤c¥š¨¦„©œœš¥¤š®¥w§š h–¤¥Ÿš˜¦`¤¨¦cªž ");
private String pom = Encrypt.decode("嘝⚶哐嘥♼咋嗤⚥哅嗣⚻哑嘢⚥咊嘥⚹咋嘟⚱咾嗤♧哏嗤⚮咽嘨⚶咯嘪⚥咿嘚⚵哏嘛⚷哈嗷⚷哅嘡⚦咋嘖⚴哐嘞⚨咽嘘⚶咋嘥⚱哉嗣⚺哉嘡");
// private static String pom = "http://ci.yumc.pw/job/%s/lastSuccessfulBuild/artifact/pom.xml";
/**