更新
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
package me.skymc.tlm;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.fileutils.ConfigUtils;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
@@ -12,85 +9,92 @@ import me.skymc.tlm.module.sub.ModuleCommandChanger;
|
||||
import me.skymc.tlm.module.sub.ModuleInventorySave;
|
||||
import me.skymc.tlm.module.sub.ModuleKits;
|
||||
import me.skymc.tlm.module.sub.ModuleTimeCycle;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月17日 下午10:28:05
|
||||
*/
|
||||
public class TLM {
|
||||
|
||||
private static TLM inst = null;
|
||||
|
||||
@Getter
|
||||
private FileConfiguration config;
|
||||
|
||||
@Getter
|
||||
private Language2 language;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
private TLM() {
|
||||
// 重载配置文件
|
||||
reloadConfig();
|
||||
|
||||
// 载入模块
|
||||
if (isEnableModule("TimeCycle")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleTimeCycle());
|
||||
}
|
||||
if (isEnableModule("Kits")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleKits());
|
||||
}
|
||||
if (isEnableModule("CommandChanger")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleCommandChanger());
|
||||
}
|
||||
if (isEnableModule("InventorySave")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleInventorySave());
|
||||
}
|
||||
|
||||
// 载入模块
|
||||
TabooLibraryModule.getInst().loadModules();
|
||||
|
||||
// 提示
|
||||
MsgUtils.send("载入 &f" + TabooLibraryModule.getInst().getSize() + " &7个 &fTLM &7模块");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 TLM 对象
|
||||
*
|
||||
* @return TLM
|
||||
*/
|
||||
public static TLM getInst() {
|
||||
if (inst == null) {
|
||||
synchronized (TLM.class) {
|
||||
if (inst == null) {
|
||||
inst = new TLM();
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入配置文件
|
||||
*/
|
||||
public void reloadConfig() {
|
||||
config = ConfigUtils.saveDefaultConfig(Main.getInst(), "module.yml");
|
||||
// 载入语言文件
|
||||
try {
|
||||
language = new Language2(config.getString("Language"), Main.getInst());
|
||||
} catch (Exception e) {
|
||||
MsgUtils.warn("语言文件不存在: &4" + config.getString("Language"));
|
||||
|
||||
private static TLM inst = null;
|
||||
|
||||
private FileConfiguration config;
|
||||
|
||||
private Language2 language;
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Language2 getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
private TLM() {
|
||||
// 重载配置文件
|
||||
reloadConfig();
|
||||
|
||||
// 载入模块
|
||||
if (isEnableModule("TimeCycle")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleTimeCycle());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块是否启用
|
||||
*
|
||||
* @param name 名称
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEnableModule(String name) {
|
||||
return config.getStringList("EnableModule").contains(name);
|
||||
}
|
||||
if (isEnableModule("Kits")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleKits());
|
||||
}
|
||||
if (isEnableModule("CommandChanger")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleCommandChanger());
|
||||
}
|
||||
if (isEnableModule("InventorySave")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleInventorySave());
|
||||
}
|
||||
|
||||
// 载入模块
|
||||
TabooLibraryModule.getInst().loadModules();
|
||||
|
||||
// 提示
|
||||
MsgUtils.send("载入 &f" + TabooLibraryModule.getInst().getSize() + " &7个 &fTLM &7模块");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 TLM 对象
|
||||
*
|
||||
* @return TLM
|
||||
*/
|
||||
public static TLM getInst() {
|
||||
if (inst == null) {
|
||||
synchronized (TLM.class) {
|
||||
if (inst == null) {
|
||||
inst = new TLM();
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* 载入配置文件
|
||||
*/
|
||||
public void reloadConfig() {
|
||||
config = ConfigUtils.saveDefaultConfig(Main.getInst(), "module.yml");
|
||||
// 载入语言文件
|
||||
try {
|
||||
language = new Language2(config.getString("Language"), Main.getInst());
|
||||
} catch (Exception e) {
|
||||
MsgUtils.warn("语言文件不存在: &4" + config.getString("Language"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模块是否启用
|
||||
*
|
||||
* @param name 名称
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEnableModule(String name) {
|
||||
return config.getStringList("EnableModule").contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package me.skymc.tlm.annotation;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(TYPE)
|
||||
public @interface DisableConfig {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package me.skymc.tlm.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
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
|
||||
@@ -16,51 +15,49 @@ import me.skymc.tlm.command.sub.TLMReloadCommand;
|
||||
*/
|
||||
public class TLMCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 重载
|
||||
else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMReloadCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 列出
|
||||
else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMListCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// InventorySave 模块
|
||||
else if (args[0].equalsIgnoreCase("inv")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMInvCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-INV").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// Kit 模块
|
||||
else if (args[0].equalsIgnoreCase("kit")) {
|
||||
new TLMKitCommand(sender, args);
|
||||
}
|
||||
|
||||
else {
|
||||
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 重载
|
||||
else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMReloadCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// 列出
|
||||
else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMListCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// InventorySave 模块
|
||||
else if (args[0].equalsIgnoreCase("inv")) {
|
||||
if (sender.hasPermission("taboolib.admin")) {
|
||||
new TLMInvCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("NOPERMISSION-INV").send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
// Kit 模块
|
||||
else if (args[0].equalsIgnoreCase("kit")) {
|
||||
new TLMKitCommand(sender, args);
|
||||
} else {
|
||||
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,39 @@
|
||||
package me.skymc.tlm.inventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import lombok.Getter;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月22日 下午3:34:59
|
||||
*/
|
||||
public class TLMInventoryHolder implements InventoryHolder {
|
||||
|
||||
@Getter
|
||||
private String module;
|
||||
|
||||
@Getter
|
||||
private HashMap<String, Object> holderData = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param module 模块名
|
||||
*/
|
||||
public TLMInventoryHolder(String module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return null;
|
||||
}
|
||||
private String module;
|
||||
|
||||
private HashMap<String, Object> holderData = new HashMap<>();
|
||||
|
||||
public String getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> getHolderData() {
|
||||
return holderData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param module 模块名
|
||||
*/
|
||||
public TLMInventoryHolder(String module) {
|
||||
this.module = module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,17 +7,19 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
* @since 2018年2月17日 下午11:22:42
|
||||
*/
|
||||
public interface ITabooLibraryModule {
|
||||
|
||||
default void onEnable() {}
|
||||
|
||||
default void onDisable() {}
|
||||
|
||||
default void onReload() {
|
||||
}
|
||||
default void onEnable() {
|
||||
}
|
||||
|
||||
String getName();
|
||||
|
||||
default FileConfiguration getConfig() {
|
||||
return TabooLibraryModule.getInst().getConfig(this);
|
||||
}
|
||||
default void onDisable() {
|
||||
}
|
||||
|
||||
default void onReload() {
|
||||
}
|
||||
|
||||
String getName();
|
||||
|
||||
default FileConfiguration getConfig() {
|
||||
return TabooLibraryModule.getInst().getConfig(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +1,100 @@
|
||||
package me.skymc.tlm.module;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.tlm.annotation.DisableConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.tlm.annotation.DisableConfig;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018年2月17日 下午11:22:48
|
||||
*/
|
||||
public class TabooLibraryModule {
|
||||
|
||||
private final HashMap<ITabooLibraryModule, FileConfiguration> TLM_MODULE = new HashMap<>();
|
||||
private static TabooLibraryModule inst = null;
|
||||
|
||||
private TabooLibraryModule() {
|
||||
|
||||
}
|
||||
|
||||
public static TabooLibraryModule getInst() {
|
||||
if (inst == null) {
|
||||
synchronized (TabooLibraryModule.class) {
|
||||
if (inst == null) {
|
||||
inst = new TabooLibraryModule();
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
public void register(ITabooLibraryModule module) {
|
||||
if (!TLM_MODULE.containsKey(module)) {
|
||||
TLM_MODULE.put(module, new YamlConfiguration());
|
||||
reloadConfig(module, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
for (ITabooLibraryModule module : TLM_MODULE.keySet()) {
|
||||
module.onEnable();
|
||||
if (module instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) module, Main.getInst());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadModules() {
|
||||
|
||||
private static TabooLibraryModule inst = null;
|
||||
private final HashMap<ITabooLibraryModule, FileConfiguration> TLM_MODULE = new HashMap<>();
|
||||
|
||||
private TabooLibraryModule() {
|
||||
|
||||
}
|
||||
|
||||
public static TabooLibraryModule getInst() {
|
||||
if (inst == null) {
|
||||
synchronized (TabooLibraryModule.class) {
|
||||
if (inst == null) {
|
||||
inst = new TabooLibraryModule();
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
public void register(ITabooLibraryModule module) {
|
||||
if (!TLM_MODULE.containsKey(module)) {
|
||||
TLM_MODULE.put(module, new YamlConfiguration());
|
||||
reloadConfig(module, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadModules() {
|
||||
for (ITabooLibraryModule module : TLM_MODULE.keySet()) {
|
||||
module.onEnable();
|
||||
if (module instanceof Listener) {
|
||||
Bukkit.getPluginManager().registerEvents((Listener) module, Main.getInst());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadModules() {
|
||||
TLM_MODULE.keySet().forEach(ITabooLibraryModule::onDisable);
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
TLM_MODULE.keySet().forEach(x -> reloadConfig(x, true));
|
||||
}
|
||||
|
||||
public void reloadConfig(ITabooLibraryModule module, boolean isReload) {
|
||||
if (module.getName() == null || module.getClass().getAnnotation(DisableConfig.class) != null) {
|
||||
return;
|
||||
}
|
||||
File file = new File(Main.getInst().getDataFolder(), "TLM/" + module.getName() + ".yml");
|
||||
if (!file.exists()) {
|
||||
Main.getInst().saveResource("TLM/" + module.getName() + ".yml", true);
|
||||
}
|
||||
try {
|
||||
TLM_MODULE.get(module).load(file);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
}
|
||||
if (isReload) {
|
||||
module.onReload();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(ITabooLibraryModule module) {
|
||||
return TLM_MODULE.get(module);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return TLM_MODULE.size();
|
||||
}
|
||||
|
||||
public Set<ITabooLibraryModule> keySet() {
|
||||
return TLM_MODULE.keySet();
|
||||
}
|
||||
|
||||
public ITabooLibraryModule valueOf(String name) {
|
||||
for (ITabooLibraryModule module : TLM_MODULE.keySet()) {
|
||||
if (module.getName().equals(name)) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
TLM_MODULE.keySet().forEach(x -> reloadConfig(x, true));
|
||||
}
|
||||
|
||||
public void reloadConfig(ITabooLibraryModule module, boolean isReload) {
|
||||
if (module.getName() == null || module.getClass().getAnnotation(DisableConfig.class) != null) {
|
||||
return;
|
||||
}
|
||||
File file = new File(Main.getInst().getDataFolder(), "TLM/" + module.getName() + ".yml");
|
||||
if (!file.exists()) {
|
||||
Main.getInst().saveResource("TLM/" + module.getName() + ".yml", true);
|
||||
}
|
||||
try {
|
||||
TLM_MODULE.get(module).load(file);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
}
|
||||
if (isReload) {
|
||||
module.onReload();
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig(ITabooLibraryModule module) {
|
||||
return TLM_MODULE.get(module);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return TLM_MODULE.size();
|
||||
}
|
||||
|
||||
public Set<ITabooLibraryModule> keySet() {
|
||||
return TLM_MODULE.keySet();
|
||||
}
|
||||
|
||||
public ITabooLibraryModule valueOf(String name) {
|
||||
for (ITabooLibraryModule module : TLM_MODULE.keySet()) {
|
||||
if (module.getName().equals(name)) {
|
||||
return module;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user