Search in sources :

Example 1 with PluginManager

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;
}
Also used : SimpleCommandMap(org.bukkit.command.SimpleCommandMap) PluginManager(org.bukkit.plugin.PluginManager) Field(java.lang.reflect.Field) PluginCommand(org.bukkit.command.PluginCommand) Command(org.bukkit.command.Command) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) SimpleCommandMap(org.bukkit.command.SimpleCommandMap) Plugin(org.bukkit.plugin.Plugin) PluginCommand(org.bukkit.command.PluginCommand)

Example 2 with PluginManager

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);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 3 with PluginManager

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);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) IEssentials(net.ess3.api.IEssentials) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent)

Example 4 with PluginManager

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);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 5 with PluginManager

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");
    }
}
Also used : PluginManager(org.bukkit.plugin.PluginManager)

Aggregations

PluginManager (org.bukkit.plugin.PluginManager)68 Plugin (org.bukkit.plugin.Plugin)13 Test (org.junit.Test)13 Permission (org.bukkit.permissions.Permission)8 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)7 Map (java.util.Map)5 World (org.bukkit.World)5 Player (org.bukkit.entity.Player)5 Listener (org.bukkit.event.Listener)5 SimplePluginManager (org.bukkit.plugin.SimplePluginManager)5 IEssentials (net.ess3.api.IEssentials)4 Event (org.bukkit.event.Event)4 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)4 Location (org.bukkit.Location)3 EventHandler (org.bukkit.event.EventHandler)3 Essentials (com.earth2me.essentials.Essentials)2 Metrics (com.earth2me.essentials.metrics.Metrics)2 PermissionsHandler (com.earth2me.essentials.perm.PermissionsHandler)2 SignBlockListener (com.earth2me.essentials.signs.SignBlockListener)2 SignEntityListener (com.earth2me.essentials.signs.SignEntityListener)2