Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
修改更新器 支持手动检查更新
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaMoHuaHuo-CN committed Jun 2, 2022
1 parent 8e84aad commit 10336d7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>moe.xmcn.catsero</groupId>
<artifactId>CatSero</artifactId>
<version>1.1.2-pre1</version>
<version>1.1.2-pre2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/moe/xmcn/catsero/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.logging.Level;

/**
* 主类
* 注册监听器
Expand All @@ -26,7 +28,7 @@ public class Main extends JavaPlugin {
public void onLoad() {
Config.INSTANCE.saveDefConfig();
ThisAPI.Companion.savXMCore("xmcore.info");
System.out.println("[CatSero] 正在加载CatSero插件");
getLogger().log(Level.INFO, "[CatSero] 正在加载CatSero插件");
if (Config.INSTANCE.getConfig().getBoolean("allow-start-warn")) {
getLogger().warning("请确保正在使用CatSero官方的构建版本,本人只为官方版本提供支持");
}
Expand All @@ -44,19 +46,20 @@ public void onEnable() {
// bStats
if (Config.INSTANCE.getConfig().getBoolean("allow-bstats")) {
int pluginId = 14767;
new Metrics((JavaPlugin) Config.INSTANCE.getPlugin(), pluginId);
new Metrics(this, pluginId);
}

// 启动TPS计算程序
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new ServerTPS(), 100L, 1L);

System.out.println("CatSero插件加载成功");
getLogger().log(Level.INFO, "CatSero插件加载成功");

// 异步加载更新检查器
new BukkitRunnable() {
@Override
public void run() {
Updater.startUpdateCheck();
getLogger().log(Level.INFO, "开始检查更新...");
getLogger().log(Level.INFO, Updater.startUpdateCheck());
}
}.runTaskAsynchronously(this);
} else {
Expand All @@ -70,7 +73,7 @@ public void run() {
*/
@Override
public void onDisable() {
System.out.println("正在卸载CatSero插件");
getLogger().log(Level.INFO, "正在卸载CatSero插件");
}

/**
Expand All @@ -79,13 +82,13 @@ public void onDisable() {
*/
public void regiserEvents() {

System.out.println("正在注册事件 -> 监听器:CommandExecutor");
getLogger().log(Level.INFO, "正在注册事件 -> 监听器:CommandExecutor");
// catsero命令
Bukkit.getPluginCommand("catsero").setExecutor(new moe.xmcn.catsero.events.commands.CatSero());
// csm命令
Bukkit.getPluginCommand("csm").setExecutor(new moe.xmcn.catsero.events.commands.SendMessageQQ());

System.out.println("正在注册事件 -> 监听器:Listener");
getLogger().log(Level.INFO, "正在注册事件 -> 监听器:Listener");
// PingHost功能
getServer().getPluginManager().registerEvents(new OnQQGroupMessage(), this);

Expand Down
13 changes: 5 additions & 8 deletions src/main/java/moe/xmcn/catsero/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Updater(String name, String durl, String devname, String devdurl) {
this.devdurl = devdurl;
}

public static void startUpdateCheck() {
public static String startUpdateCheck() {
String nowversion = Config.INSTANCE.getPluginInfo().getString("version");
Plugin plugin = moe.xmcn.catsero.Main.getPlugin(moe.xmcn.catsero.Main.class);
if (plugin.getConfig().getBoolean("check-update.enabled")) {
Expand All @@ -34,17 +34,14 @@ public static void startUpdateCheck() {
Updater updater = gson.fromJson(datajson, Updater.class);
String[] upregex = String.valueOf(updater).split("╳");
if (Objects.equals(nowversion, "dev")) {
System.out.println(ChatColor.GREEN + "最新构建ID:" + upregex[2]);
System.out.println(ChatColor.GREEN + "下载地址:" + ChatColor.YELLOW + upregex[3]);
return ChatColor.GREEN + "最新构建ID:" + upregex[2] + ChatColor.GREEN + "下载地址:" + ChatColor.YELLOW + upregex[3];
} else if (!Objects.equals(upregex[0], nowversion) && !nowversion.contains("pre") && Objects.equals(nowversion, "passed")) {
System.out.println(nowversion);
System.out.println(ChatColor.GREEN + "已找到可用的更新:" + upregex[0]);
System.out.println(ChatColor.GREEN + "下载地址:" + ChatColor.YELLOW + upregex[1]);
return ChatColor.GREEN + "已找到可用的更新:" + upregex[0] + ChatColor.GREEN + "下载地址:" + ChatColor.YELLOW + upregex[1];
} else {
System.out.println("已是最新版本");
return "已是最新版本";
}
} else {
System.out.println("跳过更新检查");
return "跳过更新检查";
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/moe/xmcn/catsero/events/commands/CatSero.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package moe.xmcn.catsero.events.commands;

import moe.xmcn.catsero.Updater;
import moe.xmcn.catsero.events.gists.PingHost;
import moe.xmcn.catsero.events.gists.WeatherUtils;
import moe.xmcn.catsero.utils.Config;
Expand Down Expand Up @@ -133,6 +134,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Config.INSTANCE.getPrefix_MC() + Config.INSTANCE.getMsgByMsID("minecraft.undefined-usage")));
return false;
}
/*
手动检查更新
*/
} else if (args[0].equalsIgnoreCase("update")) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Config.INSTANCE.getPrefix_MC() + "&a开始检查更新..."));
sender.sendMessage(Updater.startUpdateCheck());
} else {
/*
无效方法
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void onMiraiGroupMessageEvent(MiraiGroupMessageEvent event) {
if (args[0].equalsIgnoreCase("catsero") && args[1].equalsIgnoreCase("ban")) {

if (event.getSenderID() == Config.INSTANCE.getQQ_OP()) {
System.out.println(event.getSenderID());
if (args.length == 5) {
Bukkit.getBanList(BanList.Type.NAME).addBan(args[2], args[3], null, null);
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/moe/xmcn/catsero/utils/ServerTPS.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package moe.xmcn.catsero.utils;

public class ServerTPS implements Runnable {
public static final long[] TICKS = new long[600];
public static int TICK_COUNT = 0;
public static long[] TICKS = new long[600];

public static double getTPS() {
return getTPS(100);
Expand Down

0 comments on commit 10336d7

Please sign in to comment.