版本更新至 4.01

调整:TLocale$logger 现在可以发送多行文本了
调整:TLocale 发送不存在的信息,错误提示由红色改为灰色,用于区分发送错误的提示颜色。
调整:TLocaleLoader 中的 getCallerPlugin 方法转移到 Ref 中
修复:BaseMainCommand 接口中 getType 方法失效的问题
修复:Main 中的语言提示无法更改的问题
新增:TPlugin 命令现在可以补全插件名了
新增:config.yml 现在会自动重载了(部分配置还需重启)
This commit is contained in:
坏黑
2018-05-13 21:31:03 +08:00
parent eb616fd5bd
commit 3ea16b3e80
11 changed files with 122 additions and 64 deletions

View File

@@ -1,6 +1,8 @@
package me.skymc.taboolib;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.inject.TConfigWatcher;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.anvil.AnvilContainerAPI;
import me.skymc.taboolib.bstats.Metrics;
import me.skymc.taboolib.commands.TabooLibMainCommand;
@@ -180,7 +182,7 @@ public class Main extends JavaPlugin implements Listener {
String hash = connection.getValue(getTablePrefix() + "_serveruuid", "uuid", TabooLib.getServerUID(), "hash").toString();
// 如果这个值和我的值不同
if (!hash.equals(StringUtils.hashKeyForDisk(getDataFolder().getPath()))) {
MsgUtils.warn("检测到本服序列号与其他服务器相同, 已重新生成!");
TLocale.Logger.error("NOTIFY.ERROR-SERVER-KEY");
// 重新生成序列号
TabooLib.resetServerUID();
// 关服
@@ -189,7 +191,7 @@ public class Main extends JavaPlugin implements Listener {
}
} else {
// 提示
MsgUtils.warn("数据库连接失败, 请检查配置是否正确!");
TLocale.Logger.error("NOTIFY.ERROR-CONNECTION-FALL");
// 关服
Bukkit.shutdown();
}
@@ -235,14 +237,16 @@ public class Main extends JavaPlugin implements Listener {
}
// 载入完成
MsgUtils.send("§7插件载入完成!");
MsgUtils.send("§7插件版本: §f" + getDescription().getVersion());
MsgUtils.send("§7插件作者: §f" + getDescription().getAuthors());
MsgUtils.send("§7游戏版本: §f" + TabooLib.getVerint());
TLocale.Logger.info("NOTIFY.SUCCESS-LOADED", getDescription().getAuthors().toString(), getDescription().getVersion(), String.valueOf(TabooLib.getVersion()));
// 文件保存
Bukkit.getScheduler().runTaskTimerAsynchronously(this, DataUtils::saveAllCaches, 20, 20 * 120);
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> PlayerDataManager.saveAllCaches(true, false), 20, 20 * 60);
// 文件监控
TLib.getTLib().getConfigWatcher().addListener(new File(getDataFolder(), "config.yml"), null, obj -> {
reloadConfig();
TLocale.Logger.info("CONFIG.RELOAD-SUCCESS", inst.getName(), "config.yml");
});
// 插件联动
new BukkitRunnable() {
@@ -277,8 +281,7 @@ public class Main extends JavaPlugin implements Listener {
// 如果插件尚未启动完成
if (!started) {
MsgUtils.send("&c插件尚未启动完成, 已跳过卸载代码");
MsgUtils.send("&c插件作者: &4坏黑");
TLocale.Logger.error("NOTIFY.FALL-DISABLE");
return;
}
@@ -312,8 +315,7 @@ public class Main extends JavaPlugin implements Listener {
}
// 提示信息
MsgUtils.send("&c插件已卸载, 感谢您使用&4禁忌书库");
MsgUtils.send("&c插件作者: &4坏黑");
TLocale.Logger.error("NOTIFY.SUCCESS-DISABLE");
// 清理头衔
TagUtils.delete();

View File

@@ -10,6 +10,10 @@ import java.util.UUID;
public class TabooLib {
public static boolean isDebug() {
return Main.getInst().getConfig().getBoolean("DEBUG");
}
public static void debug(Plugin plugin, String... args) {
if (Main.getInst().getConfig().getBoolean("DEBUG")) {
Arrays.stream(args).forEach(var -> Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_RED + "[TabooLib - DEBUG][" + plugin.getName() + "] " + ChatColor.RED + var));

View File

@@ -2,6 +2,8 @@ package me.skymc.taboolib.commands.internal;
import com.google.common.base.Preconditions;
import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.resources.TLocaleLoader;
import com.ilummc.tlib.util.Ref;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.internal.type.CommandRegister;
@@ -10,8 +12,11 @@ import me.skymc.taboolib.string.ArrayUtils;
import me.skymc.taboolib.string.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -35,6 +40,7 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
baseMainCommand.getRegisterCommand().setExecutor(baseMainCommand);
baseMainCommand.getRegisterCommand().setTabCompleter(baseMainCommand);
baseMainCommand.getLinkClasses().add(baseMainCommand.getClass());
baseMainCommand.disguisedPlugin();
loadCommandRegister(baseMainCommand);
return baseMainCommand;
}
@@ -149,7 +155,7 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
}
private boolean isConfirmType(CommandSender sender, CommandType commandType) {
return commandType == CommandType.ALL || sender instanceof ConsoleCommandSender && commandType == CommandType.CONSOLE;
return commandType == CommandType.ALL || (sender instanceof Player && commandType == CommandType.PLAYER);
}
private void helpCommand(CommandSender sender, String label) {
@@ -159,4 +165,17 @@ public abstract class BaseMainCommand implements IMainCommand, CommandExecutor,
subCommands.stream().map(subCommand -> subCommand == null ? getEmptyLine() : subCommand.getCommandString(label)).forEach(sender::sendMessage);
sender.sendMessage(getEmptyLine());
}
private void disguisedPlugin() {
linkClasses.forEach(clazz -> disguisedPlugin(clazz, (JavaPlugin) registerCommand.getPlugin()));
}
private void disguisedPlugin(Class<?> targetClass, JavaPlugin plugin) {
try {
Field pluginField = targetClass.getClassLoader().getClass().getDeclaredField("plugin");
pluginField.setAccessible(true);
pluginField.set(targetClass.newInstance(), plugin);
} catch (Exception ignored) {
}
}
}

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Joiner;
import com.ilummc.tlib.resources.TLocale;
import me.skymc.taboolib.commands.internal.BaseMainCommand;
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.plugin.PluginUtils;
import me.skymc.taboolib.string.ArrayUtils;
@@ -12,6 +13,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -30,6 +32,21 @@ public class TabooLibPluginMainCommand extends BaseMainCommand {
reloadCommand();
}
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] args) {
if (args.length == 1) {
return getSubCommands().stream().filter(internalCommandExecutor -> internalCommandExecutor != null && (args[0].isEmpty() || internalCommandExecutor.getLabel().toLowerCase().startsWith(args[0].toLowerCase()))).map(ISubCommand::getLabel).collect(Collectors.toList());
} else if (args.length > 1 && isPluginCommand(args[0])) {
return Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(x -> !PluginUtils.isIgnored(x)).collect(Collectors.toList()).stream().filter(plugin -> args[1].isEmpty() || plugin.getName().toLowerCase().startsWith(args[1].toLowerCase())).map(Plugin::getName).collect(Collectors.toList());
} else {
return null;
}
}
private boolean isPluginCommand(String label) {
return "info".equalsIgnoreCase(label) || "load".equalsIgnoreCase(label) || "unload".equalsIgnoreCase(label) || "reload".equalsIgnoreCase(label);
}
@Override
public String getCommandTitle() {
return TLocale.asString("COMMANDS.TPLUGIN.COMMAND-TITLE");