Search in sources :

Example 6 with PluginManager

use of org.bukkit.plugin.PluginManager in project AuthMeReloaded by AuthMe.

the class PluginHookServiceTest method shouldUnhookEssentialsAndMultiverse.

@Test
public void shouldUnhookEssentialsAndMultiverse() {
    // given
    PluginManager pluginManager = mock(PluginManager.class);
    setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
    setPluginAvailable(pluginManager, MULTIVERSE, MultiverseCore.class);
    PluginHookService pluginHookService = new PluginHookService(pluginManager);
    // when
    pluginHookService.unhookEssentials();
    pluginHookService.unhookMultiverse();
    // then
    assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
    assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Test(org.junit.Test)

Example 7 with PluginManager

use of org.bukkit.plugin.PluginManager in project AuthMeReloaded by AuthMe.

the class PluginHookServiceTest method shouldReturnNullForUnavailableMultiverse.

@Test
public void shouldReturnNullForUnavailableMultiverse() {
    // given
    PluginManager pluginManager = mock(PluginManager.class);
    PluginHookService pluginHookService = new PluginHookService(pluginManager);
    World world = mock(World.class);
    // when
    Location result = pluginHookService.getMultiverseSpawn(world);
    // then
    assertThat(result, nullValue());
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) World(org.bukkit.World) MultiverseWorld(com.onarandombox.MultiverseCore.api.MultiverseWorld) Location(org.bukkit.Location) Test(org.junit.Test)

Example 8 with PluginManager

use of org.bukkit.plugin.PluginManager in project Jobs by GamingMesh.

the class JobsListener method onWorldLoad.

@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoad(WorldLoadEvent event) {
    World world = event.getWorld();
    PluginManager pm = plugin.getServer().getPluginManager();
    if (pm.getPermission("jobs.world." + world.getName().toLowerCase()) == null)
        pm.addPermission(new Permission("jobs.world." + world.getName().toLowerCase(), PermissionDefault.TRUE));
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Permission(org.bukkit.permissions.Permission) World(org.bukkit.World) EventHandler(org.bukkit.event.EventHandler)

Example 9 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 10 with PluginManager

use of org.bukkit.plugin.PluginManager in project Essentials by drtshock.

the class EssentialsGeoIP method onEnable.

@Override
public void onEnable() {
    final PluginManager pm = getServer().getPluginManager();
    final IEssentials ess = (IEssentials) pm.getPlugin("Essentials");
    if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) {
        getLogger().log(Level.WARNING, tl("versionMismatchAll"));
    }
    if (!ess.isEnabled()) {
        this.setEnabled(false);
        return;
    }
    final EssentialsGeoIPPlayerListener playerListener = new EssentialsGeoIPPlayerListener(getDataFolder(), ess);
    pm.registerEvents(playerListener, this);
    getLogger().log(Level.INFO, "This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com/.");
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) IEssentials(net.ess3.api.IEssentials)

Aggregations

PluginManager (org.bukkit.plugin.PluginManager)30 Test (org.junit.Test)12 World (org.bukkit.World)5 Plugin (org.bukkit.plugin.Plugin)5 MultiverseWorld (com.onarandombox.MultiverseCore.api.MultiverseWorld)3 Location (org.bukkit.Location)3 Listener (org.bukkit.event.Listener)3 Essentials (com.earth2me.essentials.Essentials)2 MultiverseCore (com.onarandombox.MultiverseCore.MultiverseCore)2 MVWorldManager (com.onarandombox.MultiverseCore.api.MVWorldManager)2 File (java.io.File)2 Method (java.lang.reflect.Method)2 IEssentials (net.ess3.api.IEssentials)2 Player (org.bukkit.entity.Player)2 Event (org.bukkit.event.Event)2 EventException (org.bukkit.event.EventException)2 EventHandler (org.bukkit.event.EventHandler)2 PlayerJoinEvent (org.bukkit.event.player.PlayerJoinEvent)2 EventExecutor (org.bukkit.plugin.EventExecutor)2 JavaPlugin (org.bukkit.plugin.java.JavaPlugin)2