update 5.04
This commit is contained in:
parent
eab2835c52
commit
a643453c88
@ -5,7 +5,7 @@ plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '4.0.4'
|
||||
}
|
||||
group = 'me.skymc'
|
||||
version = '5.03'
|
||||
version = '5.04'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
@ -26,7 +26,7 @@ public class TabooLibLoader {
|
||||
|
||||
static Map<String, List<Class>> pluginClasses = Maps.newHashMap();
|
||||
static List<Loader> loaders = Lists.newArrayList();
|
||||
static List<Runnable> runnables = Lists.newArrayList();
|
||||
static List<Runnable> tasks = Lists.newArrayList();
|
||||
static boolean started;
|
||||
|
||||
static void init() {
|
||||
@ -60,18 +60,30 @@ public class TabooLibLoader {
|
||||
return classes == null ? new ArrayList<>() : new ArrayList<>(classes);
|
||||
}
|
||||
|
||||
public static Map<String, List<Class>> getPluginClasses() {
|
||||
return pluginClasses;
|
||||
}
|
||||
|
||||
public static List<Loader> getLoaders() {
|
||||
return loaders;
|
||||
}
|
||||
|
||||
public static List<Runnable> getTasks() {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
public static boolean isStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
public static void runTask(Runnable runnable) {
|
||||
if (started) {
|
||||
runnable.run();
|
||||
} else {
|
||||
runnables.add(runnable);
|
||||
tasks.add(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isLoader(Class pluginClass) {
|
||||
return !Loader.class.equals(pluginClass) && Loader.class.isAssignableFrom(pluginClass);
|
||||
}
|
||||
|
||||
@TSchedule
|
||||
static void start() {
|
||||
PluginLoader.active(TabooLib.getPlugin());
|
||||
@ -82,7 +94,7 @@ public class TabooLibLoader {
|
||||
// 通讯网络客户端
|
||||
TabooLibClient.init();
|
||||
// 执行动作
|
||||
for (Runnable runnable : runnables) {
|
||||
for (Runnable runnable : tasks) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable t) {
|
||||
@ -163,6 +175,10 @@ public class TabooLibLoader {
|
||||
});
|
||||
}
|
||||
|
||||
static boolean isLoader(Class pluginClass) {
|
||||
return !Loader.class.equals(pluginClass) && Loader.class.isAssignableFrom(pluginClass);
|
||||
}
|
||||
|
||||
public interface Loader {
|
||||
|
||||
default void preLoad(org.bukkit.plugin.Plugin plugin, Class<?> pluginClass) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.izzel.taboolib.common.event;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
@ -11,8 +12,7 @@ public class PlayerJumpEvent extends Event implements Cancellable {
|
||||
private boolean isCancelled;
|
||||
private Player player;
|
||||
|
||||
public PlayerJumpEvent(boolean b, Player player) {
|
||||
this.isCancelled = false;
|
||||
public PlayerJumpEvent(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@ -24,6 +24,11 @@ public class PlayerJumpEvent extends Event implements Cancellable {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public PlayerJumpEvent call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.isCancelled;
|
||||
|
@ -1,52 +1,40 @@
|
||||
package io.izzel.taboolib.common.listener;
|
||||
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
import io.izzel.taboolib.common.event.PlayerJumpEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import io.izzel.taboolib.module.inject.TInject;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
import io.izzel.taboolib.util.lite.cooldown.Cooldown;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@TListener
|
||||
public class ListenerPlayerJump implements Listener {
|
||||
|
||||
public HashMap<Player, Long> cooldown = new HashMap<>();
|
||||
@TInject
|
||||
private static Cooldown cooldown = new Cooldown("taboolib:jump", 350);
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJump(PlayerMoveEvent event) {
|
||||
if ((!event.getPlayer().isFlying()) && (event.getPlayer().getGameMode() != GameMode.CREATIVE) && (event.getFrom().getY() + 0.5D != event.getTo().getY()) && (event.getFrom().getY() + 0.419D < event.getTo().getY())) {
|
||||
Location loc = event.getFrom();
|
||||
loc.setY(event.getFrom().getY() - 1.0D);
|
||||
if (loc.getBlock().getType() != Material.AIR) {
|
||||
if (!this.cooldown.containsKey(event.getPlayer())) {
|
||||
this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L);
|
||||
PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(evt);
|
||||
if (evt.isCancelled()) {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
} else if (this.cooldown.get(event.getPlayer()) <= System.currentTimeMillis()) {
|
||||
this.cooldown.put(event.getPlayer(), System.currentTimeMillis() + 350L);
|
||||
PlayerJumpEvent evt = new PlayerJumpEvent(event.isCancelled(), event.getPlayer());
|
||||
Bukkit.getPluginManager().callEvent(evt);
|
||||
if (evt.isCancelled()) {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onJump(PlayerMoveEvent e) {
|
||||
// 不是飞行
|
||||
if (!e.getPlayer().isFlying()
|
||||
// 生存或冒险模式
|
||||
&& (e.getPlayer().getGameMode() == GameMode.SURVIVAL || e.getPlayer().getGameMode() == GameMode.ADVENTURE)
|
||||
// 坐标计算
|
||||
&& (e.getFrom().getY() + 0.5D != e.getTo().getY())
|
||||
&& (e.getFrom().getY() + 0.419D < e.getTo().getY())
|
||||
// 不在冷却
|
||||
&& !cooldown.isCooldown(e.getPlayer().getName())) {
|
||||
|
||||
PlayerJumpEvent event = new PlayerJumpEvent(e.getPlayer()).call();
|
||||
if (event.isCancelled()) {
|
||||
// 返回位置
|
||||
e.setTo(e.getFrom());
|
||||
// 重置冷却
|
||||
cooldown.reset(e.getPlayer().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
this.cooldown.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ import java.util.stream.Collectors;
|
||||
* @Author sky
|
||||
* @Since 2018-05-23 2:43
|
||||
*/
|
||||
@TFunction(enable = "init")
|
||||
public class TCommandHandler {
|
||||
|
||||
private static SimpleCommandMap commandMap;
|
||||
private static Map<String, Command> knownCommands;
|
||||
|
||||
@TFunction.Init
|
||||
static void init() {
|
||||
SimpleReflection.saveField(SimplePluginManager.class, "commandMap");
|
||||
SimpleReflection.saveField(SimpleCommandMap.class, "knownCommands");
|
||||
|
@ -14,6 +14,24 @@ import java.lang.annotation.Target;
|
||||
public @interface TFunction {
|
||||
|
||||
String enable() default "onEnable";
|
||||
|
||||
String disable() default "onDisable";
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Load {
|
||||
|
||||
}
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Init {
|
||||
|
||||
}
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Cancel {
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package io.izzel.taboolib.module.inject;
|
||||
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.TabooLibLoader;
|
||||
import io.izzel.taboolib.module.locale.logger.TLogger;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
@ -14,44 +14,54 @@ import java.lang.reflect.Modifier;
|
||||
*/
|
||||
public class TFunctionLoader implements TabooLibLoader.Loader {
|
||||
|
||||
@Override
|
||||
public void preLoad(Plugin plugin, Class<?> pluginClass) {
|
||||
invokeMethods(pluginClass, TFunction.Load.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLoad(Plugin plugin, Class<?> pluginClass) {
|
||||
invokeMethods(pluginClass, true);
|
||||
invokeMethods(pluginClass, TFunction.Init.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(Plugin plugin, Class<?> pluginClass) {
|
||||
invokeMethods(pluginClass, false);
|
||||
invokeMethods(pluginClass, TFunction.Cancel.class);
|
||||
}
|
||||
|
||||
public void invokeMethods(Class<?> pluginClass, boolean enable) {
|
||||
if (pluginClass.isAnnotationPresent(TFunction.class)) {
|
||||
TFunction function = pluginClass.getAnnotation(TFunction.class);
|
||||
try {
|
||||
Method method = pluginClass.getDeclaredMethod(function.enable());
|
||||
Method method = pluginClass.getDeclaredMethod(enable ? function.enable() : function.disable());
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
TLogger.getGlobalLogger().error(method.getName() + " is not a static method.");
|
||||
return;
|
||||
}
|
||||
method.setAccessible(true);
|
||||
method.invoke(null);
|
||||
TabooLibAPI.debug("Function " + pluginClass.getSimpleName() + " loaded. (" + plugin.getName() + ")");
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
} catch (Exception e) {
|
||||
TLogger.getGlobalLogger().warn("TFunction load Failed: " + pluginClass.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(Plugin plugin, Class<?> pluginClass) {
|
||||
if (pluginClass.isAnnotationPresent(TFunction.class)) {
|
||||
TFunction function = pluginClass.getAnnotation(TFunction.class);
|
||||
try {
|
||||
Method method = pluginClass.getDeclaredMethod(function.disable());
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
TLogger.getGlobalLogger().error(method.getName() + " is not a static method.");
|
||||
return;
|
||||
public void invokeMethods(Class<?> pluginClass, Class<? extends Annotation> a) {
|
||||
for (Method declaredMethod : pluginClass.getDeclaredMethods()) {
|
||||
if (declaredMethod.isAnnotationPresent(a)) {
|
||||
try {
|
||||
if (!Modifier.isStatic(declaredMethod.getModifiers())) {
|
||||
TLogger.getGlobalLogger().error(declaredMethod.getName() + " is not a static method.");
|
||||
return;
|
||||
}
|
||||
declaredMethod.setAccessible(true);
|
||||
declaredMethod.invoke(null);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
method.setAccessible(true);
|
||||
method.invoke(null);
|
||||
TabooLibAPI.debug("Function " + pluginClass.getSimpleName() + " unloaded. (" + plugin.getName() + ")");
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
} catch (Exception e) {
|
||||
TLogger.getGlobalLogger().warn("TFunction unload Failed: " + pluginClass.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ import io.izzel.taboolib.module.packet.TPacketHandler;
|
||||
import io.izzel.taboolib.module.packet.TPacketListener;
|
||||
import io.izzel.taboolib.util.lite.cooldown.Cooldown;
|
||||
import io.izzel.taboolib.util.lite.cooldown.Cooldowns;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@ -66,6 +68,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
||||
}
|
||||
});
|
||||
TabooLibLoader.runTask(config::runListener);
|
||||
} catch (NoSuchMethodException ignore) {
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@ -97,6 +100,26 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
// PluginExists Inject
|
||||
injectTypes.put(Boolean.TYPE, (plugin, field, args, pluginClass, instance) -> {
|
||||
try {
|
||||
if (args.value().length > 0) {
|
||||
field.set(instance, Bukkit.getPluginManager().getPlugin(args.value()[0]) != null);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
// PluginHook Inject
|
||||
injectTypes.put(JavaPlugin.class, (plugin, field, args, pluginClass, instance) -> {
|
||||
try {
|
||||
if (args.value().length > 0) {
|
||||
field.set(instance, Bukkit.getPluginManager().getPlugin(args.value()[0]));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,12 +23,12 @@ import java.util.Optional;
|
||||
* @Author 坏黑
|
||||
* @Since 2019-05-22 1:16
|
||||
*/
|
||||
@TFunction(enable = "init")
|
||||
public class SimpleI18n {
|
||||
|
||||
private static FileConfiguration lang;
|
||||
private static boolean released;
|
||||
|
||||
@TFunction.Init
|
||||
static void init() {
|
||||
File localeFile = getLocaleFile(TabooLib.getPlugin());
|
||||
if (localeFile == null) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.izzel.taboolib.util.lite;
|
||||
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import io.izzel.taboolib.module.locale.logger.TLogger;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
@ -14,12 +14,12 @@ import java.util.Objects;
|
||||
* @Author sky
|
||||
* @Since 2018-06-02 22:48
|
||||
*/
|
||||
@TFunction(enable = "init")
|
||||
public class Scripts {
|
||||
|
||||
private static ScriptEngine scriptEngine;
|
||||
private static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
|
||||
|
||||
@TFunction.Init
|
||||
static void init() {
|
||||
try {
|
||||
NashornScriptEngineFactory factory = (NashornScriptEngineFactory) scriptEngineManager.getEngineFactories().stream().filter(factories -> "Oracle Nashorn".equalsIgnoreCase(factories.getEngineName())).findFirst().orElse(null);
|
||||
|
@ -69,4 +69,8 @@ public class Cooldown {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reset(String player) {
|
||||
data.remove(player);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.izzel.taboolib.util.tag;
|
||||
|
||||
import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -20,7 +19,6 @@ import java.util.UUID;
|
||||
* @Author sky
|
||||
* @Since 2018-05-23 0:37
|
||||
*/
|
||||
@TFunction(enable = "init")
|
||||
@TListener
|
||||
public class TagDataHandler implements Listener {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user