com.earth2me.essentials.Essentials Java Examples

The following examples show how to use com.earth2me.essentials.Essentials. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginHookServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: PluginHookServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldSetSocialSpyStatus() {
    // given
    Player player = mock(Player.class);

    Essentials ess = mock(Essentials.class);
    User user = mock(User.class);
    given(ess.getUser(player)).willReturn(user);

    PluginManager pluginManager = mock(PluginManager.class);
    setPluginAvailable(pluginManager, ESSENTIALS, ess);
    PluginHookService pluginHookService = new PluginHookService(pluginManager);

    // when
    pluginHookService.setEssentialsSocialSpyStatus(player, true);

    // then
    verify(ess).getUser(player);
    verify(user).setSocialSpyEnabled(true);
}
 
Example #3
Source File: PluginHookServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldReturnEssentialsDataFolder() {
    // given
    Essentials ess = mock(Essentials.class);
    File essDataFolder = new File("test/data-folder");
    // Need to set the data folder with reflections because getDataFolder() is declared final
    ReflectionTestUtils.setField(JavaPlugin.class, ess, "dataFolder", essDataFolder);

    PluginManager pluginManager = mock(PluginManager.class);
    setPluginAvailable(pluginManager, ESSENTIALS, ess);
    PluginHookService pluginHookService = new PluginHookService(pluginManager);

    // when
    File dataFolder = pluginHookService.getEssentialsDataFolder();

    // then
    assertThat(dataFolder, equalTo(essDataFolder));
}
 
Example #4
Source File: Harbor.java    From Harbor with MIT License 6 votes vote down vote up
public void onEnable() {
    harbor = this;
    saveDefaultConfig();
    new Metrics(this);

    getCommand("harbor").setExecutor(new HarborCommand());
    getServer().getPluginManager().registerEvents(new BedListener(), this);
    getServer().getPluginManager().registerEvents(new PlayerListener(), this);
    getServer().getScheduler().runTaskTimerAsynchronously(this,
            new Checker(), 0L, Config.getInteger("interval") * 20);

    essentials = (Essentials) getServer().getPluginManager().getPlugin("Essentials");
    if (essentials == null) { // If Essentials isn't present, enable fallback AFK system
        getLogger().info("Essentials not present- registering fallback AFK detection system.");
        getServer().getPluginManager().registerEvents(new AfkListener(), this);
    }

    if (!Config.getString("version").equals("1.6.2")) {
        getLogger().warning("Your Harbor configuration is outdated- please regenerate your " +
                "config or Harbor may not work properly!");
    }
}
 
Example #5
Source File: EssentialsBridge.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public void uninject(Plugin plugin)
{
    BungeePerms.getLogger().info("Uninjection of Bungeeperms into Essentials");

    try
    {
        Essentials ess = (Essentials) plugin;

        Field f = ess.getClass().getDeclaredField("permissionsHandler");
        f.setAccessible(true);
        PermissionsHandler permhandler = (PermissionsHandler) f.get(plugin);

        permhandler.checkPermissions();
    }
    catch (Exception ex)
    {
        BungeePerms.getInstance().getDebug().log(ex);
    }
}
 
Example #6
Source File: MessageManager.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Detects Essentials' Locale
 */
public static void detectEssentialsLocale() {
	if(plugin.getDependencyManager().isEnabled(Dependency.ESSENTIALS) && !Config.LANG_OVERRIDEESSENTIALS.getBoolean()) {
		Essentials essentials = plugin.getDependencyManager().get(Dependency.ESSENTIALS, Essentials.class);
		if(essentials.getSettings() == null) {
			return;
		}

		String locale = essentials.getSettings().getLocale();
		if(locale.isEmpty()) {
			locale = "en";
		}

		if(ConfigManager.essentialsLocale.containsKey(locale)) {
			Config.LANG_NAME.set(ConfigManager.essentialsLocale.get(locale));
		}

		LoggerUtils.info("Changed lang to Essentials' locale: " + Config.LANG_NAME.getString());
	}
}
 
Example #7
Source File: PlayerManager.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if a player is vanished
 *
 * @param player player
 * @return boolean
 */
public boolean isVanished(Player player) {
	return player != null
			&& (plugin.getDependencyManager().isEnabled(Dependency.VANISHNOPACKET) && plugin.getDependencyManager().get(Dependency.VANISHNOPACKET, VanishPlugin.class).getManager().isVanished(player)
					|| plugin.getDependencyManager().isEnabled(Dependency.ESSENTIALS) && plugin.getDependencyManager().get(Dependency.ESSENTIALS, Essentials.class).getVanishedPlayers().contains(player.getName()));

}
 
Example #8
Source File: PluginHookServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #9
Source File: PluginHookServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@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));
}
 
Example #10
Source File: PluginHookService.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Attempts to create a hook into Essentials.
 */
public void tryHookToEssentials() {
    try {
        essentials = getPlugin(pluginManager, "Essentials", Essentials.class);
    } catch (Exception | NoClassDefFoundError ignored) {
        essentials = null;
    }
}
 
Example #11
Source File: EssentialsBridge.java    From BungeePerms with GNU General Public License v3.0 5 votes vote down vote up
public void inject(Plugin plugin)
{
    BungeePerms.getLogger().info("Injection of Bungeeperms into Essentials");
    try
    {
        Essentials ess = (Essentials) plugin;

        if (!ess.isEnabled())
            return;

        //get ess permhandler
        Field f = ess.getClass().getDeclaredField("permissionsHandler");
        f.setAccessible(true);
        PermissionsHandler permhandler = (PermissionsHandler) f.get(plugin);

        //inject bungeeperms
        f = permhandler.getClass().getDeclaredField("handler");
        f.setAccessible(true);
        IPermissionsHandler handler = (IPermissionsHandler) f.get(permhandler);

        BungeePerms bpPlugin = BungeePerms.getInstance();
        if (bpPlugin != null && bpPlugin.isEnabled())
        {
            if (!(handler instanceof BungeePermsHandler))
            {
                Logger.getLogger("Essentials").log(Level.INFO, "Essentials: Using BungeePerms based permissions.");
                handler = new BungeePermsHandler();
                f.set(permhandler, handler);
            }
        }
    }
    catch (Exception ex)
    {
        BungeePerms.getInstance().getDebug().log(ex);
    }
}
 
Example #12
Source File: Island.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public void spawnPlayer(Player player) {
    if (player == null) return;
    if (Bukkit.getPluginManager().isPluginEnabled("EssentialsSpawn")) {
        EssentialsSpawn essentialsSpawn = (EssentialsSpawn) Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
        Essentials essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
        player.teleport(essentialsSpawn.getSpawn(essentials.getUser(player).getGroup()));
    } else {
        World world = Bukkit.getWorld(IridiumSkyblock.getConfiguration().worldSpawn);
        if (world == null) {
            world = Bukkit.getWorlds().get(0);
        }
        player.teleport(world.getSpawnLocation());
    }
}
 
Example #13
Source File: GodmodeFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
private void handleValue(Player player, State state)
{
	if (state != null)
	{
		this.isGodmodeEnabled = (state == State.ALLOW ? true : false);
	}
	else
	{
		this.isGodmodeEnabled = null;
	}
	
	//For now at least
	Plugin essentials = this.getPlugin().getServer().getPluginManager().getPlugin("Essentials");
	if (essentials != null)
	{
		User user = ((Essentials)essentials).getUser(player);
		
		if (this.isGodmodeEnabled != null)
		{
			if (this.isGodmodeEnabled != user.isGodModeEnabled())
			{
				if (this.originalEssentialsGodmode == null)
				{
					this.originalEssentialsGodmode = user.isGodModeEnabled();
				}
				
				user.setGodModeEnabled(this.isGodmodeEnabled);
			}
		}
		else
		{
			if (this.originalEssentialsGodmode != null)
			{
				user.setGodModeEnabled(this.originalEssentialsGodmode);
				
				this.originalEssentialsGodmode = null;
			}
		}
	}
}
 
Example #14
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static boolean Essentials_isAFK(ITabPlayer p) {
	try {
		return ((Essentials)essentials).getUser(p.getBukkitEntity()).isAfk();
	} catch (Throwable t) {
		return Shared.errorManager.printError(false, "Failed to check AFK status of " + p.getName() + " using Essentials", t);
	}
}
 
Example #15
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static double Essentials_getMoney(ITabPlayer p) {
	try {
		return ((Essentials)essentials).getUser(p.getBukkitEntity()).getMoney().doubleValue();
	} catch (Throwable t) {
		return Shared.errorManager.printError(0, "Failed to check money of " + p.getName() + " using Essentials", t);
	}
}
 
Example #16
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onPluginEnable(Plugin plugin) {
    essentials = (Essentials) plugin;
    forcedInvisibilityTask = forcedInvisibilityRunnable.runTaskTimer(superVanish, 0, 100);
    forcedInvisibilityRunnable.run();
}
 
Example #17
Source File: EssentialsHelper.java    From WorldGuardExtraFlagsPlugin with MIT License 4 votes vote down vote up
public EssentialsHelper(WorldGuardExtraFlagsPlugin plugin, Plugin essentialsPlugin)
{
	this(plugin, (Essentials)essentialsPlugin);
}
 
Example #18
Source File: Harbor.java    From Harbor with MIT License 4 votes vote down vote up
public static Essentials getEssentials() {
    return essentials;
}
 
Example #19
Source File: PluginHooks.java    From TAB with Apache License 2.0 4 votes vote down vote up
public static String Essentials_getNickname(ITabPlayer p) {
	return ((Essentials)essentials).getUser(p.getBukkitEntity()).getNickname();
}