mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-13 11:41:24 +01:00
Update essentials to support 3rd party vanish toggling.
This commit is contained in:
parent
0f6625aea9
commit
6269ce9a3f
@ -44,21 +44,26 @@ public class PlayerList
|
||||
}
|
||||
|
||||
// Produce a user summary: There are 5 out of maximum 10 players online.
|
||||
public static String listSummary(final IEssentials ess, final boolean showHidden)
|
||||
public static String listSummary(final IEssentials ess, final User user, final boolean showHidden)
|
||||
{
|
||||
Server server = ess.getServer();
|
||||
int playerHidden = 0;
|
||||
int hiddenCount = 0;
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
if (ess.getUser(onlinePlayer).isHidden())
|
||||
if (ess.getUser(onlinePlayer).isHidden(user.getBase()))
|
||||
{
|
||||
playerHidden++;
|
||||
if (showHidden || user.getBase().canSee(onlinePlayer))
|
||||
{
|
||||
hiddenCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
String online;
|
||||
if (showHidden && playerHidden > 0)
|
||||
if (hiddenCount > 0)
|
||||
{
|
||||
online = tl("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers());
|
||||
online = tl("listAmountHidden", server.getOnlinePlayers().length - playerHidden, hiddenCount, server.getMaxPlayers());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -68,14 +73,14 @@ public class PlayerList
|
||||
}
|
||||
|
||||
// Build the basic player list, divided by groups.
|
||||
public static Map<String, List<User>> getPlayerLists(final IEssentials ess, final boolean showHidden)
|
||||
public static Map<String, List<User>> getPlayerLists(final IEssentials ess, final User sender, final boolean showHidden)
|
||||
{
|
||||
Server server = ess.getServer();
|
||||
final Map<String, List<User>> playerList = new HashMap<String, List<User>>();
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User onlineUser = ess.getUser(onlinePlayer);
|
||||
if (onlineUser.isHidden() && !showHidden)
|
||||
if (onlineUser.isHidden(sender.getBase()) && !showHidden && (sender != null && !sender.getBase().canSee(onlinePlayer)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -534,6 +534,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
{
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public boolean isHidden(final Player player)
|
||||
{
|
||||
return hidden || !player.canSee(getBase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHidden(final boolean hidden)
|
||||
@ -751,6 +756,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
{
|
||||
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean canInteractVanished()
|
||||
{
|
||||
return isAuthorized("essentials.vanish.interact");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVanished()
|
||||
|
@ -117,13 +117,13 @@ public class Commandexp extends EssentialsCommand
|
||||
|
||||
private void showMatch(final Server server, final CommandSource sender, final String match) throws PlayerNotFoundException
|
||||
{
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(match);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -138,13 +138,13 @@ public class Commandexp extends EssentialsCommand
|
||||
|
||||
private void expMatch(final Server server, final CommandSource sender, final String match, String amount, final boolean give) throws NotEnoughArgumentsException, PlayerNotFoundException
|
||||
{
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(match);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -84,13 +84,13 @@ public class Commandgamemode extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException(tl("gameModeInvalid"));
|
||||
}
|
||||
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(name);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class Commandkick extends EssentialsCommand
|
||||
if (sender.isPlayer())
|
||||
{
|
||||
User user = ess.getUser(sender.getPlayer());
|
||||
if (target.isHidden() && !user.isAuthorized("essentials.vanish.interact"))
|
||||
if (target.isHidden(sender.getPlayer()) && !user.canInteractVanished() && !sender.getPlayer().canSee(target.getBase()))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ public class Commandlist extends EssentialsCommand
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
boolean showHidden = true;
|
||||
User user = null;
|
||||
if (sender.isPlayer())
|
||||
{
|
||||
showHidden = ess.getUser(sender.getPlayer()).isAuthorized("essentials.list.hidden") || ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
user = ess.getUser(sender.getPlayer());
|
||||
showHidden = user.isAuthorized("essentials.list.hidden") || user.canInteractVanished();
|
||||
}
|
||||
sender.sendMessage(PlayerList.listSummary(ess, showHidden));
|
||||
final Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, showHidden);
|
||||
sender.sendMessage(PlayerList.listSummary(ess, user, showHidden));
|
||||
final Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, user, showHidden);
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
|
@ -101,12 +101,12 @@ public class Commandnear extends EssentialsCommand
|
||||
final World world = loc.getWorld();
|
||||
final StringBuilder output = new StringBuilder();
|
||||
final long radiusSquared = radius * radius;
|
||||
boolean showHidden = user.isAuthorized("essentials.vanish.interact");
|
||||
boolean showHidden = user.canInteractVanished();
|
||||
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User player = ess.getUser(onlinePlayer);
|
||||
if (!player.equals(user) && (!player.isHidden() || showHidden))
|
||||
if (!player.equals(user) && (!player.isHidden(user.getBase()) || showHidden || user.getBase().canSee(onlinePlayer)))
|
||||
{
|
||||
final Location playerLoc = player.getLocation();
|
||||
if (playerLoc.getWorld() != world)
|
||||
|
@ -27,7 +27,14 @@ public class Commandpay extends EssentialsLoopCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
amount = new BigDecimal(args[1].replaceAll("[^0-9\\.]", ""));
|
||||
String stringAmount = args[1].replaceAll("[^0-9\\.]", "");
|
||||
|
||||
if (stringAmount.length() < 1)
|
||||
{
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
amount = new BigDecimal(stringAmount);
|
||||
loopOnlinePlayers(server, user.getSource(), false, user.isAuthorized("essentials.pay.multiple"), args[0], args);
|
||||
}
|
||||
|
||||
@ -43,6 +50,6 @@ public class Commandpay extends EssentialsLoopCommand
|
||||
catch (MaxMoneyException ex)
|
||||
{
|
||||
sender.sendMessage(tl("maxMoney"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,12 @@ public class Commandrealname extends EssentialsCommand
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
final String whois = args[0].toLowerCase(Locale.ENGLISH);
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User u = ess.getUser(onlinePlayer);
|
||||
if (skipHidden && u.isHidden())
|
||||
if (skipHidden && u.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -72,13 +72,13 @@ public class Commandspeed extends EssentialsCommand
|
||||
|
||||
private void speedOtherPlayers(final Server server, final CommandSource sender, final boolean isFly, final boolean isBypass, final float speed, final String name) throws PlayerNotFoundException
|
||||
{
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(name);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -54,10 +54,21 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
return getPlayer(server, args, pos, true, false);
|
||||
}
|
||||
|
||||
// Get online players - only show vanished if source has permission
|
||||
protected User getPlayer(final Server server, final CommandSource sender, final String searchTerm) throws PlayerNotFoundException, NotEnoughArgumentsException
|
||||
{
|
||||
if (sender.isPlayer())
|
||||
{
|
||||
User user = ess.getUser(sender.getPlayer());
|
||||
return getPlayer(server, user, searchTerm, user.canInteractVanished(), false);
|
||||
}
|
||||
return getPlayer(server, searchTerm, true, false);
|
||||
}
|
||||
|
||||
// Get online players - only show vanished if source has permission
|
||||
protected User getPlayer(final Server server, final User user, final String[] args, final int pos) throws PlayerNotFoundException, NotEnoughArgumentsException
|
||||
{
|
||||
return getPlayer(server, user, args, pos, user.isAuthorized("essentials.vanish.interact"), false);
|
||||
return getPlayer(server, user, args, pos, user.canInteractVanished(), false);
|
||||
}
|
||||
|
||||
// Get online or offline players, this method allows for raw access
|
||||
@ -114,11 +125,12 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
if (!getHidden && user.isHidden() && !user.equals(sourceUser))
|
||||
|
||||
if (getHidden || canInteractWith(sourceUser, user))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
final List<Player> matches = server.matchPlayer(searchTerm);
|
||||
|
||||
@ -128,7 +140,8 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User userMatch = ess.getUser(onlinePlayer);
|
||||
if (getHidden || !userMatch.isHidden() || userMatch.equals(sourceUser))
|
||||
|
||||
if (getHidden || canInteractWith(sourceUser, userMatch))
|
||||
{
|
||||
final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
|
||||
if (displayName.contains(matchText))
|
||||
@ -143,13 +156,13 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
for (Player player : matches)
|
||||
{
|
||||
final User userMatch = ess.getUser(player);
|
||||
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || !userMatch.isHidden() || userMatch.equals(sourceUser)))
|
||||
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch)))
|
||||
{
|
||||
return userMatch;
|
||||
}
|
||||
}
|
||||
final User userMatch = ess.getUser(matches.get(0));
|
||||
if (getHidden || !userMatch.isHidden() || userMatch.equals(sourceUser))
|
||||
if (getHidden || canInteractWith(sourceUser, userMatch))
|
||||
{
|
||||
return userMatch;
|
||||
}
|
||||
@ -199,4 +212,19 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||
}
|
||||
return bldr.toString();
|
||||
}
|
||||
|
||||
private static boolean canInteractWith(User interactor, User interactee)
|
||||
{
|
||||
if (interactor == null)
|
||||
{
|
||||
return !interactee.isHidden();
|
||||
}
|
||||
|
||||
if (interactor.equals(interactee))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return interactor.getBase().canSee(interactee.getBase());
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import org.bukkit.Server;
|
||||
@ -35,11 +37,11 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand
|
||||
}
|
||||
else if (matchWildcards && searchTerm.contentEquals("*"))
|
||||
{
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User onlineUser = ess.getUser(onlinePlayer);
|
||||
if (skipHidden && onlineUser.isHidden())
|
||||
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -79,14 +81,14 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
|
||||
if (matchWildcards && (searchTerm.contentEquals("**") || searchTerm.contentEquals("*")))
|
||||
{
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
final User onlineUser = ess.getUser(onlinePlayer);
|
||||
if (skipHidden && onlineUser.isHidden())
|
||||
if (skipHidden && onlineUser.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -101,15 +103,37 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand
|
||||
}
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(searchTerm);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
|
||||
if (matchedPlayers.isEmpty())
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
|
||||
for (Player onlinePlayer : server.getOnlinePlayers())
|
||||
{
|
||||
continue;
|
||||
final User player = ess.getUser(onlinePlayer);
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(onlinePlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
final String displayName = FormatUtil.stripFormat(player.getDisplayName()).toLowerCase(Locale.ENGLISH);
|
||||
if (displayName.contains(matchText))
|
||||
{
|
||||
foundUser = true;
|
||||
updatePlayer(server, sender, player, commandArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foundUser = true;
|
||||
updatePlayer(server, sender, player, commandArgs);
|
||||
}
|
||||
foundUser = true;
|
||||
updatePlayer(server, sender, player, commandArgs);
|
||||
}
|
||||
if (!foundUser)
|
||||
{
|
||||
@ -118,7 +142,7 @@ public abstract class EssentialsLoopCommand extends EssentialsCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
final User player = getPlayer(server, searchTerm, !skipHidden, false);
|
||||
final User player = getPlayer(server, sender, searchTerm);
|
||||
updatePlayer(server, sender, player, commandArgs);
|
||||
}
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ public abstract class EssentialsToggleCommand extends EssentialsCommand
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
|
||||
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
|
||||
boolean foundUser = false;
|
||||
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
|
||||
for (Player matchPlayer : matchedPlayers)
|
||||
{
|
||||
final User player = ess.getUser(matchPlayer);
|
||||
if (skipHidden && player.isHidden())
|
||||
if (skipHidden && player.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(matchPlayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -205,11 +205,11 @@ public class KeywordReplacer implements IText
|
||||
}
|
||||
else
|
||||
{
|
||||
showHidden = user.isAuthorized("essentials.list.hidden") || user.isAuthorized("essentials.vanish.interact");
|
||||
showHidden = user.isAuthorized("essentials.list.hidden") || user.canInteractVanished();
|
||||
}
|
||||
|
||||
//First lets build the per group playerlist
|
||||
final Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, showHidden);
|
||||
final Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, user, showHidden);
|
||||
outputList = new HashMap<String, String>();
|
||||
for (String groupName : playerList.keySet())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user