自动注册扫描仅对依赖 TabooLib 的插件有效
修复一个丢了的类
This commit is contained in:
parent
1e50bd526b
commit
2ffb1ce886
@ -1,6 +1,7 @@
|
|||||||
package me.skymc.taboolib.commands.internal;
|
package me.skymc.taboolib.commands.internal;
|
||||||
|
|
||||||
import com.ilummc.tlib.resources.TLocale;
|
import com.ilummc.tlib.resources.TLocale;
|
||||||
|
import me.skymc.taboolib.TabooLib;
|
||||||
import me.skymc.taboolib.fileutils.FileUtils;
|
import me.skymc.taboolib.fileutils.FileUtils;
|
||||||
import me.skymc.taboolib.listener.TListener;
|
import me.skymc.taboolib.listener.TListener;
|
||||||
import me.skymc.taboolib.methods.ReflectionUtils;
|
import me.skymc.taboolib.methods.ReflectionUtils;
|
||||||
@ -133,6 +134,7 @@ public class TCommandHandler implements Listener {
|
|||||||
*/
|
*/
|
||||||
public static void registerCommands() {
|
public static void registerCommands() {
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
if (plugin.equals(TabooLib.instance()) || plugin.getDescription().getDepend().contains("TabooLib")) {
|
||||||
try {
|
try {
|
||||||
registerCommand(plugin);
|
registerCommand(plugin);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -140,6 +142,7 @@ public class TCommandHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册插件的所有 TCommand 命令
|
* 注册插件的所有 TCommand 命令
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.skymc.taboolib.listener;
|
package me.skymc.taboolib.listener;
|
||||||
|
|
||||||
import com.ilummc.tlib.util.Ref;
|
|
||||||
import com.ilummc.tlib.util.Strings;
|
import com.ilummc.tlib.util.Strings;
|
||||||
|
import me.skymc.taboolib.TabooLib;
|
||||||
import me.skymc.taboolib.fileutils.FileUtils;
|
import me.skymc.taboolib.fileutils.FileUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -11,7 +11,6 @@ import org.bukkit.event.server.PluginDisableEvent;
|
|||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -29,6 +28,7 @@ public class TListenerHandler implements Listener {
|
|||||||
*/
|
*/
|
||||||
public static void setupListeners() {
|
public static void setupListeners() {
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
if (plugin.equals(TabooLib.instance()) || plugin.getDescription().getDepend().contains("TabooLib")) {
|
||||||
try {
|
try {
|
||||||
setupListener(plugin);
|
setupListener(plugin);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -36,6 +36,7 @@ public class TListenerHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化插件的所有监听器
|
* 初始化插件的所有监听器
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package me.skymc.taboolib.socket.packet;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import me.skymc.taboolib.fileutils.FileUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author sky
|
||||||
|
* @Since 2018-08-22 23:07
|
||||||
|
*/
|
||||||
|
public class PacketParser {
|
||||||
|
|
||||||
|
private List<Class<?>> packets = new ArrayList<>();
|
||||||
|
|
||||||
|
public PacketParser() {
|
||||||
|
FileUtils.getClasses(PacketParser.class).stream().filter(clazz -> clazz.isAnnotationPresent(PacketType.class)).forEach(clazz -> packets.add(clazz));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet parser(JsonObject json) {
|
||||||
|
if (!json.has("packet")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String packetType = json.get("packet").getAsString();
|
||||||
|
Optional<Class<?>> packetFind = packets.stream().filter(packet -> packet.getAnnotation(PacketType.class).name().equals(packetType)).findFirst();
|
||||||
|
if (!packetFind.isPresent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Packet packetObject = (Packet) packetFind.get().getConstructor(Integer.TYPE).newInstance(json.get("port").getAsInt());
|
||||||
|
packetObject.unSerialize(json);
|
||||||
|
return packetObject;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// *********************************
|
||||||
|
//
|
||||||
|
// Getter and Setter
|
||||||
|
//
|
||||||
|
// *********************************
|
||||||
|
|
||||||
|
public List<Class<?>> getPackets() {
|
||||||
|
return packets;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user