diff options
Diffstat (limited to 'spark-bungeecord')
-rw-r--r-- | spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordClassSourceLookup.java | 52 | ||||
-rw-r--r-- | spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordSparkPlugin.java | 6 |
2 files changed, 58 insertions, 0 deletions
diff --git a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordClassSourceLookup.java b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordClassSourceLookup.java new file mode 100644 index 0000000..e601f87 --- /dev/null +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordClassSourceLookup.java @@ -0,0 +1,52 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) <luck@lucko.me> + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package me.lucko.spark.bungeecord; + +import me.lucko.spark.common.util.ClassSourceLookup; + +import net.md_5.bungee.api.plugin.PluginDescription; + +import java.lang.reflect.Field; + +public class BungeeCordClassSourceLookup extends ClassSourceLookup.ByClassLoader { + private static final Class<?> PLUGIN_CLASS_LOADER; + private static final Field DESC_FIELD; + + static { + try { + PLUGIN_CLASS_LOADER = Class.forName("net.md_5.bungee.api.plugin.PluginClassloader"); + DESC_FIELD = PLUGIN_CLASS_LOADER.getDeclaredField("desc"); + DESC_FIELD.setAccessible(true); + } catch (ReflectiveOperationException e) { + throw new ExceptionInInitializerError(e); + } + } + + @Override + public String identify(ClassLoader loader) throws ReflectiveOperationException { + if (PLUGIN_CLASS_LOADER.isInstance(loader)) { + PluginDescription desc = (PluginDescription) DESC_FIELD.get(loader); + return desc.getName(); + } + return null; + } +} + diff --git a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordSparkPlugin.java b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordSparkPlugin.java index 357c457..2fb44c3 100644 --- a/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordSparkPlugin.java +++ b/spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordSparkPlugin.java @@ -23,6 +23,7 @@ package me.lucko.spark.bungeecord; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; import me.lucko.spark.common.platform.PlatformInfo; +import me.lucko.spark.common.util.ClassSourceLookup; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.md_5.bungee.api.CommandSender; @@ -79,6 +80,11 @@ public class BungeeCordSparkPlugin extends Plugin implements SparkPlugin { } @Override + public ClassSourceLookup createClassSourceLookup() { + return new BungeeCordClassSourceLookup(); + } + + @Override public PlatformInfo getPlatformInfo() { return new BungeeCordPlatformInfo(getProxy()); } |