Remove update-check
This commit is contained in:
parent
e864468539
commit
d42affeac8
@ -7,7 +7,6 @@ import me.skymc.taboolib.commands.internal.BaseSubCommand;
|
||||
import me.skymc.taboolib.commands.internal.TCommand;
|
||||
import me.skymc.taboolib.commands.internal.type.CommandArgument;
|
||||
import me.skymc.taboolib.commands.internal.type.CommandRegister;
|
||||
import me.skymc.taboolib.commands.internal.type.CommandType;
|
||||
import me.skymc.taboolib.commands.taboolib.*;
|
||||
import me.skymc.taboolib.database.GlobalDataManager;
|
||||
import me.skymc.taboolib.inventory.ItemUtils;
|
||||
@ -17,7 +16,6 @@ import me.skymc.taboolib.timecycle.TimeCycle;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleEvent;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleManager;
|
||||
import me.skymc.taboolib.update.UpdateTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -209,11 +207,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 6)
|
||||
BaseSubCommand attributes = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "attributes";
|
||||
@ -238,11 +231,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 7)
|
||||
BaseSubCommand enchants = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "enchants";
|
||||
@ -267,11 +255,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 8)
|
||||
BaseSubCommand potions = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "potions";
|
||||
@ -296,11 +279,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 9)
|
||||
BaseSubCommand flags = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "flags";
|
||||
@ -325,11 +303,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 10)
|
||||
BaseSubCommand slots = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "slots";
|
||||
@ -354,11 +327,6 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
@CommandRegister(priority = 11)
|
||||
BaseSubCommand sounds = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public boolean hideInHelp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "sounds";
|
||||
@ -849,35 +817,4 @@ public class TabooLibMainCommand extends BaseMainCommand {
|
||||
new ImportCommand(sender, args);
|
||||
}
|
||||
};
|
||||
|
||||
@CommandRegister(priority = 28)
|
||||
BaseSubCommand updatePlugin = new BaseSubCommand() {
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return "updatePlugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return TLocale.asString("COMMANDS.TABOOLIB.UPDATEPLUGIN.DESCRIPTION");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandArgument[] getArguments() {
|
||||
return new CommandArgument[] {
|
||||
new CommandArgument(TLocale.asString("COMMANDS.TABOOLIB.UPDATEPLUGIN.ARGUMENTS.0"), false)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
UpdateTask.updatePlugin(true, args.length > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandType getType() {
|
||||
return CommandType.CONSOLE;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package me.skymc.taboolib.listener;
|
||||
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.playerdata.DataUtils;
|
||||
import me.skymc.taboolib.translateuuid.TranslateUUID;
|
||||
import me.skymc.taboolib.update.UpdateTask;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,9 +15,6 @@ public class ListenerPlayerJoinAndQuit implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (UpdateTask.isHaveUpdate() && e.getPlayer().hasPermission("taboolib.update.notify")) {
|
||||
TLocale.Logger.sendTo(e.getPlayer(), "UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(UpdateTask.getNewVersion()));
|
||||
}
|
||||
if (TranslateUUID.isEnabled()) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Main.getInst(), () -> TranslateUUID.updateUsername(e.getPlayer().getUniqueId(), e.getPlayer().getName()));
|
||||
}
|
||||
|
@ -1,136 +0,0 @@
|
||||
package me.skymc.taboolib.update;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.common.schedule.TSchedule;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import me.skymc.taboolib.player.PlayerUtils;
|
||||
import me.skymc.taboolib.plugin.PluginUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月23日 下午10:39:14
|
||||
*/
|
||||
public class UpdateTask {
|
||||
|
||||
private static double newVersion = 0;
|
||||
private static double length = -1;
|
||||
private static int updateLocationUsing;
|
||||
private static String[][] updateLocation = {
|
||||
{
|
||||
"https://api.github.com/repos/Bkm016/TabooLib/releases",
|
||||
"https://github.com/Bkm016/TabooLib/releases/download/?/TabooLib-?.jar"
|
||||
},
|
||||
{
|
||||
"https://gitee.com/bkm016/TabooLibCloud/raw/master/release.json",
|
||||
"https://gitee.com/bkm016/TabooLibCloud/raw/master/core/TabooLib.jar"
|
||||
}
|
||||
};
|
||||
|
||||
@TSchedule(async = true, delay = 100, period = 20 * 60 * 60 * 6)
|
||||
static void update() {
|
||||
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK", true)) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < updateLocation.length; i++) {
|
||||
String[] location = updateLocation[i];
|
||||
String value = FileUtils.getStringFromURL(location[0], null);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
JsonElement json = new JsonParser().parse(value);
|
||||
if (json.isJsonArray()) {
|
||||
JsonObject releaseData = json.getAsJsonArray().get(0).getAsJsonObject();
|
||||
updateLocationUsing = i;
|
||||
newVersion = releaseData.get("tag_name").getAsDouble();
|
||||
// 获取文件长度
|
||||
for (JsonElement assetData : releaseData.getAsJsonArray("assets")) {
|
||||
if (assetData instanceof JsonObject && ((JsonObject) assetData).get("name").getAsString().equals("TabooLib-" + newVersion + ".jar")) {
|
||||
length = ((JsonObject) assetData).get("size").getAsInt();
|
||||
}
|
||||
}
|
||||
if (TabooLib.getPluginVersion() >= newVersion) {
|
||||
TLocale.Logger.info("UPDATETASK.VERSION-LATEST");
|
||||
} else {
|
||||
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
|
||||
// 是否启用启动下载
|
||||
if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
|
||||
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> updatePlugin(true, false));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
TLocale.Logger.error("UPDATETASK.VERSION-FAIL");
|
||||
}
|
||||
|
||||
public static boolean isHaveUpdate() {
|
||||
return newVersion > TabooLib.getPluginVersion();
|
||||
}
|
||||
|
||||
public static double getNewVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public static int getUpdateLocationUsing() {
|
||||
return updateLocationUsing;
|
||||
}
|
||||
|
||||
public static String[][] getUpdateLocation() {
|
||||
return updateLocation;
|
||||
}
|
||||
|
||||
public static void updatePlugin(boolean shutdown, boolean force) {
|
||||
File pluginFile = PluginUtils.getPluginFile(Main.getInst());
|
||||
if (pluginFile == null) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.FILE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
if (!UpdateTask.isHaveUpdate() && (newVersion == 0 || !force)) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND");
|
||||
return;
|
||||
}
|
||||
if (length < 0) {
|
||||
TLocale.Logger.error("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND-SIZE");
|
||||
return;
|
||||
}
|
||||
if (PlayerUtils.getOnlinePlayers().size() > 0) {
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.PLAYER-ONLINE");
|
||||
return;
|
||||
}
|
||||
// 创建临时文件
|
||||
File tempFile = new File(Main.getInst().getDataFolder(), "update" + File.separator + "TabooLib-" + newVersion + ".jar");
|
||||
FileUtils.createNewFileAndPath(tempFile);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(TabooLib.instance(), () -> {
|
||||
FileUtils.download(updateLocation[updateLocationUsing][1].replace("?", String.valueOf(newVersion)), tempFile);
|
||||
// 判断文件长度是否与标准长度相同
|
||||
if (tempFile.length() != length) {
|
||||
TLocale.Logger.error("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-FAILED");
|
||||
} else {
|
||||
// 覆盖插件文件
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(tempFile)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(pluginFile))) {
|
||||
while ((len = inputStream.read(buf)) > 0) {
|
||||
outputStream.write(buf, 0, len);
|
||||
}
|
||||
outputStream.flush();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return;
|
||||
}
|
||||
TLocale.Logger.info("COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-SUCCESS");
|
||||
if (shutdown) {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user