diff options
author | KHobbits <rob@khobbits.co.uk> | 2014-06-27 01:46:37 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-06-27 01:46:37 +0100 |
commit | 20329e99a96ac03928b3a241145fac28839cba63 (patch) | |
tree | aa7cdcd3062fe42f437ba428b248bfc98029fe23 | |
parent | 87c0f20e92f504dbdf1bbff8d74e9ff262a638c1 (diff) | |
download | Essentials-20329e99a96ac03928b3a241145fac28839cba63.tar Essentials-20329e99a96ac03928b3a241145fac28839cba63.tar.gz Essentials-20329e99a96ac03928b3a241145fac28839cba63.tar.lz Essentials-20329e99a96ac03928b3a241145fac28839cba63.tar.xz Essentials-20329e99a96ac03928b3a241145fac28839cba63.zip |
Update essentials to support 3rd party vanish toggling.
14 files changed, 122 insertions, 46 deletions
diff --git a/Essentials/src/com/earth2me/essentials/PlayerList.java b/Essentials/src/com/earth2me/essentials/PlayerList.java index 2ea820adf..bfd7ce2b1 100644 --- a/Essentials/src/com/earth2me/essentials/PlayerList.java +++ b/Essentials/src/com/earth2me/essentials/PlayerList.java @@ -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; } diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index f4a1ed5a0..82eca3d3d 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -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() diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java index 4cbe72de6..3100c9708 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandexp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandexp.java @@ -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;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java index ae303f493..4b91d0582 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgamemode.java @@ -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; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java index e7095f44c..f4c2bdaca 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java @@ -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(); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 46d8dd95a..bb5475721 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -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) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java index 846534baf..29d30b3e7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnear.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnear.java @@ -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) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java index 01492faed..a83df4ac7 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandpay.java @@ -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")); - } + } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index 7a83641fc..a292316bd 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -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; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java index f155c5dec..620f43956 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java @@ -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; } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index 13fd2632c..71d45a288 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -55,9 +55,20 @@ public abstract class EssentialsCommand implements IEssentialsCommand } // 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()); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java index 7ac4d0595..7dfa594fc 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsLoopCommand.java @@ -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); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java index 062441dda..deed20a13 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java @@ -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; } diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 683a1fe00..111c1b3cd 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -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()) { |