use of org.bukkit.plugin.SimplePluginManager in project LuckPerms by lucko.
the class InjectorSubscriptionMap method inject.
private LPSubscriptionMap inject() throws Exception {
Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
if (!(pluginManager instanceof SimplePluginManager)) {
this.plugin.getLogger().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
this.plugin.getLogger().severe("Unable to inject LuckPerms Permission Subscription map.");
return null;
}
Object map = PERM_SUBS_FIELD.get(pluginManager);
if (map instanceof LPSubscriptionMap) {
if (((LPSubscriptionMap) map).plugin == this.plugin) {
return null;
}
map = ((LPSubscriptionMap) map).detach();
}
// noinspection unchecked
Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
// make a new subscription map & inject it
LPSubscriptionMap newMap = new LPSubscriptionMap(this.plugin, castedMap);
PERM_SUBS_FIELD.set(pluginManager, newMap);
return newMap;
}
use of org.bukkit.plugin.SimplePluginManager in project DiscordBot by LXGaming.
the class CommandManager method getCommandMap.
private CommandMap getCommandMap() {
if (!(Bukkit.getPluginManager() instanceof SimplePluginManager)) {
return null;
}
try {
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
return (CommandMap) field.get(Bukkit.getPluginManager());
} catch (IllegalAccessException | IllegalArgumentException | NoSuchFieldException | SecurityException ex) {
DiscordBot.getInstance().getLogger().severe("Exception getting commandMap!");
ex.printStackTrace();
}
return null;
}
use of org.bukkit.plugin.SimplePluginManager in project SpaciousLib by anhcraft.
the class CommandManager method register.
/**
* Registers a command of a Bukkit plugin
* @param plugin the plugin which owned that command
* @param command the command
*/
public static void register(JavaPlugin plugin, PluginCommand command) {
try {
Class<?> craftServerClass = Class.forName("org.bukkit.craftbukkit." + GameVersion.getVersion().toString() + ".CraftServer");
Object craftServer = craftServerClass.cast(Bukkit.getServer());
Field commandMapField = craftServerClass.getDeclaredField("commandMap");
commandMapField.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) commandMapField.get(craftServer);
commandMap.register(plugin.getDescription().getName(), command);
commandMapField.set(craftServer, commandMap);
Field simplePluginManagerField = craftServerClass.getDeclaredField("pluginManager");
simplePluginManagerField.setAccessible(true);
SimplePluginManager simplePluginManager = (SimplePluginManager) simplePluginManagerField.get(craftServer);
Field commandMapPluginManagerField = SimplePluginManager.class.getDeclaredField("commandMap");
commandMapPluginManagerField.setAccessible(true);
SimpleCommandMap commandPluginManagerMap = (SimpleCommandMap) commandMapPluginManagerField.get(simplePluginManager);
commandPluginManagerMap.register(plugin.getDescription().getName(), command);
commandMapPluginManagerField.set(simplePluginManager, commandPluginManagerMap);
simplePluginManagerField.set(craftServer, simplePluginManager);
} catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
e.printStackTrace();
}
}
use of org.bukkit.plugin.SimplePluginManager in project LuckPerms by lucko.
the class InjectorPermissionMap method inject.
private LPPermissionMap inject() throws Exception {
Objects.requireNonNull(PERMISSIONS_FIELD, "PERMISSIONS_FIELD");
PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
if (!(pluginManager instanceof SimplePluginManager)) {
this.plugin.getLogger().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
this.plugin.getLogger().severe("Unable to inject LuckPerms Permission map.");
return null;
}
Object map = PERMISSIONS_FIELD.get(pluginManager);
if (map instanceof LPPermissionMap && ((LPPermissionMap) map).plugin == this.plugin) {
return null;
}
// noinspection unchecked
Map<String, Permission> castedMap = (Map<String, Permission>) map;
// make a new map & inject it
LPPermissionMap newMap = new LPPermissionMap(this.plugin, castedMap);
PERMISSIONS_FIELD.set(pluginManager, newMap);
return newMap;
}
Aggregations