版本更新至 4.08

调整:优化 /tplugin 各项命令,更多提示。
修复:修复 BaseSubCommand 中仅允许控制台类型无效的错误。
新增:/tlib updatePlugin 命令用于下载更新。
新增:自动下载最新版(默认关闭)。
This commit is contained in:
坏黑 2018-06-03 21:10:00 +08:00
parent efeb088a70
commit 2c61f793f7
13 changed files with 262 additions and 84 deletions

View File

@ -6,7 +6,7 @@
<groupId>me.skymc</groupId> <groupId>me.skymc</groupId>
<artifactId>TabooLib</artifactId> <artifactId>TabooLib</artifactId>
<version>4.07</version> <version>4.08</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,14 +1,24 @@
package me.skymc.taboolib.commands; package me.skymc.taboolib.commands;
import com.ilummc.tlib.resources.TLocale; 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.BaseMainCommand;
import me.skymc.taboolib.commands.internal.BaseSubCommand; import me.skymc.taboolib.commands.internal.BaseSubCommand;
import me.skymc.taboolib.commands.internal.type.CommandArgument; import me.skymc.taboolib.commands.internal.type.CommandArgument;
import me.skymc.taboolib.commands.internal.type.CommandRegister; 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.commands.taboolib.*;
import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.inventory.ItemUtils; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
/** /**
* @Author sky * @Author sky
@ -723,4 +733,59 @@ public class TabooLibMainCommand extends BaseMainCommand {
new ImportCommand(sender, args); 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;
}
};
} }

View File

@ -109,7 +109,7 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
continue; continue;
} }
if (!isConfirmType(sender, subCommand.getType())) { 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; return true;
} }
String[] subCommandArgs = ArrayUtils.removeFirst(args); String[] subCommandArgs = ArrayUtils.removeFirst(args);
@ -166,7 +166,9 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
} }
private boolean isConfirmType(CommandSender sender, CommandType commandType) { 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) { private void helpCommand(CommandSender sender, String label) {

View File

@ -7,6 +7,9 @@ import me.skymc.taboolib.commands.internal.BaseSubCommand;
import me.skymc.taboolib.commands.internal.ISubCommand; import me.skymc.taboolib.commands.internal.ISubCommand;
import me.skymc.taboolib.commands.internal.type.CommandArgument; import me.skymc.taboolib.commands.internal.type.CommandArgument;
import me.skymc.taboolib.commands.internal.type.CommandRegister; 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.plugin.PluginUtils;
import me.skymc.taboolib.string.ArrayUtils; import me.skymc.taboolib.string.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -62,16 +65,29 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
public void onCommand(CommandSender sender, Command command, String label, String[] args) { public void onCommand(CommandSender sender, Command command, String label, String[] args) {
String name = ArrayUtils.arrayJoin(args, 0); String name = ArrayUtils.arrayJoin(args, 0);
if (PluginUtils.getPluginByName(name) != null) { 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 { } else {
switch (PluginUtils.load(name)) { PluginLoadState loadState;
case "loaded": { try {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-SUCCESS", name); 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; break;
} }
default: { case INVALID_PLUGIN: {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LOAD.LOAD-FAIL", name); 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)) { } else if (PluginUtils.isIgnored(plugin)) {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.INVALID-PLUGIN-IGNORED", name); TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.INVALID-PLUGIN-IGNORED", name);
} else { } else {
switch (PluginUtils.unload(plugin)) { PluginUnloadState unloadState;
case "unloaded": { 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); TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-SUCCESS", name);
break;
}
default: {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.UNLOAD.UNLOAD-FAIL", name);
}
} }
} }
} }
@ -185,9 +203,9 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
String.valueOf(plugin.getDescription().getMain()), String.valueOf(plugin.getDescription().getMain()),
String.valueOf(plugin.getDescription().getVersion()), String.valueOf(plugin.getDescription().getVersion()),
String.valueOf(plugin.getDescription().getWebsite()), String.valueOf(plugin.getDescription().getWebsite()),
String.valueOf(plugin.getDescription().getCommands().keySet())); String.valueOf(plugin.getDescription().getCommands() == null ? "" : plugin.getDescription().getCommands().keySet()));
} catch (Exception ignored) { } catch (Exception e) {
TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-PLUGIN", name); TLocale.sendTo(sender, "COMMANDS.TPLUGIN.INFO.INVALID-DESCRIPTION", name, e.getMessage());
} }
} }
} }
@ -213,7 +231,7 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
@Override @Override
public void onCommand(CommandSender sender, Command command, String label, String[] args) { public void onCommand(CommandSender sender, Command command, String label, String[] args) {
List<String> pluginList = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()); List<String> 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)); TLocale.sendTo(sender, "COMMANDS.TPLUGIN.LIST.LIST-PLUGIN", String.valueOf(Bukkit.getPluginManager().getPlugins().length), Joiner.on(", ").join(pluginList));
} }
}; };

View File

@ -119,7 +119,7 @@ public class FileUtils {
* *
* @param file 文件夹 * @param file 文件夹
*/ */
public void deleteAllFile(File file) { public static void deleteAllFile(File file) {
if (!file.exists()) { if (!file.exists()) {
return; return;
} }
@ -139,7 +139,7 @@ public class FileUtils {
* @param file1 文件1 * @param file1 文件1
* @param file2 文件2 * @param file2 文件2
*/ */
public void copyAllFile(String file1, String file2) { public static void copyAllFile(String file1, String file2) {
File _file1 = new File(file1); File _file1 = new File(file1);
File _file2 = new File(file2); File _file2 = new File(file2);
if (!_file2.exists()) { if (!_file2.exists()) {
@ -168,7 +168,7 @@ public class FileUtils {
* @param file1 文件1 * @param file1 文件1
* @param file2 文件2 * @param file2 文件2
*/ */
public void fileChannelCopy(File file1, File file2) { public static void fileChannelCopy(File file1, File file2) {
FileInputStream fileIn = null; FileInputStream fileIn = null;
FileOutputStream fileOut = null; FileOutputStream fileOut = null;
FileChannel channelIn = null; FileChannel channelIn = null;

View File

@ -911,7 +911,7 @@ public class NMSUtil19 {
} }
public static Class<?> getBukkitClass(String className) { public static Class<?> getBukkitClass(String className) {
Class<?> result = null; Class<?> result;
try { try {
result = fixBukkitClass(className); result = fixBukkitClass(className);
} catch (Exception ex) { } catch (Exception ex) {
@ -930,6 +930,7 @@ public class NMSUtil19 {
try { try {
return NMSUtils.class.getClassLoader().loadClass(className); return NMSUtils.class.getClassLoader().loadClass(className);
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
return null;
} }
} }

View File

@ -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;
}
}

View File

@ -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
}

View File

@ -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;
}
}

View File

@ -1,8 +1,3 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package me.skymc.taboolib.plugin; package me.skymc.taboolib.plugin;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -26,16 +21,33 @@ import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
/**
* @author PluginMan
*/
public class PluginUtils { 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) { public static void enable(Plugin plugin) {
if (plugin != null && !plugin.isEnabled()) { if (plugin != null && !plugin.isEnabled()) {
Bukkit.getPluginManager().enablePlugin(plugin); Bukkit.getPluginManager().enablePlugin(plugin);
} }
} }
public static void disable(Plugin plugin) { public static void disable(Plugin plugin) {
@ -45,11 +57,11 @@ public class PluginUtils {
} }
public static void enableAll() { 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() { 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) { public static String getFormattedName(Plugin plugin) {
@ -58,7 +70,7 @@ public class PluginUtils {
public static String getFormattedName(Plugin plugin, boolean includeVersions) { public static String getFormattedName(Plugin plugin, boolean includeVersions) {
ChatColor color = plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED; ChatColor color = plugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED;
String pluginName = color + plugin.getName(); String pluginName = color + plugin.getName() + ChatColor.RESET;
if (includeVersions) { if (includeVersions) {
pluginName = pluginName + " (" + plugin.getDescription().getVersion() + ")"; pluginName = pluginName + " (" + plugin.getDescription().getVersion() + ")";
} }
@ -89,9 +101,8 @@ public class PluginUtils {
Map commands = plugin.getDescription().getCommands(); Map commands = plugin.getDescription().getCommands();
if (commands != null) { if (commands != null) {
for (Object o : commands.entrySet()) { for (Object o : commands.entrySet()) {
Entry thisEntry = (Entry) o; if (o != null) {
if (thisEntry != null) { parsedCommands.add((String) ((Entry) o).getKey());
parsedCommands.add((String) thisEntry.getKey());
} }
} }
} }
@ -158,37 +169,28 @@ public class PluginUtils {
return plugin.equals(Main.getInst()); return plugin.equals(Main.getInst());
} }
private static String load(Plugin plugin) { private static PluginLoadState load(Plugin plugin) {
return load(plugin.getName()); return load(plugin.getName());
} }
/** public static PluginLoadState load(String name) {
* 返回内容
*
* plugin-directory 插件目录不存在
* cannot-find 插件不存在
* invalid-description 无效的描述
* invalid-plugin 无效的插件
* loaded 载入成功
*/
public static String load(String name) {
Plugin target; Plugin target;
File pluginDir = new File("plugins"); File pluginDir = new File("plugins");
if (!pluginDir.isDirectory()) { if (!pluginDir.isDirectory()) {
return "plugin-directory"; return new PluginLoadState(PluginLoadStateType.DIRECTORY_NOT_FOUND, "null");
} else { } else {
File pluginFile = new File(pluginDir, name + ".jar"); File pluginFile = new File(pluginDir, name + ".jar");
if (!pluginFile.isFile()) { if (!pluginFile.exists()) {
for (File f : Objects.requireNonNull(pluginDir.listFiles())) { for (File plugin : Objects.requireNonNull(pluginDir.listFiles())) {
if (f.getName().endsWith(".jar")) { if (plugin.getName().endsWith(".jar")) {
try { try {
PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(f); PluginDescriptionFile desc = Main.getInst().getPluginLoader().getPluginDescription(plugin);
if (desc.getName().equalsIgnoreCase(name)) { if (desc.getName().equalsIgnoreCase(name)) {
pluginFile = f; pluginFile = plugin;
break; break;
} }
} catch (InvalidDescriptionException var11) { } catch (InvalidDescriptionException ignored) {
return "cannot-find"; return new PluginLoadState(PluginLoadStateType.FILE_NOT_FOUND, "null");
} }
} }
} }
@ -196,15 +198,15 @@ public class PluginUtils {
try { try {
target = Bukkit.getPluginManager().loadPlugin(pluginFile); target = Bukkit.getPluginManager().loadPlugin(pluginFile);
} catch (InvalidDescriptionException var9) { } catch (InvalidDescriptionException e) {
return "invalid-description"; return new PluginLoadState(PluginLoadStateType.INVALID_DESCRIPTION, e.toString());
} catch (InvalidPluginException var10) { } catch (InvalidPluginException e) {
return "invalid-plugin"; return new PluginLoadState(PluginLoadStateType.INVALID_PLUGIN, e.toString());
} }
target.onLoad(); target.onLoad();
Bukkit.getPluginManager().enablePlugin(target); Bukkit.getPluginManager().enablePlugin(target);
return "loaded"; return new PluginLoadState(PluginLoadStateType.LOADED, "null");
} }
} }
@ -213,20 +215,13 @@ public class PluginUtils {
unload(plugin); unload(plugin);
load(plugin); load(plugin);
} }
} }
public static void reloadAll() { public static void reloadAll() {
Arrays.stream(Bukkit.getPluginManager().getPlugins(), 0, Bukkit.getPluginManager().getPlugins().length).filter(PluginUtils::isIgnored).forEach(PluginUtils::reload); Arrays.stream(Bukkit.getPluginManager().getPlugins(), 0, Bukkit.getPluginManager().getPlugins().length).filter(PluginUtils::isIgnored).forEach(PluginUtils::reload);
} }
/** public static PluginUnloadState unload(Plugin plugin) {
* 返回内容
*
* failed 卸载失败
* unloaded 卸载成功
*/
public static String unload(Plugin plugin) {
String name = plugin.getName(); String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null; SimpleCommandMap commandMap = null;
@ -236,7 +231,6 @@ public class PluginUtils {
Map<Event, SortedSet<RegisteredListener>> listeners = null; Map<Event, SortedSet<RegisteredListener>> listeners = null;
if (pluginManager != null) { if (pluginManager != null) {
pluginManager.disablePlugin(plugin); pluginManager.disablePlugin(plugin);
try { try {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins"); Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
pluginsField.setAccessible(true); pluginsField.setAccessible(true);
@ -259,8 +253,8 @@ public class PluginUtils {
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands"); Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true); knownCommandsField.setAccessible(true);
commands = (Map) knownCommandsField.get(commandMap); commands = (Map) knownCommandsField.get(commandMap);
} catch (NoSuchFieldException | IllegalAccessException var15) { } catch (NoSuchFieldException | IllegalAccessException e) {
return "failed"; return new PluginUnloadState(true, e.toString());
} }
} }
@ -276,10 +270,8 @@ public class PluginUtils {
Iterator it; Iterator it;
if (listeners != null) { if (listeners != null) {
it = listeners.values().iterator(); it = listeners.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
SortedSet<RegisteredListener> set = (SortedSet) it.next(); SortedSet<RegisteredListener> set = (SortedSet) it.next();
while (it.hasNext()) { while (it.hasNext()) {
RegisteredListener value = (RegisteredListener) it.next(); RegisteredListener value = (RegisteredListener) it.next();
if (value.getPlugin() == plugin) { if (value.getPlugin() == plugin) {
@ -291,7 +283,6 @@ public class PluginUtils {
if (commandMap != null) { if (commandMap != null) {
it = commands.entrySet().iterator(); it = commands.entrySet().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Entry<String, Command> entry = (Entry) it.next(); Entry<String, Command> entry = (Entry) it.next();
if (entry.getValue() instanceof PluginCommand) { if (entry.getValue() instanceof PluginCommand) {
@ -312,7 +303,7 @@ public class PluginUtils {
Logger.getLogger(PluginUtils.class.getName()).log(Level.SEVERE, null, var13); 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) { private static String consolidateStrings(String[] args, int start) {

View File

@ -7,6 +7,7 @@ import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.Main; import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.fileutils.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
/** /**
@ -26,9 +27,6 @@ public class UpdateTask {
return newVersion; return newVersion;
} }
/**
* 旧地址https://internal.github.com/repos/Bkm016/TabooLib/releases/latest
*/
public UpdateTask() { public UpdateTask() {
new BukkitRunnable() { new BukkitRunnable() {
@ -53,6 +51,15 @@ public class UpdateTask {
} else { } else {
haveUpdate = true; haveUpdate = true;
TLocale.Logger.info("UPDATETASK.VERSION-OUTDATED", String.valueOf(TabooLib.getPluginVersion()), String.valueOf(newVersion)); 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());
} }
} }
} }

View File

@ -41,6 +41,9 @@ TABLIST-SORT: false
# 是否启用更新检测 # 是否启用更新检测
UPDATE-CHECK: true UPDATE-CHECK: true
# 是否启用自动更新
UPDATE-DOWNLOAD: false
# 是否在关闭服务器时清理玩家数据 # 是否在关闭服务器时清理玩家数据
# 该配置将在启用数据库储存时失效 # 该配置将在启用数据库储存时失效
DELETE-DATA: false DELETE-DATA: false

View File

@ -157,7 +157,7 @@ COMMANDS:
ONLY-PLAYER: '&8[&3&lTabooLib&8] &4控制台无法这么做' ONLY-PLAYER: '&8[&3&lTabooLib&8] &4控制台无法这么做'
ONLY-STORAGE-SQL: '&8[&3&lTabooLib&8] &4只有启用数据库储存时才能这么做' ONLY-STORAGE-SQL: '&8[&3&lTabooLib&8] &4只有启用数据库储存时才能这么做'
INTERNAL: 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-PLAYER: 玩家
TYPE-CONSOLE: 控制台 TYPE-CONSOLE: 控制台
ERROR-USAGE: ERROR-USAGE:
@ -230,6 +230,13 @@ COMMANDS:
IMPORTING-START: '&8[&3&lTabooLib&8] &7开始导入 &f{0} &7项玩家数据' IMPORTING-START: '&8[&3&lTabooLib&8] &7开始导入 &f{0} &7项玩家数据'
IMPORTING-PROGRESS: '&8[&3&lTabooLib&8] &7导入玩家数据: &f{0} &7进度: &f{1}/{2}' IMPORTING-PROGRESS: '&8[&3&lTabooLib&8] &7导入玩家数据: &f{0} &7进度: &f{1}/{2}'
SUCCESS: '&8[&3&lTabooLib&8] &7导入完成' 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: JAVASHELL:
DESCRIPTION: DESCRIPTION:
LOAD: '载入脚本' LOAD: '载入脚本'
@ -470,6 +477,7 @@ COMMANDS:
ARGUMENTS: ARGUMENTS:
0: '名称' 0: '名称'
INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在' INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在'
INVALID-DESCRIPTION: '&8[&3&lTabooLib&8] &4获取插件 &c{0} &4信息失败: &c{1}'
INFO-PLUGIN: INFO-PLUGIN:
- '&8[&3&lTabooLib&8] &7插件名称: &f{0}' - '&8[&3&lTabooLib&8] &7插件名称: &f{0}'
- '&8[&3&lTabooLib&8] &7描述: &f{1}' - '&8[&3&lTabooLib&8] &7描述: &f{1}'
@ -484,9 +492,10 @@ COMMANDS:
DESCRIPTION: '载入插件' DESCRIPTION: '载入插件'
ARGUMENTS: ARGUMENTS:
0: '名称' 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-SUCCESS: '&8[&3&lTabooLib&8] &7插件已载入'
LOAD-FAIL: '&8[&3&lTabooLib&8] &7插件载入失败'
UNLOAD: UNLOAD:
DESCRIPTION: '卸载插件' DESCRIPTION: '卸载插件'
ARGUMENTS: ARGUMENTS:
@ -494,7 +503,7 @@ COMMANDS:
INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在' INVALID-PLUGIN: '&8[&3&lTabooLib&8] &4插件 &c{0} &4不存在'
INVALID-PLUGIN-IGNORED: '&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-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: RELOAD:
DESCRIPTION: '重载插件' DESCRIPTION: '重载插件'
ARGUMENTS: ARGUMENTS: