Search in sources :

Example 21 with PluginManager

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

the class PluginHookServiceTest method shouldReturnNullForNonMvWorld.

@Test
public void shouldReturnNullForNonMvWorld() {
    // given
    World world = mock(World.class);
    MVWorldManager mvWorldManager = mock(MVWorldManager.class);
    given(mvWorldManager.isMVWorld(world)).willReturn(false);
    PluginManager pluginManager = mock(PluginManager.class);
    MultiverseCore multiverse = mock(MultiverseCore.class);
    setPluginAvailable(pluginManager, MULTIVERSE, multiverse);
    given(multiverse.getMVWorldManager()).willReturn(mvWorldManager);
    PluginHookService pluginHookService = new PluginHookService(pluginManager);
    // when
    Location spawn = pluginHookService.getMultiverseSpawn(world);
    // then
    assertThat(spawn, nullValue());
    verify(mvWorldManager).isMVWorld(world);
    verify(mvWorldManager, never()).getMVWorld(world);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) MultiverseCore(com.onarandombox.MultiverseCore.MultiverseCore) MVWorldManager(com.onarandombox.MultiverseCore.api.MVWorldManager) World(org.bukkit.World) MultiverseWorld(com.onarandombox.MultiverseCore.api.MultiverseWorld) Location(org.bukkit.Location) Test(org.junit.Test)

Example 22 with PluginManager

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

the class PluginHookServiceTest method shouldHookIntoEssentials.

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

Example 23 with PluginManager

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

the class PluginHookServiceTest method shouldHandlePluginRetrievalError.

@Test
public void shouldHandlePluginRetrievalError() {
    // given
    PluginManager pluginManager = mock(PluginManager.class);
    given(pluginManager.isPluginEnabled(anyString())).willReturn(true);
    doThrow(IllegalStateException.class).when(pluginManager).getPlugin(anyString());
    // when
    PluginHookService pluginHookService = new PluginHookService(pluginManager);
    // then
    assertThat(pluginHookService.isEssentialsAvailable(), equalTo(false));
    assertThat(pluginHookService.isMultiverseAvailable(), equalTo(false));
    assertThat(pluginHookService.isCombatTagPlusAvailable(), equalTo(false));
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Test(org.junit.Test)

Example 24 with PluginManager

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

the class PluginHookServiceTest method shouldHookIntoEssentialsAtInitialization.

// Note ljacqu 20160312: Cannot test with CombatTagPlus because its class is declared final
@Test
public void shouldHookIntoEssentialsAtInitialization() {
    // given
    PluginManager pluginManager = mock(PluginManager.class);
    setPluginAvailable(pluginManager, ESSENTIALS, Essentials.class);
    // when
    PluginHookService pluginHookService = new PluginHookService(pluginManager);
    // then
    assertThat(pluginHookService.isEssentialsAvailable(), equalTo(true));
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Test(org.junit.Test)

Example 25 with PluginManager

use of org.bukkit.plugin.PluginManager in project TotalFreedomMod by TotalFreedom.

the class Command_plugincontrol method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length == 0 || args.length > 2) {
        return false;
    }
    final PluginManager pm = server.getPluginManager();
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("list")) {
            for (Plugin serverPlugin : pm.getPlugins()) {
                final String version = serverPlugin.getDescription().getVersion();
                msg(ChatColor.GRAY + "- " + (serverPlugin.isEnabled() ? ChatColor.GREEN : ChatColor.RED) + serverPlugin.getName() + ChatColor.GOLD + (version != null && !version.isEmpty() ? " v" + version : "") + " by " + StringUtils.join(serverPlugin.getDescription().getAuthors(), ", "));
            }
            return true;
        }
        return false;
    }
    if ("enable".equals(args[0])) {
        final Plugin target = getPlugin(args[1]);
        if (target == null) {
            msg("Plugin not found!");
            return true;
        }
        if (target.isEnabled()) {
            msg("Plugin is already enabled.");
            return true;
        }
        pm.enablePlugin(target);
        if (!pm.isPluginEnabled(target)) {
            msg("Error enabling plugin " + target.getName());
            return true;
        }
        msg(target.getName() + " is now enabled.");
        return true;
    }
    if ("disable".equals(args[0])) {
        final Plugin target = getPlugin(args[1]);
        if (target == null) {
            msg("Plugin not found!");
            return true;
        }
        if (!target.isEnabled()) {
            msg("Plugin is already disabled.");
            return true;
        }
        if (target.getName().equals(plugin.getName())) {
            msg("You cannot disable " + plugin.getName());
            return true;
        }
        pm.disablePlugin(target);
        if (pm.isPluginEnabled(target)) {
            msg("Error disabling plugin " + target.getName());
            return true;
        }
        msg(target.getName() + " is now disabled.");
        return true;
    }
    if ("reload".equals(args[0])) {
        final Plugin target = getPlugin(args[1]);
        if (target == null) {
            msg("Plugin not found!");
            return true;
        }
        if (target.getName().equals(plugin.getName())) {
            msg("Use /tfm reload to reload instead.");
            return true;
        }
        pm.disablePlugin(target);
        pm.enablePlugin(target);
        msg(target.getName() + " reloaded.");
        return true;
    }
    return false;
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) Plugin(org.bukkit.plugin.Plugin)

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