use of org.bukkit.plugin.PluginManager in project SpaciousLib by anhcraft.
the class SPlugin method unloadPlugin.
public static boolean unloadPlugin(Plugin plugin) throws NoSuchFieldException, IllegalAccessException, IOException {
String name = plugin.getName();
PluginManager pluginManager = Bukkit.getPluginManager();
SimpleCommandMap commandMap = null;
List<Plugin> plugins = null;
Map<String, Plugin> names = null;
Map<String, Command> commands = null;
disablePlugin(plugin);
if (pluginManager != null) {
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
Field commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
Field commandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
commandsField.setAccessible(true);
pluginsField.setAccessible(true);
commandMapField.setAccessible(true);
lookupNamesField.setAccessible(true);
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
commands = (Map<String, Command>) commandsField.get(commandMap);
plugins = (List<Plugin>) pluginsField.get(pluginManager);
names = (Map<String, Plugin>) lookupNamesField.get(pluginManager);
}
if (plugins != null && plugins.contains(plugin)) {
plugins.remove(plugin);
}
if (names != null && names.containsKey(name)) {
names.remove(name);
}
if (commandMap != null) {
for (Iterator<Map.Entry<String, Command>> it = commands.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, Command> entry = it.next();
if (entry.getValue() instanceof PluginCommand) {
PluginCommand c = (PluginCommand) entry.getValue();
if (c.getPlugin() == plugin) {
c.unregister(commandMap);
it.remove();
}
}
}
}
ClassLoader cl = plugin.getClass().getClassLoader();
if (cl instanceof URLClassLoader) {
((URLClassLoader) cl).close();
}
System.gc();
return true;
}
use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.
the class EssentialsProtect method onEnable.
@Override
public void onEnable() {
final PluginManager pm = this.getServer().getPluginManager();
final Plugin essPlugin = pm.getPlugin("Essentials");
if (essPlugin == null || !essPlugin.isEnabled()) {
enableEmergencyMode(pm);
return;
}
ess = new EssentialsConnect(essPlugin, this);
final EssentialsProtectBlockListener blockListener = new EssentialsProtectBlockListener(this);
pm.registerEvents(blockListener, this);
final EssentialsProtectEntityListener entityListener = new EssentialsProtectEntityListener(this);
pm.registerEvents(entityListener, this);
final EssentialsProtectWeatherListener weatherListener = new EssentialsProtectWeatherListener(this);
pm.registerEvents(weatherListener, this);
}
use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.
the class EssentialsChat method onEnable.
@Override
public void onEnable() {
final PluginManager pluginManager = getServer().getPluginManager();
final IEssentials ess = (IEssentials) pluginManager.getPlugin("Essentials");
if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
LOGGER.log(Level.WARNING, tl("versionMismatchAll"));
}
if (!ess.isEnabled()) {
this.setEnabled(false);
return;
}
final Map<AsyncPlayerChatEvent, ChatStore> chatStore = Collections.synchronizedMap(new HashMap<AsyncPlayerChatEvent, ChatStore>());
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore);
final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore);
final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore);
pluginManager.registerEvents(playerListenerLowest, this);
pluginManager.registerEvents(playerListenerNormal, this);
pluginManager.registerEvents(playerListenerHighest, this);
}
use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.
the class EssentialsAntiBuild method onEnable.
@Override
public void onEnable() {
final PluginManager pm = this.getServer().getPluginManager();
final Plugin essPlugin = pm.getPlugin("Essentials");
if (essPlugin == null || !essPlugin.isEnabled()) {
return;
}
ess = new EssentialsConnect(essPlugin, this);
final EssentialsAntiBuildListener blockListener = new EssentialsAntiBuildListener(this);
pm.registerEvents(blockListener, this);
}
use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.
the class Jails method registerListeners.
private void registerListeners() {
enabled = true;
final PluginManager pluginManager = ess.getServer().getPluginManager();
final JailListener blockListener = new JailListener();
pluginManager.registerEvents(blockListener, ess);
if (ess.getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Registering Jail listener");
}
}
Aggregations