Search in sources :

Example 26 with PluginManager

use of org.bukkit.plugin.PluginManager in project Glowstone by GlowstoneMC.

the class QueryTest method testFullStats.

@Test
public void testFullStats() throws Exception {
    World world = mock(World.class);
    when(world.getName()).thenReturn("world");
    GlowPlayer p1 = mock(GlowPlayer.class);
    GlowPlayer p2 = mock(GlowPlayer.class);
    when(p1.getName()).thenReturn("barneygale");
    when(p2.getName()).thenReturn("Vivalahelvig");
    PluginManager pluginManager = mock(PluginManager.class);
    when(glowServer.getMotd()).thenReturn("A Minecraft Server");
    Mockito.doReturn(Arrays.asList(p1, p2)).when(glowServer).getOnlinePlayers();
    when(glowServer.getMaxPlayers()).thenReturn(20);
    when(glowServer.getPort()).thenReturn(25565);
    when(glowServer.getWorlds()).thenReturn(Arrays.asList(world));
    when(glowServer.getIp()).thenReturn("");
    when(glowServer.getVersion()).thenReturn("123");
    when(glowServer.getBukkitVersion()).thenReturn("xyz");
    when(glowServer.getPluginManager()).thenReturn(pluginManager);
    when(pluginManager.getPlugins()).thenReturn(new Plugin[0]);
    QueryHandler handler = new QueryHandler(server, queryPlugins);
    when(random.nextInt()).thenReturn(9513307);
    server.generateChallengeToken(address);
    testChannelRead(handler, FULL_STATS_RECV, FULL_STATS_SEND);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) QueryHandler(net.glowstone.net.query.QueryHandler) GlowPlayer(net.glowstone.entity.GlowPlayer) World(org.bukkit.World) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with PluginManager

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

the class EssentialsXMPP method onEnable.

@Override
public void onEnable() {
    instance = this;
    final PluginManager pluginManager = getServer().getPluginManager();
    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 EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess);
    pluginManager.registerEvents(playerListener, this);
    users = new UserManager(this.getDataFolder());
    xmpp = new XMPPManager(this);
    ess.addReloadListener(users);
    ess.addReloadListener(xmpp);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager)

Example 28 with PluginManager

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

the class Essentials method onEnable.

@Override
public void onEnable() {
    try {
        LOGGER.setParent(this.getLogger());
        execTimer = new ExecuteTimer();
        execTimer.start();
        i18n = new I18n(this);
        i18n.onEnable();
        execTimer.mark("I18n1");
        Console.setInstance(this);
        final PluginManager pm = getServer().getPluginManager();
        for (Plugin plugin : pm.getPlugins()) {
            if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) {
                getLogger().warning(tl("versionMismatch", plugin.getDescription().getName()));
            }
        }
        for (Method method : Server.class.getDeclaredMethods()) {
            if (method.getName().endsWith("getOnlinePlayers") && method.getReturnType() == Player[].class) {
                oldGetOnlinePlayers = method;
                break;
            }
        }
        forceLoadClasses();
        try {
            final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
            upgrade.beforeSettings();
            execTimer.mark("Upgrade");
            confList = new ArrayList<>();
            settings = new Settings(this);
            confList.add(settings);
            execTimer.mark("Settings");
            userMap = new UserMap(this);
            confList.add(userMap);
            execTimer.mark("Init(Usermap)");
            upgrade.afterSettings();
            execTimer.mark("Upgrade2");
            warps = new Warps(getServer(), this.getDataFolder());
            confList.add(warps);
            execTimer.mark("Init(Spawn/Warp)");
            worth = new Worth(this.getDataFolder());
            confList.add(worth);
            itemDb = new ItemDb(this);
            confList.add(itemDb);
            execTimer.mark("Init(Worth/ItemDB)");
            jails = new Jails(this);
            confList.add(jails);
            spawnerProvider = new ProviderFactory<>(getLogger(), Arrays.asList(BlockMetaSpawnerProvider.class, v1_8_R2SpawnerProvider.class, v1_8_R1SpawnerProvider.class, LegacySpawnerProvider.class), "mob spawner").getProvider();
            spawnEggProvider = new ProviderFactory<>(getLogger(), Arrays.asList(ReflSpawnEggProvider.class, LegacySpawnEggProvider.class), "spawn egg").getProvider();
            potionMetaProvider = new ProviderFactory<>(getLogger(), Arrays.asList(BasePotionDataProvider.class, LegacyPotionMetaProvider.class), "potion meta").getProvider();
            reload();
        } catch (YAMLException exception) {
            if (pm.getPlugin("EssentialsUpdate") != null) {
                LOGGER.log(Level.SEVERE, tl("essentialsHelp2"));
            } else {
                LOGGER.log(Level.SEVERE, tl("essentialsHelp1"));
            }
            handleCrash(exception);
            return;
        }
        backup = new Backup(this);
        permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
        alternativeCommandsHandler = new AlternativeCommandsHandler(this);
        timer = new EssentialsTimer(this);
        scheduleSyncRepeatingTask(timer, 1000, 50);
        Economy.setEss(this);
        execTimer.mark("RegHandler");
        metrics = new Metrics(this);
        if (!metrics.isOptOut()) {
            getLogger().info("Starting Metrics. Opt-out using the global bStats config.");
        } else {
            getLogger().info("Metrics disabled per bStats config.");
        }
        final String timeroutput = execTimer.end();
        if (getSettings().isDebug()) {
            LOGGER.log(Level.INFO, "Essentials load {0}", timeroutput);
        }
    } catch (NumberFormatException ex) {
        handleCrash(ex);
    } catch (Error ex) {
        handleCrash(ex);
        throw ex;
    }
}
Also used : LegacyPotionMetaProvider(net.ess3.nms.legacy.LegacyPotionMetaProvider) LegacySpawnerProvider(net.ess3.nms.legacy.LegacySpawnerProvider) BlockMetaSpawnerProvider(net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider) net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider(net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider) BasePotionDataProvider(net.ess3.nms.updatedmeta.BasePotionDataProvider) PluginManager(org.bukkit.plugin.PluginManager) LegacySpawnEggProvider(net.ess3.nms.legacy.LegacySpawnEggProvider) Metrics(com.earth2me.essentials.metrics.Metrics) PermissionsHandler(com.earth2me.essentials.perm.PermissionsHandler) ProviderFactory(net.ess3.providers.ProviderFactory) ISettings(net.ess3.api.ISettings) net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider(net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider) YAMLException(org.yaml.snakeyaml.error.YAMLException) Method(java.lang.reflect.Method) ReflSpawnEggProvider(net.ess3.nms.refl.ReflSpawnEggProvider) Plugin(org.bukkit.plugin.Plugin) JavaPlugin(org.bukkit.plugin.java.JavaPlugin)

Example 29 with PluginManager

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

the class Essentials method reload.

@Override
public void reload() {
    Trade.closeLog();
    for (IConf iConf : confList) {
        iConf.reloadConfig();
        execTimer.mark("Reload(" + iConf.getClass().getSimpleName() + ")");
    }
    i18n.updateLocale(settings.getLocale());
    final PluginManager pm = getServer().getPluginManager();
    registerListeners(pm);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager)

Example 30 with PluginManager

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

the class Essentials method handleCrash.

private void handleCrash(Throwable exception) {
    final PluginManager pm = getServer().getPluginManager();
    LOGGER.log(Level.SEVERE, exception.toString());
    pm.registerEvents(new Listener() {

        @EventHandler(priority = EventPriority.LOW)
        public void onPlayerJoin(final PlayerJoinEvent event) {
            event.getPlayer().sendMessage("Essentials failed to load, read the log file.");
        }
    }, this);
    for (Player player : getOnlinePlayers()) {
        player.sendMessage("Essentials failed to load, read the log file.");
    }
    this.setEnabled(false);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Player(org.bukkit.entity.Player) SignBlockListener(com.earth2me.essentials.signs.SignBlockListener) SignEntityListener(com.earth2me.essentials.signs.SignEntityListener) SignPlayerListener(com.earth2me.essentials.signs.SignPlayerListener) Listener(org.bukkit.event.Listener) EventHandler(org.bukkit.event.EventHandler)

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