TabooLib v4.6-R3

+ Remove depend: Vault
+ Optimize Main
This commit is contained in:
坏黑 2018-11-02 18:47:47 +08:00
parent c2b17ebd59
commit 9ae4c0701e
7 changed files with 17 additions and 118 deletions

View File

@ -4,32 +4,21 @@ import com.ilummc.tlib.TLib;
import com.ilummc.tlib.resources.TLocale;
import com.ilummc.tlib.util.IO;
import com.ilummc.tlib.util.Strings;
import me.skymc.taboolib.common.function.TFunctionLoader;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.economy.EcoUtils;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.inventory.speciaitem.SpecialItem;
import me.skymc.taboolib.itagapi.TagDataHandler;
import me.skymc.taboolib.javascript.ScriptHandler;
import me.skymc.taboolib.listener.TListenerHandler;
import me.skymc.taboolib.mysql.hikari.HikariHandler;
import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.nms.item.DabItemUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.permission.PermissionUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import me.skymc.taboolib.skript.SkriptHandler;
import me.skymc.taboolib.socket.TabooLibClient;
import me.skymc.taboolib.socket.TabooLibServer;
import me.skymc.taboolib.string.language2.Language2;
import me.skymc.taboolib.support.SupportPlaceholder;
import me.skymc.taboolib.timecycle.TimeCycleManager;
import me.skymc.taboolib.translateuuid.TranslateUUID;
import me.skymc.taboolib.update.UpdateTask;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.TabooLibraryModule;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
@ -110,24 +99,6 @@ public class Main extends JavaPlugin {
public void onEnable() {
// 注册插件配置
TabooLibLoader.register();
// 载入经济
EcoUtils.setupEconomy();
// 载入权限
PermissionUtils.loadRegisteredServiceProvider();
// 物品名称
ItemUtils.init();
// 低层工具
DabItemUtils.getInstance();
// 载入周期管理器
TimeCycleManager.load();
// 启动脚本
ScriptHandler.inst();
// 注册脚本
SkriptHandler.register();
// 注册头衔
TagDataHandler.init(this);
// 载入语言文件
exampleLanguage2 = new Language2("Language2", this);
// 启动数据库储存方法
if (getStorageType() == StorageType.SQL) {
GlobalDataManager.SQLMethod.startSQLMethod();
@ -147,16 +118,6 @@ public class Main extends JavaPlugin {
@Override
public void run() {
// 载入 PlaceholderAPI 扩展
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new SupportPlaceholder(getInst(), "taboolib").hook();
}
// 载入 TLM 接口
TLM.getInst();
// 载入 SpecialItem 接口
SpecialItem.getInst().loadItems();
// 载入 TranslateUUID 工具
TranslateUUID.init();
// 面子工程
InputStream inputStream = FileUtils.getResource("motd.txt");
try {
@ -178,6 +139,8 @@ public class Main extends JavaPlugin {
new UpdateTask();
// 启动
started = true;
// 载入语言文件
exampleLanguage2 = new Language2("Language2", this);
}
@Override
@ -198,12 +161,6 @@ public class Main extends JavaPlugin {
DataUtils.saveAllCaches();
// 保存玩家数据
PlayerDataManager.saveAllPlayers(false, true);
// 注销 SpecialItem 接口
SpecialItem.getInst().unloadItems();
// 注销 TLM 接口
TabooLibraryModule.getInst().unloadModules();
// 注销 TranslateUUID 接口
TranslateUUID.cancel();
// 注销连接池
HikariHandler.closeDataSourceForce();
// 注销监听器

View File

@ -60,6 +60,11 @@ public class TabooLibLoader implements Listener {
static void unregister() {
unloadClasses();
try {
tabooLibDeprecated.unregister();
} catch (Exception e) {
e.printStackTrace();
}
}
public static TabooLibDeprecated getTabooLibDeprecated() {

View File

@ -5,6 +5,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.common.configuration.TConfiguration;
import me.skymc.taboolib.common.function.TFunction;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.itemnbtapi.NBTItem;
import me.skymc.taboolib.itemnbtapi.NBTList;
@ -37,6 +38,7 @@ import java.util.stream.IntStream;
/**
* @author sky
*/
@TFunction(enable = "init")
public class ItemUtils {
private static File finalItemsFolder;

View File

@ -3,6 +3,7 @@ package me.skymc.taboolib.itagapi;
import com.google.common.base.Preconditions;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.common.function.TFunction;
import me.skymc.taboolib.packet.PacketUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -24,16 +25,17 @@ import java.util.UUID;
* @Author sky
* @Since 2018-05-23 0:37
*/
@TFunction(enable = "init")
public class TagDataHandler implements Listener {
private static TagDataHandler handler;
private HashMap<UUID, TagPlayerData> playersData = new HashMap<>();
public static void init(Plugin plugin) {
public static void init() {
Preconditions.checkArgument(handler == null, "TagDataHandler is already instanced!");
handler = new TagDataHandler();
// 注册监听
Bukkit.getPluginManager().registerEvents(handler, plugin);
Bukkit.getPluginManager().registerEvents(handler, TabooLib.instance());
// 启动相关功能
new BukkitRunnable() {
@ -43,7 +45,7 @@ public class TagDataHandler implements Listener {
TagPacket.inst();
}
}
}.runTask(plugin);
}.runTask(TabooLib.instance());
}
public TagPlayerData unregisterPlayerData(Player player) {

View File

@ -2,6 +2,7 @@ package me.skymc.taboolib.javascript;
import com.ilummc.tlib.logger.TLogger;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
import me.skymc.taboolib.common.function.TFunction;
import org.bukkit.configuration.file.FileConfiguration;
import javax.script.Compilable;
@ -14,12 +15,13 @@ import java.util.Objects;
* @Author sky
* @Since 2018-06-02 22:48
*/
@TFunction(enable = "init")
public class ScriptHandler {
private static ScriptEngine scriptEngine;
private static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
public static void inst() {
public static void init() {
try {
NashornScriptEngineFactory factory = (NashornScriptEngineFactory) scriptEngineManager.getEngineFactories().stream().filter(factories -> "Oracle Nashorn".equalsIgnoreCase(factories.getEngineName())).findFirst().orElse(null);
scriptEngine = Objects.requireNonNull(factory).getScriptEngine("-doe", "--global-per-engine");

View File

@ -1,69 +0,0 @@
package me.skymc.taboolib.support;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.tlm.module.sub.ModuleKits;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
* @author sky
*/
public class SupportPlaceholder extends EZPlaceholderHook {
public SupportPlaceholder(Plugin plugin, String identifier) {
super(plugin, identifier);
}
@Override
public String onPlaceholderRequest(Player player, String args) {
if (args.startsWith("variable_")) {
String[] value = args.split("_");
StringBuilder sb = new StringBuilder();
for (int i = 1; i < value.length; i++) {
sb.append(value[i]).append("_");
}
return GlobalDataManager.getVariableAsynchronous(sb.substring(0, sb.length() - 1), "<none>");
}
if (args.startsWith("tlm_kit_")) {
// 是否启用
if (TabooLibraryModule.getInst().valueOf("Kits") == null) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.0").asString();
}
// 获取模块
ModuleKits moduleKits = (ModuleKits) TabooLibraryModule.getInst().valueOf("Kits");
String kit = args.split("_")[2];
// 礼包不存在
if (!moduleKits.contains(kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.1").asString();
}
// 是否领取
if (moduleKits.isPlayerRewared(player, kit)) {
// 是否只能领取一次
if (moduleKits.isDisposable(kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.2").asString();
}
// 是否冷却中
if (moduleKits.isPlayerCooldown(player, kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.4").asString();
}
}
// 是否有权限领取
String permission = moduleKits.getPermission(kit);
if (permission != null && !player.hasPermission(permission)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.5").asString();
}
// 可领取
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.3").asString();
}
return null;
}
}