diff --git a/pom.xml b/pom.xml
index c7ea8c9..e89eeb8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.skymc
TabooLib
- 4.07
+ 4.08
UTF-8
diff --git a/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java
index 2db286c..a97cfeb 100644
--- a/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java
+++ b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java
@@ -1,14 +1,24 @@
package me.skymc.taboolib.commands;
import com.ilummc.tlib.resources.TLocale;
+import com.ilummc.tlib.util.Strings;
+import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.internal.BaseMainCommand;
import me.skymc.taboolib.commands.internal.BaseSubCommand;
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.fileutils.FileUtils;
import me.skymc.taboolib.inventory.ItemUtils;
+import me.skymc.taboolib.plugin.PluginUtils;
+import me.skymc.taboolib.update.UpdateTask;
+import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.io.File;
/**
* @Author sky
@@ -723,4 +733,59 @@ public class TabooLibMainCommand extends BaseMainCommand {
new ImportCommand(sender, args);
}
};
+
+ @CommandRegister(priority = 26)
+ 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[0];
+ }
+
+ @Override
+ public void onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (!UpdateTask.isHaveUpdate()) {
+ TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-FOUND");
+ return;
+ }
+
+ File file = new File("plugins/update");
+ if (!file.exists()) {
+ TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-NOT-SUPPORT");
+ return;
+ }
+
+ File pluginFile = PluginUtils.getPluginFile(Main.getInst());
+ if (pluginFile == null) {
+ TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.FILE-NOT-FOUND");
+ return;
+ }
+
+ new BukkitRunnable() {
+
+ @Override
+ public void run() {
+ String url = Strings.replaceWithOrder("https://github.com/Bkm016/TabooLib/releases/download/{0}/TabooLib-{0}.jar", UpdateTask.getNewVersion());
+ TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-START", url);
+ FileUtils.download(url, new File(file, pluginFile.getName()));
+ TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-SUCCESS");
+ }
+ }.runTaskAsynchronously(Main.getInst());
+ }
+
+ @Override
+ public CommandType getType() {
+ return CommandType.CONSOLE;
+ }
+ };
}
diff --git a/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java b/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java
index c2669d9..36ac981 100644
--- a/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java
+++ b/src/main/java/me/skymc/taboolib/commands/internal/BaseMainCommand.java
@@ -109,7 +109,7 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
continue;
}
if (!isConfirmType(sender, subCommand.getType())) {
- TLocale.sendTo(sender, "COMMANDS.INTERNAL.ONLY-PLAYER", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType()));
+ TLocale.sendTo(sender, "COMMANDS.INTERNAL.TYPE-ERROR", args[0], TLocale.asString("COMMANDS.INTERNAL.TYPE-" + subCommand.getType()));
return true;
}
String[] subCommandArgs = ArrayUtils.removeFirst(args);
@@ -166,7 +166,9 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
}
private boolean isConfirmType(CommandSender sender, CommandType commandType) {
- return commandType == CommandType.ALL || (sender instanceof Player && commandType == CommandType.PLAYER);
+ return commandType == CommandType.ALL
+ || (sender instanceof Player && commandType == CommandType.PLAYER)
+ || (sender instanceof ConsoleCommandSender && commandType == CommandType.CONSOLE);
}
private void helpCommand(CommandSender sender, String label) {
diff --git a/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java b/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java
index 4f80d08..42a0a86 100644
--- a/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java
+++ b/src/main/java/me/skymc/taboolib/commands/plugin/TabooLibPluginMainCommand.java
@@ -7,6 +7,9 @@ import me.skymc.taboolib.commands.internal.BaseSubCommand;
import me.skymc.taboolib.commands.internal.ISubCommand;
import me.skymc.taboolib.commands.internal.type.CommandArgument;
import me.skymc.taboolib.commands.internal.type.CommandRegister;
+import me.skymc.taboolib.plugin.PluginLoadState;
+import me.skymc.taboolib.plugin.PluginLoadStateType;
+import me.skymc.taboolib.plugin.PluginUnloadState;
import me.skymc.taboolib.plugin.PluginUtils;
import me.skymc.taboolib.string.ArrayUtils;
import org.bukkit.Bukkit;
@@ -62,16 +65,29 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
String name = ArrayUtils.arrayJoin(args, 0);
if (PluginUtils.getPluginByName(name) != null) {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-PLUGIN", name);
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-PLUGIN", name, name + " already loaded!");
} else {
- switch (PluginUtils.load(name)) {
- case "loaded": {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-SUCCESS", name);
+ PluginLoadState loadState;
+ try {
+ loadState = PluginUtils.load(name);
+ } catch (Exception e) {
+ loadState = new PluginLoadState(PluginLoadStateType.INVALID_PLUGIN, e.toString());
+ }
+ switch (loadState.getStateType()) {
+ case INVALID_DESCRIPTION: {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-DESCRIPTION");
break;
}
- default: {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-FAIL", name);
+ case INVALID_PLUGIN: {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.INVALID-PLUGIN", name, loadState.getMessage());
+ break;
}
+ case FILE_NOT_FOUND: {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.FILE-NOT-FOUND", name);
+ break;
+ }
+ default:
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-SUCCESS", name);
}
}
}
@@ -104,14 +120,16 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
} else if (PluginUtils.isIgnored(plugin)) {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.INVALID-PLUGIN-IGNORED", name);
} else {
- switch (PluginUtils.unload(plugin)) {
- case "unloaded": {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-SUCCESS", name);
- break;
- }
- default: {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-FAIL", name);
- }
+ PluginUnloadState unloadState;
+ try {
+ unloadState = PluginUtils.unload(plugin);
+ } catch (Exception e) {
+ unloadState = new PluginUnloadState(true, e.toString());
+ }
+ if (unloadState.isFailed()) {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-FAIL", name, unloadState.getMessage());
+ } else {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-SUCCESS", name);
}
}
}
@@ -185,9 +203,9 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
String.valueOf(plugin.getDescription().getMain()),
String.valueOf(plugin.getDescription().getVersion()),
String.valueOf(plugin.getDescription().getWebsite()),
- String.valueOf(plugin.getDescription().getCommands().keySet()));
- } catch (Exception ignored) {
- TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-PLUGIN", name);
+ String.valueOf(plugin.getDescription().getCommands() == null ? "" : plugin.getDescription().getCommands().keySet()));
+ } catch (Exception e) {
+ TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-DESCRIPTION", name, e.getMessage());
}
}
}
@@ -213,7 +231,7 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
@Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) {
- List pluginList = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList());
+ List pluginList = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(PluginUtils::getFormattedName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList());
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LIST.LIST-PLUGIN", String.valueOf(Bukkit.getPluginManager().getPlugins().length), Joiner.on(", ").join(pluginList));
}
};
diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
index a0afd4d..676e092 100644
--- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
+++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java
@@ -119,7 +119,7 @@ public class FileUtils {
*
* @param file 文件夹
*/
- public void deleteAllFile(File file) {
+ public static void deleteAllFile(File file) {
if (!file.exists()) {
return;
}
@@ -139,7 +139,7 @@ public class FileUtils {
* @param file1 文件1
* @param file2 文件2
*/
- public void copyAllFile(String file1, String file2) {
+ public static void copyAllFile(String file1, String file2) {
File _file1 = new File(file1);
File _file2 = new File(file2);
if (!_file2.exists()) {
@@ -168,7 +168,7 @@ public class FileUtils {
* @param file1 文件1
* @param file2 文件2
*/
- public void fileChannelCopy(File file1, File file2) {
+ public static void fileChannelCopy(File file1, File file2) {
FileInputStream fileIn = null;
FileOutputStream fileOut = null;
FileChannel channelIn = null;
diff --git a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java
index 94ecc74..7c24b14 100644
--- a/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java
+++ b/src/main/java/me/skymc/taboolib/nms/NMSUtil19.java
@@ -911,7 +911,7 @@ public class NMSUtil19 {
}
public static Class> getBukkitClass(String className) {
- Class> result = null;
+ Class> result;
try {
result = fixBukkitClass(className);
} catch (Exception ex) {
@@ -930,6 +930,7 @@ public class NMSUtil19 {
try {
return NMSUtils.class.getClassLoader().loadClass(className);
} catch (ClassNotFoundException ignored) {
+ return null;
}
}
diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginLoadState.java b/src/main/java/me/skymc/taboolib/plugin/PluginLoadState.java
new file mode 100644
index 0000000..59b7250
--- /dev/null
+++ b/src/main/java/me/skymc/taboolib/plugin/PluginLoadState.java
@@ -0,0 +1,24 @@
+package me.skymc.taboolib.plugin;
+
+/**
+ * @Author sky
+ * @Since 2018-06-01 21:34
+ */
+public class PluginLoadState {
+
+ private final PluginLoadStateType stateType;
+ private final String message;
+
+ public PluginLoadState(PluginLoadStateType stateType, String message) {
+ this.stateType = stateType;
+ this.message = message;
+ }
+
+ public PluginLoadStateType getStateType() {
+ return stateType;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginLoadStateType.java b/src/main/java/me/skymc/taboolib/plugin/PluginLoadStateType.java
new file mode 100644
index 0000000..15c98b3
--- /dev/null
+++ b/src/main/java/me/skymc/taboolib/plugin/PluginLoadStateType.java
@@ -0,0 +1,34 @@
+package me.skymc.taboolib.plugin;
+
+/**
+ * @Author sky
+ * @Since 2018-06-01 21:32
+ */
+public enum PluginLoadStateType {
+
+ /**
+ * 目录不存在
+ */
+ DIRECTORY_NOT_FOUND,
+
+ /**
+ * 插件不存在
+ */
+ FILE_NOT_FOUND,
+
+ /**
+ * 无效的描述
+ */
+ INVALID_DESCRIPTION,
+
+ /**
+ * 无效的插件
+ */
+ INVALID_PLUGIN,
+
+ /**
+ * 载入成功
+ */
+ LOADED
+
+}
diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUnloadState.java b/src/main/java/me/skymc/taboolib/plugin/PluginUnloadState.java
new file mode 100644
index 0000000..5e94809
--- /dev/null
+++ b/src/main/java/me/skymc/taboolib/plugin/PluginUnloadState.java
@@ -0,0 +1,24 @@
+package me.skymc.taboolib.plugin;
+
+/**
+ * @Author sky
+ * @Since 2018-06-01 21:39
+ */
+public class PluginUnloadState {
+
+ private final boolean failed;
+ private final String message;
+
+ public PluginUnloadState(boolean failed, String message) {
+ this.failed = failed;
+ this.message = message;
+ }
+
+ public boolean isFailed() {
+ return failed;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java
index a592f4c..30d3a53 100644
--- a/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java
+++ b/src/main/java/me/skymc/taboolib/plugin/PluginUtils.java
@@ -1,8 +1,3 @@
-//
-// Source code recreated from a .class file by IntelliJ IDEA
-// (powered by Fernflower decompiler)
-//
-
package me.skymc.taboolib.plugin;
import com.google.common.base.Joiner;
@@ -26,16 +21,33 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
+/**
+ * @author PluginMan
+ */
public class PluginUtils {
- private PluginUtils() {
+ PluginUtils() {
+ }
+
+ public static File getPluginFile(Plugin plugin) {
+ for (File pluginFile : Objects.requireNonNull(new File("plugins").listFiles())) {
+ if (pluginFile.getName().endsWith(".jar")) {
+ try {
+ PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(pluginFile);
+ if (desc.getName().equalsIgnoreCase(plugin.getName())) {
+ return pluginFile;
+ }
+ } catch (InvalidDescriptionException ignored) {
+ }
+ }
+ }
+ return null;
}
public static void enable(Plugin plugin) {
if (plugin != null && !plugin.isEnabled()) {
Bukkit.getPluginManager().enablePlugin(plugin);
}
-
}
public static void disable(Plugin plugin) {
@@ -45,11 +57,11 @@ public class PluginUtils {
}
public static void enableAll() {
- Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> isIgnored(plugin)).forEach(PluginUtils::enable);
+ Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(PluginUtils::isIgnored).forEach(PluginUtils::enable);
}
public static void disableAll() {
- Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> isIgnored(plugin)).forEach(PluginUtils::disable);
+ Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(PluginUtils::isIgnored).forEach(PluginUtils::disable);
}
public static String getFormattedName(Plugin plugin) {
@@ -58,7 +70,7 @@ public class PluginUtils {
public static String getFormattedName(Plugin plugin, boolean includeVersions) {
ChatColor color = plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED;
- String pluginName = color + plugin.getName();
+ String pluginName = color + plugin.getName() + ChatColor.RESET;
if (includeVersions) {
pluginName = pluginName + " (" + plugin.getDescription().getVersion() + ")";
}
@@ -89,9 +101,8 @@ public class PluginUtils {
Map commands = plugin.getDescription().getCommands();
if (commands != null) {
for (Object o : commands.entrySet()) {
- Entry thisEntry = (Entry) o;
- if (thisEntry != null) {
- parsedCommands.add((String) thisEntry.getKey());
+ if (o != null) {
+ parsedCommands.add((String) ((Entry) o).getKey());
}
}
}
@@ -158,37 +169,28 @@ public class PluginUtils {
return plugin.equals(Main.getInst());
}
- private static String load(Plugin plugin) {
+ private static PluginLoadState load(Plugin plugin) {
return load(plugin.getName());
}
- /**
- * 返回内容:
- *
- * plugin-directory —— 插件目录不存在
- * cannot-find —— 插件不存在
- * invalid-description —— 无效的描述
- * invalid-plugin —— 无效的插件
- * loaded —— 载入成功
- */
- public static String load(String name) {
+ public static PluginLoadState load(String name) {
Plugin target;
File pluginDir = new File("plugins");
if (!pluginDir.isDirectory()) {
- return "plugin-directory";
+ return new PluginLoadState(PluginLoadStateType.DIRECTORY_NOT_FOUND, "null");
} else {
File pluginFile = new File(pluginDir, name + ".jar");
- if (!pluginFile.isFile()) {
- for (File f : Objects.requireNonNull(pluginDir.listFiles())) {
- if (f.getName().endsWith(".jar")) {
+ if (!pluginFile.exists()) {
+ for (File plugin : Objects.requireNonNull(pluginDir.listFiles())) {
+ if (plugin.getName().endsWith(".jar")) {
try {
- PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(f);
+ PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(plugin);
if (desc.getName().equalsIgnoreCase(name)) {
- pluginFile = f;
+ pluginFile = plugin;
break;
}
- } catch (InvalidDescriptionException var11) {
- return "cannot-find";
+ } catch (InvalidDescriptionException ignored) {
+ return new PluginLoadState(PluginLoadStateType.FILE_NOT_FOUND, "null");
}
}
}
@@ -196,15 +198,15 @@ public class PluginUtils {
try {
target = Bukkit.getPluginManager().loadPlugin(pluginFile);
- } catch (InvalidDescriptionException var9) {
- return "invalid-description";
- } catch (InvalidPluginException var10) {
- return "invalid-plugin";
+ } catch (InvalidDescriptionException e) {
+ return new PluginLoadState(PluginLoadStateType.INVALID_DESCRIPTION, e.toString());
+ } catch (InvalidPluginException e) {
+ return new PluginLoadState(PluginLoadStateType.INVALID_PLUGIN, e.toString());
}
target.onLoad();
Bukkit.getPluginManager().enablePlugin(target);
- return "loaded";
+ return new PluginLoadState(PluginLoadStateType.LOADED, "null");
}
}
@@ -213,20 +215,13 @@ public class PluginUtils {
unload(plugin);
load(plugin);
}
-
}
public static void reloadAll() {
Arrays.stream(Bukkit.getPluginManager().getPlugins(), 0, Bukkit.getPluginManager().getPlugins().length).filter(PluginUtils::isIgnored).forEach(PluginUtils::reload);
}
- /**
- * 返回内容:
- *
- * failed —— 卸载失败
- * unloaded —— 卸载成功
- */
- public static String unload(Plugin plugin) {
+ public static PluginUnloadState unload(Plugin plugin) {
String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
@@ -236,7 +231,6 @@ public class PluginUtils {
Map> listeners = null;
if (pluginManager != null) {
pluginManager.disablePlugin(plugin);
-
try {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
pluginsField.setAccessible(true);
@@ -259,8 +253,8 @@ public class PluginUtils {
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
commands = (Map) knownCommandsField.get(commandMap);
- } catch (NoSuchFieldException | IllegalAccessException var15) {
- return "failed";
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ return new PluginUnloadState(true, e.toString());
}
}
@@ -276,10 +270,8 @@ public class PluginUtils {
Iterator it;
if (listeners != null) {
it = listeners.values().iterator();
-
while (it.hasNext()) {
SortedSet set = (SortedSet) it.next();
-
while (it.hasNext()) {
RegisteredListener value = (RegisteredListener) it.next();
if (value.getPlugin() == plugin) {
@@ -291,7 +283,6 @@ public class PluginUtils {
if (commandMap != null) {
it = commands.entrySet().iterator();
-
while (it.hasNext()) {
Entry entry = (Entry) it.next();
if (entry.getValue() instanceof PluginCommand) {
@@ -312,7 +303,7 @@ public class PluginUtils {
Logger.getLogger(PluginUtils.class.getName()).log(Level.SEVERE, null, var13);
}
}
- return "unloaded";
+ return new PluginUnloadState(false, "null");
}
private static String consolidateStrings(String[] args, int start) {
diff --git a/src/main/java/me/skymc/taboolib/update/UpdateTask.java b/src/main/java/me/skymc/taboolib/update/UpdateTask.java
index ee4f992..6d469ca 100644
--- a/src/main/java/me/skymc/taboolib/update/UpdateTask.java
+++ b/src/main/java/me/skymc/taboolib/update/UpdateTask.java
@@ -7,6 +7,7 @@ import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.fileutils.FileUtils;
+import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
/**
@@ -26,9 +27,6 @@ public class UpdateTask {
return newVersion;
}
- /**
- * 旧地址:https://internal.github.com/repos/Bkm016/TabooLib/releases/latest
- */
public UpdateTask() {
new BukkitRunnable() {
@@ -53,6 +51,15 @@ public class UpdateTask {
} else {
haveUpdate = true;
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion));
+
+ new BukkitRunnable() {
+ @Override
+ public void run() {
+ if (Main.getInst().getConfig().getBoolean("UPDATE-DOWNLOAD", false)) {
+ Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "taboolib updatePlugin");
+ }
+ }
+ }.runTask(Main.getInst());
}
}
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 9f49274..72b53ab 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -41,6 +41,9 @@ TABLIST-SORT: false
# 是否启用更新检测
UPDATE-CHECK: true
+# 是否启用自动更新
+UPDATE-DOWNLOAD: false
+
# 是否在关闭服务器时清理玩家数据
# 该配置将在启用数据库储存时失效
DELETE-DATA: false
diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml
index 2f4ae64..4ca772c 100644
--- a/src/main/resources/lang/zh_CN.yml
+++ b/src/main/resources/lang/zh_CN.yml
@@ -157,7 +157,7 @@ COMMANDS:
ONLY-PLAYER: '&8[&3&lTabooLib&8] &4控制台无法这么做'
ONLY-STORAGE-SQL: '&8[&3&lTabooLib&8] &4只有启用数据库储存时才能这么做'
INTERNAL:
- ONLY-PLAYER: '&8[&3&lTabooLib&8] &7指令 &f{0} &7只能由 &f{1} &7执行'
+ TYPE-ERROR: '&8[&3&lTabooLib&8] &7指令 &f{0} &7只能由 &f{1} &7执行'
TYPE-PLAYER: 玩家
TYPE-CONSOLE: 控制台
ERROR-USAGE:
@@ -230,6 +230,13 @@ COMMANDS:
IMPORTING-START: '&8[&3&lTabooLib&8] &7开始导入 &f{0} &7项玩家数据'
IMPORTING-PROGRESS: '&8[&3&lTabooLib&8] &7导入玩家数据: &f{0} &7进度: &f{1}/{2}'
SUCCESS: '&8[&3&lTabooLib&8] &7导入完成'
+ UPDATEPLUGIN:
+ DESCRIPTION: '&4更新插件 &8(谨防非正规途径的插件获取方式)'
+ UPDATE-NOT-FOUND: '&8[&3&lTabooLib&8] &7插件已是最新版, 无需更新!'
+ UPDATE-NOT-SUPPORT: '&8[&3&lTabooLib&8] &4您的服务器不支持在线更新!'
+ FILE-NOT-FOUND: '&8[&3&lTabooLib&8] &4尚未寻找到插件文件'
+ UPDATE-START: '&8[&3&lTabooLib&8] &7开始下载:&f {0}'
+ UPDATE-SUCCESS: '&8[&3&lTabooLib&8] &7最新版下载完成, 重启服务器自动更新!'
JAVASHELL:
DESCRIPTION:
LOAD: '载入脚本'
@@ -470,6 +477,7 @@ COMMANDS:
ARGUMENTS:
0: '名称'
INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在'
+ INVALID-DESCRIPTION: '&8[&3&lTabooLib&8] &4获取插件 &c{0} &4信息失败: &c{1}'
INFO-PLUGIN:
- '&8[&3&lTabooLib&8] &7插件名称: &f{0}'
- '&8[&3&lTabooLib&8] &7描述: &f{1}'
@@ -484,9 +492,10 @@ COMMANDS:
DESCRIPTION: '载入插件'
ARGUMENTS:
0: '名称'
- INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4已经载入'
+ INVALID-DESCRIPTION: '&8[&3&lTabooLib&8] &4插件目录不存在'
+ INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4载入失败: &c{1}'
+ FILE-NOT-FOUND: '&8[&3&lTabooLib&8] &4插件 &c{0} &4文件不存在'
LOAD-SUCCESS: '&8[&3&lTabooLib&8] &7插件已载入'
- LOAD-FAIL: '&8[&3&lTabooLib&8] &7插件载入失败'
UNLOAD:
DESCRIPTION: '卸载插件'
ARGUMENTS:
@@ -494,7 +503,7 @@ COMMANDS:
INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在'
INVALID-PLUGIN-IGNORED: '&8[&3&lTabooLib&8] &4插件 &c{0} &4无法操作'
UNLOAD-SUCCESS: '&8[&3&lTabooLib&8] &7插件已卸载'
- UNLOAD-FAIL: '&8[&3&lTabooLib&8] &7插件卸载失败'
+ UNLOAD-FAIL: '&8[&3&lTabooLib&8] &4插件 &c{0} &e卸载失败: &c{1}'
RELOAD:
DESCRIPTION: '重载插件'
ARGUMENTS: