版本更新至 3.55
新增:ItemUtils 工具新增 isNull() 方法 新增:SpecialItem 工具类 新增:SpecialItemResult 枚举类 新增:AbstractSpecialItem 接口类 新增:Language2Value 对象新增 asString() 方法获取语言文本 新增:ITabooLibraryModule 接口类 新增:TabooLibraryModule 工具类 新增:TLM 框架大致完成。 新增:TLM 框架首个模块 TimeCycle 完成。 修复:Language2 的文本集合类型不再会移除第一条内容了。
This commit is contained in:
@@ -36,6 +36,7 @@ import me.skymc.taboolib.economy.EcoUtils;
|
||||
import me.skymc.taboolib.entity.EntityUtils;
|
||||
import me.skymc.taboolib.fileutils.ConfigUtils;
|
||||
import me.skymc.taboolib.inventory.ItemUtils;
|
||||
import me.skymc.taboolib.inventory.speciaitem.SpecialItem;
|
||||
import me.skymc.taboolib.javashell.JavaShell;
|
||||
import me.skymc.taboolib.listener.ListenerPlayerCommand;
|
||||
import me.skymc.taboolib.listener.ListenerPlayerQuit;
|
||||
@@ -50,6 +51,9 @@ import me.skymc.taboolib.string.language2.Language2;
|
||||
import me.skymc.taboolib.support.SupportPlaceholder;
|
||||
import me.skymc.taboolib.team.TagUtils;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleManager;
|
||||
import me.skymc.tlm.TLM;
|
||||
import me.skymc.tlm.command.TLMCommands;
|
||||
import me.skymc.tlm.module.TabooLibraryModule;
|
||||
import me.skymc.taboolib.nms.item.DabItemUtils;
|
||||
import me.skymc.taboolib.other.NumberUtils;
|
||||
import me.skymc.taboolib.permission.PermissionUtils;
|
||||
@@ -168,6 +172,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||
// 注册指令
|
||||
getCommand("taboolib").setExecutor(new MainCommands());
|
||||
getCommand("language2").setExecutor(new Language2Command());
|
||||
getCommand("taboolibrarymodule").setExecutor(new TLMCommands());
|
||||
|
||||
// 注册监听
|
||||
registerListener();
|
||||
@@ -209,6 +214,10 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
new SupportPlaceholder(getInst(), "taboolib").hook();
|
||||
}
|
||||
// 载入 SpecialItem 接口
|
||||
SpecialItem.getInst().loadItems();
|
||||
// 载入 TLM 接口
|
||||
TLM.getInst();
|
||||
}
|
||||
}.runTask(this);
|
||||
}
|
||||
@@ -227,6 +236,10 @@ public class Main extends JavaPlugin implements Listener {
|
||||
PlayerDataManager.saveAllPlayers(false, true);
|
||||
// 结束脚本
|
||||
JavaShell.javaShellCancel();
|
||||
// 注销 SpecialItem 接口
|
||||
SpecialItem.getInst().unloadItems();
|
||||
// 注销 TLM 接口
|
||||
TabooLibraryModule.getInst().unloadModules();
|
||||
|
||||
// 结束数据库储存方法
|
||||
if (getStorageType() == StorageType.SQL) {
|
||||
|
||||
@@ -188,6 +188,10 @@ public class ItemUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static boolean isNull(ItemStack item) {
|
||||
return item == null || item.getType().equals(Material.AIR);
|
||||
}
|
||||
|
||||
public static boolean isName(ItemStack i, String a) {
|
||||
if (!isNamed(i) || i.getItemMeta() == null || i.getItemMeta().getDisplayName() == null || !i.getItemMeta().getDisplayName().equals(a)) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package me.skymc.taboolib.inventory.speciaitem;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>8:35:42
|
||||
*/
|
||||
public abstract interface AbstractSpecialItem {
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>ӿڱ<D3BF><DAB1><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
default void onEnable() {}
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>ӿڱ<D3BF>ж<EFBFBD><D0B6>
|
||||
*/
|
||||
default void onDisable() {}
|
||||
|
||||
/**
|
||||
* <20><>ȡʶ<C8A1><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
abstract String getName();
|
||||
|
||||
/**
|
||||
* <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return {@link Plugin}
|
||||
*/
|
||||
abstract Plugin getPlugin();
|
||||
|
||||
/**
|
||||
* <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>¼<EFBFBD>
|
||||
*
|
||||
* @param player <20><><EFBFBD><EFBFBD>
|
||||
* @param currentItem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
* @param cursorItem <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
* @return {@link SpecialItemResult[]}
|
||||
*/
|
||||
abstract SpecialItemResult[] isCorrectClick(Player player, ItemStack currentItem, ItemStack cursorItem);
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package me.skymc.taboolib.inventory.speciaitem;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.inventory.ItemUtils;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>8:34:12
|
||||
*/
|
||||
public class SpecialItem implements Listener {
|
||||
|
||||
private static SpecialItem specialItem = null;
|
||||
|
||||
private final List<AbstractSpecialItem> ITEM_DATA = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Getter
|
||||
private boolean isLoaded;
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>췽<EFBFBD><ECB7BD>
|
||||
*/
|
||||
private SpecialItem() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><>ȡ<EFBFBD><C8A1><EFBFBD>߶<EFBFBD><DFB6><EFBFBD>
|
||||
*
|
||||
* @return {@link SpecialItem}
|
||||
*/
|
||||
public static SpecialItem getInst() {
|
||||
if (specialItem == null) {
|
||||
synchronized (SpecialItem.class) {
|
||||
if (specialItem == null) {
|
||||
specialItem = new SpecialItem();
|
||||
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Bukkit.getPluginManager().registerEvents(specialItem, Main.getInst());
|
||||
}
|
||||
}
|
||||
}
|
||||
return specialItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* ע<><D7A2><EFBFBD>ӿ<EFBFBD>
|
||||
*
|
||||
* @param item <20>ӿڶ<D3BF><DAB6><EFBFBD>
|
||||
*/
|
||||
public void register(AbstractSpecialItem item) {
|
||||
if (contains(item.getName())) {
|
||||
MsgUtils.warn("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ӿ<EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> &4" + item.getName() + " &c<>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>");
|
||||
}
|
||||
else {
|
||||
ITEM_DATA.add(item);
|
||||
if (isLoaded) {
|
||||
item.onEnable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ע<><D7A2><EFBFBD>ӿ<EFBFBD>
|
||||
*
|
||||
* @param name ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
public void cancel(String name) {
|
||||
for (AbstractSpecialItem specialitem : ITEM_DATA) {
|
||||
if (specialitem.getName() != null && specialitem.getName().equals(specialitem)) {
|
||||
specialitem.onDisable();
|
||||
ITEM_DATA.remove(specialitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ע<><D7A2><EFBFBD>ӿ<EFBFBD>
|
||||
*
|
||||
* @param plugin ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
public void cancel(Plugin plugin) {
|
||||
for (AbstractSpecialItem specialitem : ITEM_DATA) {
|
||||
if (specialitem.getPlugin() != null && specialitem.getPlugin().equals(plugin)) {
|
||||
specialitem.onDisable();
|
||||
ITEM_DATA.remove(specialitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param name ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean contains(String name) {
|
||||
for (AbstractSpecialItem specialitem : ITEM_DATA) {
|
||||
if (specialitem.getName().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>ӿ<EFBFBD>
|
||||
*/
|
||||
public void loadItems() {
|
||||
ITEM_DATA.forEach(x -> x.onEnable());
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD>ӿ<EFBFBD>
|
||||
*/
|
||||
public void unloadItems() {
|
||||
ITEM_DATA.forEach(x -> x.onDisable());
|
||||
ITEM_DATA.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisable(PluginDisableEvent e) {
|
||||
cancel(e.getPlugin());
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.MONITOR)
|
||||
public void click(InventoryClickEvent e) {
|
||||
if (e.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (ItemUtils.isNull(e.getCurrentItem()) || ItemUtils.isNull(e.getCursor())) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
for (AbstractSpecialItem specialitem : ITEM_DATA) {
|
||||
for (SpecialItemResult result : specialitem.isCorrectClick(player, e.getCurrentItem(), e.getCursor())) {
|
||||
if (result == SpecialItemResult.CANCEL) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
else if (result == SpecialItemResult.BREAK) {
|
||||
return;
|
||||
}
|
||||
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT) {
|
||||
e.setCurrentItem(null);
|
||||
}
|
||||
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR) {
|
||||
e.getWhoClicked().setItemOnCursor(null);
|
||||
}
|
||||
else if (result == SpecialItemResult.REMOVE_ITEM_CURRENT_AMOUNT_1) {
|
||||
if (e.getCurrentItem().getAmount() > 1) {
|
||||
e.getCurrentItem().setAmount(e.getCurrentItem().getAmount() - 1);
|
||||
}
|
||||
else {
|
||||
e.setCurrentItem(null);
|
||||
}
|
||||
}
|
||||
else if (result == SpecialItemResult.REMOVE_ITEM_CURSOR_AMOUNT_1) {
|
||||
if (e.getCursor().getAmount() > 1) {
|
||||
e.getCursor().setAmount(e.getCursor().getAmount() - 1);
|
||||
}
|
||||
else {
|
||||
e.getWhoClicked().setItemOnCursor(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package me.skymc.taboolib.inventory.speciaitem;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>8:55:36
|
||||
*/
|
||||
public enum SpecialItemResult {
|
||||
|
||||
/**
|
||||
* ֹͣ<CDA3>ӿڼ<D3BF><DABC><EFBFBD>
|
||||
*/
|
||||
BREAK,
|
||||
|
||||
/**
|
||||
* ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
||||
*/
|
||||
CANCEL,
|
||||
|
||||
/**
|
||||
* <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
*/
|
||||
REMOVE_ITEM_CURRENT,
|
||||
|
||||
/**
|
||||
* <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
*/
|
||||
REMOVE_ITEM_CURSOR,
|
||||
|
||||
/**
|
||||
* <20>Ƴ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
*/
|
||||
REMOVE_ITEM_CURRENT_AMOUNT_1,
|
||||
|
||||
/**
|
||||
* <20>Ƴ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
||||
*/
|
||||
REMOVE_ITEM_CURSOR_AMOUNT_1;
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -38,7 +40,7 @@ public class Language2Value {
|
||||
private LinkedHashMap<String, String> placeholder = new LinkedHashMap<>();
|
||||
|
||||
@Getter
|
||||
private boolean enablePlaceholderAPI;
|
||||
private boolean enablePlaceholderAPI = false;
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>췽<EFBFBD><ECB7BD>
|
||||
@@ -63,6 +65,14 @@ public class Language2Value {
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
String type = languageValue.get(0).toLowerCase();
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
boolean isType = true;
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>PAPI
|
||||
if (type.contains("[papi]")) {
|
||||
enablePlaceholderAPI = true;
|
||||
}
|
||||
|
||||
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (type.contains("[json]")) {
|
||||
languageType = Language2Type.JSON;
|
||||
@@ -75,18 +85,13 @@ public class Language2Value {
|
||||
}
|
||||
else {
|
||||
languageType = Language2Type.TEXT;
|
||||
isType = false;
|
||||
}
|
||||
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>PAPI
|
||||
if (type.contains("[papi]")) {
|
||||
enablePlaceholderAPI = true;
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>
|
||||
if (isType) {
|
||||
languageValue.remove(0);
|
||||
}
|
||||
else {
|
||||
enablePlaceholderAPI = false;
|
||||
}
|
||||
|
||||
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
languageValue.remove(0);
|
||||
}
|
||||
else {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
||||
@@ -108,24 +113,18 @@ public class Language2Value {
|
||||
public void send(Player player) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (languageType == Language2Type.TITLE) {
|
||||
// ʶ<><CAB6><EFBFBD>ı<EFBFBD>
|
||||
Language2Title title = new Language2Title(this);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
||||
title.send(player);
|
||||
new Language2Title(this).send(player);
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else if (languageType == Language2Type.ACTION) {
|
||||
// ʶ<><CAB6><EFBFBD>ı<EFBFBD>
|
||||
Language2Action action = new Language2Action(this);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
||||
action.send(player);
|
||||
new Language2Action(this).send(player);
|
||||
}
|
||||
// JSON<4F><4E><EFBFBD><EFBFBD>
|
||||
else if (languageType == Language2Type.JSON) {
|
||||
// ʶ<><CAB6><EFBFBD>ı<EFBFBD>
|
||||
Language2Json json = new Language2Json(this, player);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
||||
json.send(player);
|
||||
new Language2Json(this, player).send(player);
|
||||
}
|
||||
else {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
||||
@@ -186,6 +185,29 @@ public class Language2Value {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><>ȡ<EFBFBD>ı<EFBFBD>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String asString() {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (languageType == Language2Type.TITLE) {
|
||||
return new Language2Title(this).getTitle();
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else if (languageType == Language2Type.ACTION) {
|
||||
return new Language2Action(this).getText();
|
||||
}
|
||||
// JSON<4F><4E><EFBFBD><EFBFBD>
|
||||
else if (languageType == Language2Type.JSON) {
|
||||
return new Language2Json(this, null).getText().toString();
|
||||
}
|
||||
else {
|
||||
return languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : languageValue.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD>滻
|
||||
*
|
||||
|
||||
72
src/main/src/me/skymc/tlm/TLM.java
Normal file
72
src/main/src/me/skymc/tlm/TLM.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package me.skymc.tlm;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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;
|
||||
import me.skymc.tlm.module.TabooLibraryModule;
|
||||
import me.skymc.tlm.module.sub.ModuleTimeCycle;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>10:28:05
|
||||
*/
|
||||
public class TLM {
|
||||
|
||||
private static TLM inst = null;
|
||||
|
||||
@Getter
|
||||
private FileConfiguration config;
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD>췽<EFBFBD><ECB7BD>
|
||||
*/
|
||||
private TLM() {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
reloadConfig();
|
||||
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
if (isEnableModule("TimeCycle")) {
|
||||
TabooLibraryModule.getInst().register(new ModuleTimeCycle());
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
|
||||
TabooLibraryModule.getInst().loadModules();
|
||||
// <20><>ʾ
|
||||
MsgUtils.send("<EFBFBD><EFBFBD><EFBFBD><EFBFBD> &f" + TabooLibraryModule.getInst().getSize() + " &7<><37> &fTLM &7ģ<37><C4A3>");
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><>ȡ TLM <20><><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return TLM
|
||||
*/
|
||||
public static TLM getInst() {
|
||||
if (inst == null) {
|
||||
synchronized (TLM.class) {
|
||||
if (inst == null) {
|
||||
inst = new TLM();
|
||||
}
|
||||
}
|
||||
}
|
||||
return inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
*/
|
||||
public void reloadConfig() {
|
||||
config = ConfigUtils.saveDefaultConfig(Main.getInst(), "module.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* ģ<><C4A3><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param name <20><><EFBFBD><EFBFBD>
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean isEnableModule(String name) {
|
||||
return config.getStringList("EnableModule").contains(name);
|
||||
}
|
||||
}
|
||||
66
src/main/src/me/skymc/tlm/command/TLMCommands.java
Normal file
66
src/main/src/me/skymc/tlm/command/TLMCommands.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package me.skymc.tlm.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
import me.skymc.tlm.TLM;
|
||||
import me.skymc.tlm.module.ITabooLibraryModule;
|
||||
import me.skymc.tlm.module.TabooLibraryModule;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>18<31><38> <20><><EFBFBD><EFBFBD>12:02:08
|
||||
*/
|
||||
public class TLMCommands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>b<EFBFBD><EFBFBD>l----- <20><>3<EFBFBD><33>lTaooLibraryModule Commands <20><>b<EFBFBD><62>l-----");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>7 /tlm list <20><>f- <20><>8<EFBFBD>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>7 /tlm reload [ģ<><C4A3><EFBFBD><EFBFBD>/TLM/ALL] <20><>f- <20><>8<EFBFBD><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (args.length != 2) {
|
||||
MsgUtils.send(sender, "&4<><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
else if (args[1].equalsIgnoreCase("tlm")) {
|
||||
TLM.getInst().reloadConfig();
|
||||
MsgUtils.send(sender, "&fTLM &7<><37><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>");
|
||||
}
|
||||
|
||||
else if (args[1].equalsIgnoreCase("all")) {
|
||||
TabooLibraryModule.getInst().reloadConfig();
|
||||
MsgUtils.send(sender, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>");
|
||||
}
|
||||
|
||||
else {
|
||||
ITabooLibraryModule module = TabooLibraryModule.getInst().valueOf(args[1]);
|
||||
if (module == null) {
|
||||
MsgUtils.send(sender, "&4ģ<34><C4A3> &c" + args[1] + " &4<><34><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>");
|
||||
}
|
||||
else {
|
||||
TabooLibraryModule.getInst().reloadConfig(module, true);
|
||||
MsgUtils.send(sender, "ģ<EFBFBD><EFBFBD> &f" + args[1] + " &7<><37><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ء<EFBFBD>");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("list")) {
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>b<EFBFBD><EFBFBD>l----- <20><>3<EFBFBD><33>lTaooLibraryModule Modules <20><>b<EFBFBD><62>l-----");
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
for (ITabooLibraryModule module : TabooLibraryModule.getInst().keySet()) {
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f - <20><>8" + module.getName());
|
||||
}
|
||||
sender.sendMessage("<EFBFBD><EFBFBD>f");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
22
src/main/src/me/skymc/tlm/module/ITabooLibraryModule.java
Normal file
22
src/main/src/me/skymc/tlm/module/ITabooLibraryModule.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package me.skymc.tlm.module;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>11:22:42
|
||||
*/
|
||||
public abstract interface ITabooLibraryModule {
|
||||
|
||||
default void onEnable() {}
|
||||
|
||||
default void onDisable() {}
|
||||
|
||||
default void onReload() {};
|
||||
|
||||
abstract String getName();
|
||||
|
||||
default FileConfiguration getConfig() {
|
||||
return TabooLibraryModule.getInst().getConfig(this);
|
||||
}
|
||||
}
|
||||
100
src/main/src/me/skymc/tlm/module/TabooLibraryModule.java
Normal file
100
src/main/src/me/skymc/tlm/module/TabooLibraryModule.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package me.skymc.tlm.module;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>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() {
|
||||
TLM_MODULE.keySet().forEach(x -> x.onDisable());
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
TLM_MODULE.keySet().forEach(x -> reloadConfig(x, true));
|
||||
}
|
||||
|
||||
public void reloadConfig(ITabooLibraryModule module, boolean isReload) {
|
||||
if (module.getName() == 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;
|
||||
}
|
||||
}
|
||||
114
src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java
Normal file
114
src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java
Normal file
@@ -0,0 +1,114 @@
|
||||
package me.skymc.tlm.module.sub;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.message.MsgUtils;
|
||||
import me.skymc.taboolib.other.DateUtils;
|
||||
import me.skymc.taboolib.other.NumberUtils;
|
||||
import me.skymc.taboolib.timecycle.TimeCycle;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleEvent;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
|
||||
import me.skymc.taboolib.timecycle.TimeCycleManager;
|
||||
import me.skymc.tlm.module.ITabooLibraryModule;
|
||||
|
||||
/**
|
||||
* @author sky
|
||||
* @since 2018<31><38>2<EFBFBD><32>17<31><37> <20><><EFBFBD><EFBFBD>11:23:38
|
||||
*/
|
||||
public class ModuleTimeCycle implements ITabooLibraryModule, Listener {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TimeCycle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
loadCycles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
unloadCycles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
unloadCycles();
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
loadCycles();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTimeCycleInitialize(TimeCycleInitializeEvent e) {
|
||||
if (e.getCycle().getName().contains("tlm|")) {
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
String name = e.getCycle().getName().replace("tlm|", "");
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (getConfig().contains("TimeCycle." + name + ".Initialise.InitialiseDate")) {
|
||||
// <20><>ȡʱ<C8A1><CAB1>
|
||||
Calendar date = Calendar.getInstance();
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (String typeStr : getConfig().getStringList("TimeCycle." + name + ".Initialise.InitialiseDate")) {
|
||||
try {
|
||||
int type = (int) Calendar.class.getField(typeStr.split("=")[0]).get(Calendar.class);
|
||||
date.set(type, NumberUtils.getInteger(typeStr.split("=")[1]));
|
||||
} catch (Exception err) {
|
||||
MsgUtils.warn("ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣");
|
||||
MsgUtils.warn("ģ<EFBFBD><EFBFBD>: &4TimeCycle");
|
||||
MsgUtils.warn("λ<EFBFBD><EFBFBD>: &4" + typeStr);
|
||||
}
|
||||
}
|
||||
e.setTimeLine(date.getTimeInMillis());
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (getConfig().contains("TimeCycle." + name + ".Initialise.InitialiseCommand")) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (String command : getConfig().getStringList("TimeCycle." + name + ".Initialise.InitialiseCommand")) {
|
||||
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Bukkit.getScheduler().runTask(Main.getInst(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTimeCycle(TimeCycleEvent e) {
|
||||
if (e.getCycle().getName().contains("tlm|")) {
|
||||
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
String name = e.getCycle().getName().replace("tlm|", "");
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (getConfig().contains("TimeCycle." + name + ".UpdateCommand")) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for (String command : getConfig().getStringList("TimeCycle." + name + ".UpdateCommand")) {
|
||||
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Bukkit.getScheduler().runTask(Main.getInst(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCycles() {
|
||||
for (String name : getConfig().getConfigurationSection("TimeCycle").getKeys(false)) {
|
||||
TimeCycleManager.register(new TimeCycle("tlm|" + name, DateUtils.formatDate(getConfig().getString("TimeCycle." + name + ".Cycle")), Main.getInst()));
|
||||
}
|
||||
}
|
||||
|
||||
private void unloadCycles() {
|
||||
for (TimeCycle cycle : TimeCycleManager.getTimeCycles()) {
|
||||
if (cycle.getName().startsWith("tlm|")) {
|
||||
TimeCycleManager.cancel(cycle.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/resources/TLM/TimeCycle.yml
Normal file
35
src/resources/TLM/TimeCycle.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
# 时间检查器
|
||||
TimeCycle:
|
||||
# 检查器名称
|
||||
cycle_name:
|
||||
# 检查器周期
|
||||
# ---------- #
|
||||
# 1d = 1天
|
||||
# 1h = 1小时
|
||||
# 1m = 1分钟
|
||||
# 1s = 1秒钟
|
||||
# 时间之间用 ";" 分隔, 例如 1小时30分钟 = "1h;30m"
|
||||
# ---------- #
|
||||
Cycle: '1d'
|
||||
|
||||
# 更新配置
|
||||
UpdateCommand:
|
||||
- 'say 检查器 cycle_name 更新!'
|
||||
|
||||
# 初始化配置
|
||||
Initialise:
|
||||
# 初始化时间
|
||||
# 特殊时间
|
||||
# - DAY_OF_WEEK = 本周第几天 (最小:1)
|
||||
# - DAY_OF_MONTH = 本月第几天 (最小:1)
|
||||
InitialiseDate:
|
||||
# 初始化时将小时设置为 0
|
||||
- 'HOUR_OF_DAY=0'
|
||||
# 初始化时将分钟设置为 0
|
||||
- 'MINUTE=0'
|
||||
# 初始化时将秒钟设置为 0
|
||||
- 'SECOND=0'
|
||||
|
||||
# 初始化命令
|
||||
InitialiseCommand:
|
||||
- 'say 检查器 cycle_name 初始化完成!'
|
||||
4
src/resources/module.yml
Normal file
4
src/resources/module.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
# 启用模块
|
||||
# 该配置需要重启服务器才会生效
|
||||
EnableModule:
|
||||
#- 'TimeCycle'
|
||||
Reference in New Issue
Block a user