com.earth2me.essentials.User Java Examples

The following examples show how to use com.earth2me.essentials.User. 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: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        if (!Bukkit.getPluginManager().isPluginEnabled("Essentials")) return;
        for (UUID uuid : superVanish.getVanishStateMgr().getOnlineVanishedPlayers()) {
            Player p = Bukkit.getPlayer(uuid);
            User user = essentials.getUser(p);
            if (user == null) continue;
            if (!user.isHidden())
                user.setHidden(true);
        }
    } catch (Exception e) {
        cancel();
        superVanish.logException(e);
    }
}
 
Example #2
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onCommand(final PlayerCommandPreprocessEvent e) {
    if (!CommandAction.VANISH_SELF.checkPermission(e.getPlayer(), superVanish)) return;
    if (superVanish.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId())) return;
    String command = e.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "")
            .toLowerCase(Locale.ENGLISH);
    if (command.split(":").length > 1) command = command.split(":")[1];
    if (command.equals("supervanish") || command.equals("sv")
            || command.equals("v") || command.equals("vanish")) {
        final User user = essentials.getUser(e.getPlayer());
        if (user == null || !user.isAfk()) return;
        user.setHidden(true);
        preVanishHiddenPlayers.add(e.getPlayer().getUniqueId());
        superVanish.getServer().getScheduler().runTaskLater(superVanish, new Runnable() {
            @Override
            public void run() {
                if (preVanishHiddenPlayers.remove(e.getPlayer().getUniqueId())) {
                    user.setHidden(false);
                }
            }
        }, 1);
    }
}
 
Example #3
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 #4
Source File: EssentialsEconomyHook.java    From factions-top with MIT License 5 votes vote down vote up
@Override
public double getBalance(UUID playerId) {
    User user;
    try {
        user = essentials.getUser(playerId);
    } catch (NullPointerException e) {
        return 0;
    }

    if (user != null) {
        return user.getMoney().doubleValue();
    }
    return 0;
}
 
Example #5
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 #6
Source File: TeleportCmdWarpper.java    From NyaaUtils with MIT License 5 votes vote down vote up
private void doBack(Player p, User iu, Location curLoc, Location lastLoc) {
    if (iu.getWorld() != lastLoc.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !iu.isAuthorized("essentials.worlds." + lastLoc.getWorld().getName())) {
        msg(p, "internal.error.no_required_permission", "essentials.worlds." + lastLoc.getWorld().getName());
        return;
    }

    double fee = plugin.cfg.backBase;
    if (curLoc.getWorld() != lastLoc.getWorld()) {
        fee += plugin.cfg.backWorld;
        fee += lastLoc.distance(PlayerSpawn(p, lastLoc.getWorld())) * (double) plugin.cfg.backIncrement / plugin.cfg.backDistance;
    } else {
        fee += lastLoc.distance(curLoc) * (double) plugin.cfg.backIncrement / plugin.cfg.backDistance;
    }
    if (fee > plugin.cfg.backMax) fee = plugin.cfg.backMax;
    fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
    if (!VaultUtils.withdraw(p, fee)) {
        msg(p, "user.teleport.money_insufficient", fee);
        return;
    }
    try {
        iu.getTeleport().back(new Trade(0, ess));
        msg(p, "user.teleport.ok", fee, I18n.format("user.teleport.back"));
        if (plugin.systemBalance != null) {
            plugin.systemBalance.deposit(fee, plugin);
        }
    } catch (Exception e) {
        VaultUtils.deposit(p, fee);
        p.sendMessage(e.getMessage());
    }
}
 
Example #7
Source File: TeleportCmdWarpper.java    From NyaaUtils with MIT License 5 votes vote down vote up
private void doHome(Player p, User iu, Location homeLoc, Location curLoc) {
    if (iu.getWorld() != homeLoc.getWorld() && ess.getSettings().isWorldHomePermissions() && !iu.isAuthorized("essentials.worlds." + homeLoc.getWorld().getName())) {
        msg(p, "internal.error.no_required_permission", "essentials.worlds." + homeLoc.getWorld().getName());
        return;
    }

    double fee = plugin.cfg.homeBase;
    if (homeLoc.getWorld() != curLoc.getWorld()) {
        fee += plugin.cfg.homeWorld;
        fee += homeLoc.distance(PlayerSpawn(p, homeLoc.getWorld())) * (double) plugin.cfg.homeIncrement / plugin.cfg.homeDistance;
    } else {
        fee += homeLoc.distance(curLoc) * (double) plugin.cfg.homeIncrement / plugin.cfg.homeDistance;
    }
    if (fee > plugin.cfg.homeMax) fee = plugin.cfg.homeMax;
    fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
    if (!VaultUtils.withdraw(p, fee)) {
        msg(p, "user.teleport.money_insufficient", fee);
        return;
    }
    try {
        iu.getTeleport().teleport(homeLoc, new Trade(0, ess), PlayerTeleportEvent.TeleportCause.PLUGIN);
        msg(p, "user.teleport.ok", fee, I18n.format("user.teleport.home"));
        if (plugin.systemBalance != null) {
            plugin.systemBalance.deposit(fee, plugin);
        }
    } catch (Exception e) {
        VaultUtils.deposit(p, fee);
        p.sendMessage(e.getMessage());
    }
}
 
Example #8
Source File: TeleportCmdWarpper.java    From NyaaUtils with MIT License 5 votes vote down vote up
private int checkHomeLimit(final User user, String name) {
    if (!user.isAuthorized("essentials.sethome.multiple.unlimited")) {
        int limit = ess.getSettings().getHomeLimit(user);
        if (user.getHomes().size() == limit && user.getHomes().contains(name)) {
            return 0;
        }
        if (user.getHomes().size() >= limit) {
            return limit;
        }
        if (limit == 1) {
            return 1;
        }
    }
    return 0;
}
 
Example #9
Source File: HookEssentials.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
public static User getUser(Player player) {
    if(player == null) return null;

    IEssentials api = getAPI();
    if(api == null) return null;

    return api.getUser(player);
}
 
Example #10
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onJoin(PlayerJoinEvent e) {
    User user = essentials.getUser(e.getPlayer());
    if (user == null) return;
    if (superVanish.getVanishStateMgr().isVanished(e.getPlayer().getUniqueId()) && !user.isHidden())
        user.setHidden(true);
    else user.setHidden(false);
}
 
Example #11
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVanish(PlayerHideEvent e) {
    User user = essentials.getUser(e.getPlayer());
    if (user == null) return;
    if (user.isVanished()) user.setVanished(false);
    preVanishHiddenPlayers.remove(e.getPlayer().getUniqueId());
    user.setHidden(true);
}
 
Example #12
Source File: TeleportCmdWarpper.java    From NyaaUtils with MIT License 4 votes vote down vote up
private void doSetHome(Player p, User iu, Location curLoc, String name) {
    int n = checkHomeLimit(iu, name);
    if (n == 1) {
        if (!name.equals("home"))
            msg(p, "user.teleport.home_limit_one");
        name = "home";
    } else if (n != 0) {
        msg(p, "user.teleport.home_limit", n);
        return;
    }
    if ("bed".equals(name) || NumberUtil.isInt(name)) {
        msg(p, "user.teleport.invalid_name");
        return;
    }
    if (!ess.getSettings().isTeleportSafetyEnabled() && LocationUtil.isBlockUnsafeForUser(iu, curLoc.getWorld(), curLoc.getBlockX(), curLoc.getBlockY(), curLoc.getBlockZ())) {
        msg(p, "user.teleport.unsafe");
        return;
    }

    double fee = plugin.cfg.setHomeMax;
    World defaultWorld = Bukkit.getWorld(plugin.cfg.setHomeDefaultWorld);
    if (defaultWorld == null) {
        defaultWorld = Bukkit.getWorlds().get(0);
    }
    if (curLoc.getWorld() != defaultWorld) {
        fee += plugin.cfg.setHomeWorld;
        fee -= curLoc.distance(PlayerSpawn(p, curLoc.getWorld())) * (double) plugin.cfg.setHomeDecrement / plugin.cfg.setHomeDistance;
    } else {
        fee -= curLoc.distance(PlayerSpawn(p, defaultWorld)) * (double) plugin.cfg.setHomeDecrement / plugin.cfg.setHomeDistance;
    }
    if (fee < plugin.cfg.setHomeMin) fee = plugin.cfg.setHomeMin;
    fee = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
    if (!VaultUtils.withdraw(p, fee)) {
        msg(p, "user.teleport.money_insufficient", fee);
        return;
    }
    iu.setHome(name, curLoc);
    msg(p, "user.teleport.ok", fee, I18n.format("user.teleport.sethome"));
    if (plugin.systemBalance != null && fee > 0) {
        plugin.systemBalance.deposit(fee, plugin);
    }
}
 
Example #13
Source File: HookEssentials.java    From CombatLogX with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isVanished(Player player) {
    User user = getUser(player);
    if(user == null) return false;

    return user.isVanished();
}
 
Example #14
Source File: EssentialsHook.java    From SuperVanish with Mozilla Public License 2.0 4 votes vote down vote up
@EventHandler
public void onReappear(PostPlayerShowEvent e) {
    User user = essentials.getUser(e.getPlayer());
    if (user == null) return;
    user.setHidden(false);
}