From ffea3596611e33a9ae631f4fb4759d58ca4717ed Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 18 Aug 2014 21:00:03 +0100 Subject: [PATCH] rework /seen to be a little stricter on argument matching. --- .../essentials/commands/Commandseen.java | 51 +++++++++++-------- .../commands/EssentialsCommand.java | 15 ++++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 35c719cf4b..fd4ad69b17 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -43,38 +43,45 @@ protected void seen(final Server server, final CommandSource sender, final Strin { throw new NotEnoughArgumentsException(); } - try + User player = ess.getOfflineUser(args[0]); + if (player == null) { - User user = getPlayer(server, sender, args, 0); - seenOnline(server, sender, user, showBan, extra); - } - catch (NoSuchFieldException e) - { - User player = ess.getOfflineUser(args[0]); - if (player == null) + if (ipLookup && FormatUtil.validIP(args[0])) { - if (ipLookup && FormatUtil.validIP(args[0])) - { - seenIP(server, sender, args[0]); - return; - } - else if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) - { - sender.sendMessage(tl("isIpBanned", args[0])); - return; - } - else if (BanLookup.isBanned(ess, args[0])) + seenIP(server, sender, args[0]); + return; + } + else if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) + { + sender.sendMessage(tl("isIpBanned", args[0])); + return; + } + else if (BanLookup.isBanned(ess, args[0])) + { + sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true"))); + return; + } + else + { + try { - sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true"))); - return; + player = getPlayer(server, sender, args, 0); } - else + catch (NoSuchFieldException e) { throw new PlayerNotFoundException(); } } + } + if (player.getBase().isOnline() && canInteractWith(sender, player)) + { + seenOnline(server, sender, player, showBan, extra); + } + else + { seenOffline(server, sender, player, showBan, extra); } + } private void seenOnline(final Server server, final CommandSource sender, final User user, final boolean showBan, final boolean extra) throws Exception diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java index ee605ffb3b..bfd1843be8 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java @@ -211,6 +211,21 @@ public static String getFinalArg(final String[] args, final int start) return bldr.toString(); } + boolean canInteractWith(CommandSource interactor, User interactee) + { + if (interactor == null) + { + return !interactee.isHidden(); + } + + if (interactor.isPlayer()) + { + return canInteractWith(ess.getUser(interactor.getPlayer()), interactee); + } + + return true; // console + } + private static boolean canInteractWith(User interactor, User interactee) { if (interactor == null)