master
坏黑 2019-07-06 19:30:56 +08:00
parent 23612b8ee7
commit 44a9b79404
10 changed files with 31 additions and 15 deletions

View File

@ -10,6 +10,7 @@ import io.izzel.taboolib.module.db.local.Local;
import io.izzel.taboolib.module.db.source.DBSource;
import io.izzel.taboolib.module.dependency.TDependencyInjector;
import io.izzel.taboolib.module.inject.TListenerHandler;
import io.izzel.taboolib.module.inject.TScheduleLoader;
import io.izzel.taboolib.module.locale.TLocaleLoader;
import org.bukkit.plugin.Plugin;
@ -55,10 +56,14 @@ public abstract class PluginLoader {
public void onActivated(Plugin plugin) {
// 注册监听器
TListenerHandler.registerListener(plugin);
// 注册调度器
TScheduleLoader.run(plugin);
}
@Override
public void onStopping(Plugin plugin) {
// 卸载语言文件
TLocaleLoader.unload(plugin);
// 保存数据
Local.saveFiles(plugin.getName());
Local.clearFiles(plugin.getName());

View File

@ -63,7 +63,7 @@ public class TabooLib {
TabooLibLoader.init();
// 创建线程检测服务器是否关闭
Executors.newSingleThreadExecutor().submit(() -> {
while (NMS.getHandler().isRunning()) {
while (NMS.handle().isRunning()) {
}
// 保存数据
Local.saveFiles();

View File

@ -42,7 +42,7 @@ public class TabooLibAPI {
}
public static double[] getTPS() {
return NMS.getHandler().getTPS();
return NMS.handle().getTPS();
}
public static boolean isDebug() {

View File

@ -21,6 +21,13 @@ public class TScheduleLoader implements TabooLibLoader.Loader {
static Map<String, List<TScheduleData>> schedules = Maps.newHashMap();
public static void run(Plugin plugin) {
List<TScheduleData> list = schedules.get(plugin.getName());
if (list != null) {
list.forEach(data -> run(plugin, data.getRunnable(), data.getAnnotation().delay(), data.getAnnotation().period(), data.getAnnotation().async()));
}
}
public static void run(Plugin plugin, BukkitRunnable runnable, int delay, int period, boolean async) {
if (async) {
runnable.runTaskTimerAsynchronously(plugin, delay, period);

View File

@ -56,7 +56,7 @@ public class SimpleI18n {
}
public static String getName(Entity entity) {
return entity == null ? "-" : lang.getString(NMS.getHandler().getName(entity).replace(".", "_"), entity.getName());
return entity == null ? "-" : lang.getString(NMS.handle().getName(entity).replace(".", "_"), entity.getName());
}
public static String getName(ItemStack item) {
@ -69,7 +69,7 @@ public class SimpleI18n {
}
if (!Version.isAfter(Version.v1_11)) {
if (item.getType().name().equals("MONSTER_EGG")) {
NBTCompound nbtCompound = NMS.getHandler().loadNBT(item);
NBTCompound nbtCompound = NMS.handle().loadNBT(item);
if (nbtCompound.containsKey("EntityTag")) {
return lang.getString("item_monsterPlacer_name") + " " + lang.getString("entity_" + nbtCompound.get("EntityTag").asCompound().get("id").asString() + "_name");
}
@ -79,11 +79,11 @@ public class SimpleI18n {
if (itemMeta instanceof SpawnEggMeta) {
String spawnEggType = lang.getString("entity_" + ((SpawnEggMeta) itemMeta).getSpawnedType().getEntityClass().getSimpleName().replace(".", "_") + "_name");
if (spawnEggType != null) {
return lang.getString(NMS.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType;
return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType;
}
}
}
return lang.getString(NMS.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", ""));
return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", ""));
}
private static void releaseLocales(Plugin plugin) {

View File

@ -96,11 +96,11 @@ public class TLocale {
}
public static void sendTitle(Player player, String title, String subTitle, int fadein, int stay, int fadeout) {
NMS.getHandler().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout);
NMS.handle().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout);
}
public static void sendActionBar(Player player, String text) {
NMS.getHandler().sendActionBar(player, text);
NMS.handle().sendActionBar(player, text);
}
}

View File

@ -87,6 +87,10 @@ public class TLocaleLoader {
}
}
public static void unload(Plugin plugin) {
map.remove(plugin.getName());
}
public static boolean isLocaleLoaded(Plugin plugin) {
return map.containsKey(plugin.getName());
}

View File

@ -15,15 +15,15 @@ import org.bukkit.inventory.ItemStack;
@TFunction(enable = "init")
public abstract class NMS {
private static NMS handler;
private static NMS impl;
public static NMS getHandler() {
return handler;
public static NMS handle() {
return impl;
}
static void init() {
try {
handler = (NMS) SimpleVersionControl.createNMS("io.izzel.taboolib.module.nms.NMSHandlerImpl").translate().newInstance();
impl = (NMS) SimpleVersionControl.createNMS("io.izzel.taboolib.module.nms.NMSImpl").translate().newInstance();
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -232,7 +232,7 @@ public class Items {
// 元数据
item.setItemMeta(meta);
// 数据
NBTCompound nbt = NMS.getHandler().loadNBT(item);
NBTCompound nbt = NMS.handle().loadNBT(item);
// 物品标签
if (section.contains("nbt")) {
for (String name : section.getConfigurationSection("nbt").getKeys(false)) {
@ -281,6 +281,6 @@ public class Items {
}
nbt.put("AttributeModifiers", attr);
}
return NMS.getHandler().saveNBT(item, nbt);
return NMS.handle().saveNBT(item, nbt);
}
}

View File

@ -843,7 +843,7 @@ public enum Particles {
data = getDustColor((OrdinaryColor) data, size);
}
}
this.packet = NMS.getHandler().toPacketPlayOutWorldParticles(effect.getBukkitParticle(), longDistance, (float) center.getX(), (float) center.getY(), (float) center.getZ(), offsetX, offsetY, offsetZ, speed, amount, data);
this.packet = NMS.handle().toPacketPlayOutWorldParticles(effect.getBukkitParticle(), longDistance, (float) center.getX(), (float) center.getY(), (float) center.getZ(), offsetX, offsetY, offsetZ, speed, amount, data);
} catch (Throwable exception) {
throw new PacketInstantiationException("Packet instantiation failed", exception);
}