TabooLib 4.2 更新内容
新增 @TCommand 注解,用于在开服后自动注册 BaseMainCommand 命令 新增 @TListener 注解,用于在开服后自动注册监听器 新增 @Instantiable 注解,用于在开服后自动执行构造方法(东西多,不想在主类一条一条写) 新增 ItemBuilder 快速创建物品 新增 MenuBuilder 快速创建界面 新增 TCommandHandler 类用于动态命令注册 新增 SimpleCommandBuilder 用于快速注册命令(妈的抄了个四不像) 主类调整,插件初始化业务转移至 TabooLibLoader 类中 主类调整,删除原有的 TabooLib 数据库储存方式,改为新版数据库代码 MySQLConnection 类已过时,不在维护。新的数据库方法由 SQLTable 类实现 TabooLib 允许在 BungeeCord 载入了 彻底删除 JavaShell 相关代码(这个丢人玩意儿终于被删了) 删除 JavaScriptUtils,改为 ScriptHandler(这个丢人玩意儿终于被改了) 删除 LogUtils,改为 TLogs(这个丢人玩意儿终于被改了) 新增 allen-zhang 提供的 SimpleScoreboard 工具 注解扫描只对依赖(软兼容)于 TabooLib 的插件有效 SQLTable 新增三个方法(executeInsert, executeSelect, executeUpdate)节省命令时间 TLM 删除预定。 ThreadUtils 删除预定。 注意!该版本下的数据库储存方式将无法使用(PlayerData,PluginData)
This commit is contained in:
parent
2ffb1ce886
commit
fb13b607a1
@ -23,36 +23,94 @@ public class TabooLib {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主类对象,因 Main 名称容易造成混淆所以转移至此
|
||||
*
|
||||
* @return {@link Main}
|
||||
*/
|
||||
public static Main instance() {
|
||||
return (Main) Main.getInst();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件是否依赖于 TabooLib(依赖或软兼容)
|
||||
*
|
||||
* @param plugin 插件
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isDependTabooLib(Plugin plugin) {
|
||||
return plugin.getDescription().getDepend().contains("TabooLib") || plugin.getDescription().getSoftDepend().contains("TabooLib");
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为 Spigot 核心,因 TabooLib 可在 BungeeCord 上运行所以添加此方法
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isSpigot() {
|
||||
return spigot;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 TabooLib 插件版本
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public static double getPluginVersion() {
|
||||
return NumberUtils.getDouble(Main.getInst().getDescription().getVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务端版本
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务端版本数字
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static int getVersionNumber() {
|
||||
return getVerint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置服务器序列号
|
||||
*/
|
||||
public static void resetServerUID() {
|
||||
DataUtils.getPluginData("TabooLibrary", null).set("serverUID", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为 debug 模式
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isDebug() {
|
||||
return Main.getInst().getConfig().getBoolean("DEBUG");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送 debug 信息
|
||||
*
|
||||
* @param plugin 插件名
|
||||
* @param args 内容
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
public static double getPluginVersion() {
|
||||
return NumberUtils.getDouble(Main.getInst().getDescription().getVersion());
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
}
|
||||
|
||||
public static int getVersionNumber() {
|
||||
return getVerint();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器序列号
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getServerUID() {
|
||||
if (!DataUtils.getPluginData("TabooLibrary", null).contains("serverUID")) {
|
||||
DataUtils.getPluginData("TabooLibrary", null).set("serverUID", UUID.randomUUID().toString());
|
||||
@ -60,10 +118,6 @@ public class TabooLib {
|
||||
return DataUtils.getPluginData("TabooLibrary", null).getString("serverUID");
|
||||
}
|
||||
|
||||
public static void resetServerUID() {
|
||||
DataUtils.getPluginData("TabooLibrary", null).set("serverUID", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int getVerint() {
|
||||
String version = getVersion();
|
||||
|
@ -34,7 +34,6 @@ class TabooLibLoader {
|
||||
|
||||
static void register() {
|
||||
registerListener();
|
||||
registerCommands();
|
||||
registerMetrics();
|
||||
}
|
||||
|
||||
@ -96,14 +95,6 @@ class TabooLibLoader {
|
||||
TabooLibDatabase.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入插件命令
|
||||
*/
|
||||
static void registerCommands() {
|
||||
Bukkit.getPluginCommand("language2").setExecutor(new Language2Command());
|
||||
Bukkit.getPluginCommand("taboolibrarymodule").setExecutor(new TLMCommands());
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入插件监听
|
||||
*/
|
||||
|
@ -0,0 +1,93 @@
|
||||
package me.skymc.taboolib.commands.builder;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import me.skymc.taboolib.commands.builder.type.CompleterCommand;
|
||||
import me.skymc.taboolib.commands.builder.type.CompleterTab;
|
||||
import me.skymc.taboolib.commands.internal.TCommandHandler;
|
||||
import me.skymc.taboolib.string.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-08-27 8:42
|
||||
* @BuilderLevel 1.0
|
||||
*/
|
||||
public class SimpleCommandBuilder {
|
||||
|
||||
private final String command;
|
||||
private final Plugin plugin;
|
||||
private String description;
|
||||
private String usage;
|
||||
private List<String> aliases;
|
||||
private String permission;
|
||||
private String permissionMessage;
|
||||
private CompleterCommand completerCommand;
|
||||
private CompleterTab completerTab;
|
||||
|
||||
SimpleCommandBuilder(String command, Plugin plugin) {
|
||||
this.command = command;
|
||||
this.plugin = plugin;
|
||||
this.description = "";
|
||||
this.usage = "/" + command;
|
||||
this.aliases = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static SimpleCommandBuilder create(String command, Plugin plugin) {
|
||||
return new SimpleCommandBuilder(command, plugin);
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder usage(String usage) {
|
||||
this.usage = usage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder aliases(String... aliases) {
|
||||
this.aliases = ArrayUtils.asList(aliases);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder permission(String permission) {
|
||||
this.permission = permission;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder permissionMessage(String permissionMessage) {
|
||||
this.permissionMessage = permissionMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder execute(CompleterCommand completerCommand) {
|
||||
this.completerCommand = completerCommand;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder tab(CompleterTab completerTab) {
|
||||
this.completerTab = completerTab;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleCommandBuilder build() {
|
||||
Preconditions.checkNotNull(completerCommand, "缺少 \"CompleterCommand\" 部分");
|
||||
TCommandHandler.registerPluginCommand(
|
||||
plugin,
|
||||
command,
|
||||
description,
|
||||
usage,
|
||||
aliases,
|
||||
permission,
|
||||
permissionMessage,
|
||||
(sender, command, s, args) -> completerCommand.execute(sender, args),
|
||||
(sender, command, s, args) -> completerTab.execute(sender, args));
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package me.skymc.taboolib.commands.builder.type;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* 为了防止与 CommandExecutor 混淆所以名称改为 CompleterCommand
|
||||
*
|
||||
* @author sky
|
||||
*/
|
||||
public interface CompleterCommand {
|
||||
|
||||
boolean execute(CommandSender sender, String[] args);
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package me.skymc.taboolib.commands.builder.type;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 为了防止与 TabExecutor 混淆所以名称改为 CompleterTab
|
||||
*
|
||||
* @author sky
|
||||
*/
|
||||
public interface CompleterTab {
|
||||
|
||||
List<String> execute(CommandSender sender, String[] args);
|
||||
|
||||
}
|
@ -54,20 +54,20 @@ public class TCommandHandler implements Listener {
|
||||
return registerPluginCommand(plugin, command, "", "/" + command, new ArrayList<>(), null, null, commandExecutor, null);
|
||||
}
|
||||
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, CommandExecutor commandExecutor, TabExecutor tabExecutor) {
|
||||
return registerPluginCommand(plugin, command, "", "/" + command, new ArrayList<>(), null, null, commandExecutor, tabExecutor);
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
|
||||
return registerPluginCommand(plugin, command, "", "/" + command, new ArrayList<>(), null, null, commandExecutor, tabCompleter);
|
||||
}
|
||||
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, CommandExecutor commandExecutor, TabExecutor tabExecutor) {
|
||||
return registerPluginCommand(plugin, command, description, "/" + command, new ArrayList<>(), null, null, commandExecutor, tabExecutor);
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
|
||||
return registerPluginCommand(plugin, command, description, "/" + command, new ArrayList<>(), null, null, commandExecutor, tabCompleter);
|
||||
}
|
||||
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, CommandExecutor commandExecutor, TabExecutor tabExecutor) {
|
||||
return registerPluginCommand(plugin, command, description, usage, new ArrayList<>(), null, null, commandExecutor, tabExecutor);
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
|
||||
return registerPluginCommand(plugin, command, description, usage, new ArrayList<>(), null, null, commandExecutor, tabCompleter);
|
||||
}
|
||||
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, List<String> aliases, CommandExecutor commandExecutor, TabExecutor tabExecutor) {
|
||||
return registerPluginCommand(plugin, command, description, usage, aliases, null, null, commandExecutor, tabExecutor);
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, List<String> aliases, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
|
||||
return registerPluginCommand(plugin, command, description, usage, aliases, null, null, commandExecutor, tabCompleter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,16 +81,16 @@ public class TCommandHandler implements Listener {
|
||||
* @param permission 权限
|
||||
* @param permissionMessage 权限提示
|
||||
* @param commandExecutor 命令执行器
|
||||
* @param tabExecutor 补全执行器
|
||||
* @param tabCompleter 补全执行器
|
||||
* @return 注册结果(boolean)
|
||||
*/
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, List<String> aliases, String permission, String permissionMessage, CommandExecutor commandExecutor, TabExecutor tabExecutor) {
|
||||
public static boolean registerPluginCommand(Plugin plugin, String command, String description, String usage, List<String> aliases, String permission, String permissionMessage, CommandExecutor commandExecutor, TabCompleter tabCompleter) {
|
||||
try {
|
||||
Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
|
||||
constructor.setAccessible(true);
|
||||
PluginCommand pluginCommand = constructor.newInstance(command, plugin);
|
||||
pluginCommand.setExecutor(commandExecutor);
|
||||
pluginCommand.setTabCompleter(tabExecutor);
|
||||
pluginCommand.setTabCompleter(tabCompleter);
|
||||
ReflectionUtils.setValue(pluginCommand, pluginCommand.getClass().getSuperclass(), true, "description", description);
|
||||
ReflectionUtils.setValue(pluginCommand, pluginCommand.getClass().getSuperclass(), true, "usageMessage", usage);
|
||||
ReflectionUtils.setValue(pluginCommand, pluginCommand.getClass().getSuperclass(), true, "aliases", aliases);
|
||||
@ -134,12 +134,10 @@ public class TCommandHandler implements Listener {
|
||||
*/
|
||||
public static void registerCommands() {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.equals(TabooLib.instance()) || plugin.getDescription().getDepend().contains("TabooLib")) {
|
||||
try {
|
||||
registerCommand(plugin);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
registerCommand(plugin);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -150,6 +148,9 @@ public class TCommandHandler implements Listener {
|
||||
* @param plugin 插件
|
||||
*/
|
||||
public static void registerCommand(Plugin plugin) {
|
||||
if (!(plugin.equals(TabooLib.instance()) || TabooLib.isDependTabooLib(plugin))) {
|
||||
return;
|
||||
}
|
||||
for (Class pluginClass : FileUtils.getClasses(plugin)) {
|
||||
if (BaseMainCommand.class.isAssignableFrom(pluginClass) && pluginClass.isAnnotationPresent(TCommand.class)) {
|
||||
TCommand tCommand = (TCommand) pluginClass.getAnnotation(TCommand.class);
|
||||
|
@ -2,11 +2,12 @@ package me.skymc.taboolib.commands.language;
|
||||
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
|
||||
import me.skymc.taboolib.object.Instantiable;
|
||||
import me.skymc.taboolib.string.language2.Language2Value;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -14,18 +15,23 @@ import org.bukkit.entity.Player;
|
||||
* @author sky
|
||||
* @since 2018年2月13日 下午5:11:01
|
||||
*/
|
||||
public class Language2Command implements CommandExecutor {
|
||||
@Instantiable("Language2Command")
|
||||
public class Language2Command {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.HELP", label);
|
||||
} else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
reload(sender);
|
||||
} else if ("send".equalsIgnoreCase(args[0])) {
|
||||
send(sender, args);
|
||||
}
|
||||
return true;
|
||||
public Language2Command() {
|
||||
SimpleCommandBuilder.create("language2", TabooLib.instance())
|
||||
.aliases("lang2")
|
||||
.permission("taboolib.admin")
|
||||
.execute((sender, args) -> {
|
||||
if (args.length == 0) {
|
||||
TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.HELP", "langauge2");
|
||||
} else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
reload(sender);
|
||||
} else if ("send".equalsIgnoreCase(args[0])) {
|
||||
send(sender, args);
|
||||
}
|
||||
return true;
|
||||
}).build();
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, String[] args) {
|
||||
|
@ -28,12 +28,10 @@ public class TListenerHandler implements Listener {
|
||||
*/
|
||||
public static void setupListeners() {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
if (plugin.equals(TabooLib.instance()) || plugin.getDescription().getDepend().contains("TabooLib")) {
|
||||
try {
|
||||
setupListener(plugin);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
setupListener(plugin);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,6 +43,9 @@ public class TListenerHandler implements Listener {
|
||||
* @param plugin 插件
|
||||
*/
|
||||
public static void setupListener(Plugin plugin) {
|
||||
if (!(plugin.equals(TabooLib.instance()) || TabooLib.isDependTabooLib(plugin))) {
|
||||
return;
|
||||
}
|
||||
List<Class> classes = FileUtils.getClasses(plugin);
|
||||
for (Class<?> pluginClass : classes) {
|
||||
if (Listener.class.isAssignableFrom(pluginClass) && pluginClass.isAnnotationPresent(TListener.class)) {
|
||||
|
@ -5,6 +5,8 @@ import me.skymc.taboolib.mysql.builder.query.RunnableQuery;
|
||||
import me.skymc.taboolib.mysql.builder.query.RunnableUpdate;
|
||||
import me.skymc.taboolib.string.ArrayUtils;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
@ -52,6 +54,18 @@ public class SQLTable {
|
||||
return Strings.replaceWithOrder("truncate table `{0}`", tableName);
|
||||
}
|
||||
|
||||
public RunnableUpdate executeInsert(String values) {
|
||||
return executeUpdate("insert into " + tableName + " values(" + values + ")");
|
||||
}
|
||||
|
||||
public RunnableQuery executeSelect(String where) {
|
||||
return executeQuery("select * from " + tableName + " where " + where);
|
||||
}
|
||||
|
||||
public RunnableUpdate executeUpdate(String where, String update) {
|
||||
return executeUpdate("update " + tableName + " set " + update + " where " + where);
|
||||
}
|
||||
|
||||
public RunnableUpdate executeUpdate(String query) {
|
||||
return new RunnableUpdate(query);
|
||||
}
|
||||
|
83
src/main/java/me/skymc/taboolib/object/InstanceHandler.java
Normal file
83
src/main/java/me/skymc/taboolib/object/InstanceHandler.java
Normal file
@ -0,0 +1,83 @@
|
||||
package me.skymc.taboolib.object;
|
||||
|
||||
import com.ilummc.tlib.util.Ref;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.fileutils.FileUtils;
|
||||
import me.skymc.taboolib.listener.TListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-08-27 10:04
|
||||
*/
|
||||
@TListener
|
||||
public class InstanceHandler implements Listener {
|
||||
|
||||
private static ConcurrentHashMap<String, Object> instance = new ConcurrentHashMap<>();
|
||||
|
||||
public InstanceHandler() {
|
||||
loadInstantiable();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEnable(PluginEnableEvent e) {
|
||||
loadInstantiable(e.getPlugin());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisable(PluginDisableEvent e) {
|
||||
clear(e.getPlugin());
|
||||
}
|
||||
|
||||
public static void clear(Plugin plugin) {
|
||||
instance.entrySet().stream().filter(entry -> Ref.getCallerPlugin(entry.getValue().getClass()).equals(plugin)).forEach(entry -> instance.remove(entry.getKey()));
|
||||
}
|
||||
|
||||
public static void loadInstantiable() {
|
||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
try {
|
||||
loadInstantiable(plugin);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadInstantiable(Plugin plugin) {
|
||||
if (!(plugin.equals(TabooLib.instance()) || TabooLib.isDependTabooLib(plugin))) {
|
||||
return;
|
||||
}
|
||||
for (Class pluginClass : FileUtils.getClasses(plugin)) {
|
||||
if (pluginClass.isAnnotationPresent(Instantiable.class)) {
|
||||
Instantiable instantiable = (Instantiable) pluginClass.getAnnotation(Instantiable.class);
|
||||
try {
|
||||
instance.put(instantiable.value(), pluginClass.newInstance());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Getter and Setter
|
||||
//
|
||||
// *********************************
|
||||
|
||||
public static ConcurrentHashMap<String, Object> getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static Optional<Object> getInstance(String name) {
|
||||
return Optional.ofNullable(instance.get(name));
|
||||
}
|
||||
}
|
18
src/main/java/me/skymc/taboolib/object/Instantiable.java
Normal file
18
src/main/java/me/skymc/taboolib/object/Instantiable.java
Normal file
@ -0,0 +1,18 @@
|
||||
package me.skymc.taboolib.object;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-08-27 10:04
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Instantiable {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
@ -1,63 +1,68 @@
|
||||
package me.skymc.tlm.command;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
|
||||
import me.skymc.taboolib.object.Instantiable;
|
||||
import me.skymc.tlm.TLM;
|
||||
import me.skymc.tlm.command.sub.TLMInvCommand;
|
||||
import me.skymc.tlm.command.sub.TLMKitCommand;
|
||||
import me.skymc.tlm.command.sub.TLMListCommand;
|
||||
import me.skymc.tlm.command.sub.TLMReloadCommand;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月18日 上午12:02:08
|
||||
*/
|
||||
public class TLMCommands implements CommandExecutor {
|
||||
@Instantiable("TLMCommands")
|
||||
public class TLMCommands {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
|
||||
if (args.length == 0 || "help".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender);
|
||||
}
|
||||
}
|
||||
public TLMCommands() {
|
||||
SimpleCommandBuilder.create("taboolibrarymodule", TabooLib.instance())
|
||||
.aliases("tlm")
|
||||
.permission("tlm.use")
|
||||
.execute((sender, args) -> {
|
||||
if (args.length == 0 || "help".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 重载
|
||||
else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMReloadCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender);
|
||||
}
|
||||
}
|
||||
// 重载
|
||||
else if ("reload".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMReloadCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 列出
|
||||
else if ("list".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMListCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender);
|
||||
}
|
||||
}
|
||||
// 列出
|
||||
else if ("list".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMListCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// InventorySave 模块
|
||||
else if ("inv".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMInvCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-INV").send(sender);
|
||||
}
|
||||
}
|
||||
// InventorySave 模块
|
||||
else if ("inv".equalsIgnoreCase(args[0])) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMInvCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-INV").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// Kit 模块
|
||||
else if ("kit".equalsIgnoreCase(args[0])) {
|
||||
new TLMKitCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
|
||||
}
|
||||
return true;
|
||||
// Kit 模块
|
||||
else if ("kit".equalsIgnoreCase(args[0])) {
|
||||
new TLMKitCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
|
||||
}
|
||||
return true;
|
||||
}).build();
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,4 @@ version: ${project.version}
|
||||
|
||||
author: [lzzelAliz, 坏黑]
|
||||
depend: [Vault]
|
||||
softdepend: [PlaceholderAPI, Skript, MassiveLag]
|
||||
|
||||
# 两个命令删除预定
|
||||
commands:
|
||||
language2:
|
||||
aliases: [lang2]
|
||||
permission: taboolib.admin
|
||||
taboolibrarymodule:
|
||||
aliases: [tlm]
|
||||
softdepend: [PlaceholderAPI, Skript, MassiveLag]
|
Loading…
Reference in New Issue
Block a user