-
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract class sources (plugin/mod names) and include in data payload
- Loading branch information
Showing
32 changed files
with
684 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitClassSourceLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.bukkit; | ||
|
||
import me.lucko.spark.common.util.ClassSourceLookup; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public class BukkitClassSourceLookup extends ClassSourceLookup.ByClassLoader { | ||
private static final Class<?> PLUGIN_CLASS_LOADER; | ||
private static final Method GET_PLUGIN_METHOD; | ||
|
||
static { | ||
try { | ||
PLUGIN_CLASS_LOADER = Class.forName("org.bukkit.plugin.java.PluginClassLoader"); | ||
GET_PLUGIN_METHOD = PLUGIN_CLASS_LOADER.getDeclaredMethod("getPlugin"); | ||
GET_PLUGIN_METHOD.setAccessible(true); | ||
} catch (ReflectiveOperationException e) { | ||
throw new ExceptionInInitializerError(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String identify(ClassLoader loader) throws ReflectiveOperationException { | ||
if (PLUGIN_CLASS_LOADER.isInstance(loader)) { | ||
JavaPlugin plugin = (JavaPlugin) GET_PLUGIN_METHOD.invoke(loader); | ||
return plugin.getName(); | ||
} | ||
return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
spark-bungeecord/src/main/java/me/lucko/spark/bungeecord/BungeeCordClassSourceLookup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.