From c47647197837e5614585f3f1013b193d5047212f Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 9 Jun 2013 23:06:03 +0100 Subject: [PATCH] Don't look up valid looking IP's in the player database. --- .../essentials/commands/Commandbanip.java | 25 +++++-- .../essentials/commands/Commandunbanip.java | 18 +++-- .../essentials/perm/BPermissionsHandler.java | 74 ------------------- .../essentials/perm/Permissions2Handler.java | 61 --------------- .../essentials/perm/Permissions3Handler.java | 61 --------------- .../essentials/perm/PermissionsHandler.java | 34 --------- 6 files changed, 30 insertions(+), 243 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java delete mode 100644 Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java delete mode 100644 Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java index 2d34175d1..e1b861cb5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -25,25 +26,33 @@ public class Commandbanip extends EssentialsCommand } final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME; - final String ipAddress; - final User player = ess.getUser(args[0]); - if (player == null) + String ipAddress; + if (FormatUtil.validIP(args[0])) { ipAddress = args[0]; } else { - ipAddress = player.getLastLoginAddress(); - if (ipAddress.length() == 0) + try { - throw new Exception(_("playerNotFound")); + User player = getPlayer(server, args, 0, true, true); + ipAddress = player.getLastLoginAddress(); } + catch (PlayerNotFoundException ex) + { + ipAddress = args[0]; + } + } + + if (ipAddress.isEmpty()) + { + throw new PlayerNotFoundException(); } ess.getServer().banIP(ipAddress); server.getLogger().log(Level.INFO, _("playerBanIpAddress", senderName, ipAddress)); - - ess.broadcastMessage(sender, "essentials.ban.notify", _("playerBanIpAddress", senderName, ipAddress)); + + ess.broadcastMessage(sender, "essentials.ban.notify", _("playerBanIpAddress", senderName, ipAddress)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java index c0711b03a..2a37916cf 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java @@ -3,7 +3,6 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.Console; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; -import com.earth2me.essentials.utils.StringUtil; import com.earth2me.essentials.utils.FormatUtil; import java.util.logging.Level; import org.bukkit.Server; @@ -25,6 +24,7 @@ public class Commandunbanip extends EssentialsCommand { throw new NotEnoughArgumentsException(); } + String ipAddress; if (FormatUtil.validIP(args[0])) { @@ -32,12 +32,20 @@ public class Commandunbanip extends EssentialsCommand } else { - final User user = getPlayer(server, args, 0, true, true); - ipAddress = user.getLastLoginAddress(); - if (ipAddress.isEmpty()) + try { - throw new PlayerNotFoundException(); + User player = getPlayer(server, args, 0, true, true); + ipAddress = player.getLastLoginAddress(); } + catch (PlayerNotFoundException ex) + { + ipAddress = args[0]; + } + } + + if (ipAddress.isEmpty()) + { + throw new PlayerNotFoundException(); } ess.getServer().unbanIP(ipAddress); diff --git a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java deleted file mode 100644 index a542c3d66..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/BPermissionsHandler.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.earth2me.essentials.perm; - -import de.bananaco.permissions.Permissions; -import de.bananaco.permissions.info.InfoReader; -import de.bananaco.permissions.interfaces.PermissionSet; -import de.bananaco.permissions.worlds.WorldPermissionsManager; -import java.util.List; -import org.bukkit.entity.Player; - - -public class BPermissionsHandler extends SuperpermsHandler -{ - private final transient WorldPermissionsManager wpm; - private final transient InfoReader info; - - public BPermissionsHandler() - { - wpm = Permissions.getWorldPermissionsManager(); - info = new InfoReader(); - info.instantiate(); - } - - @Override - public String getGroup(final Player base) - { - final List groups = getGroups(base); - if (groups == null || groups.isEmpty()) - { - return null; - } - return groups.get(0); - } - - @Override - public List getGroups(final Player base) - { - final PermissionSet pset = wpm.getPermissionSet(base.getWorld()); - if (pset == null) - { - return null; - } - return pset.getGroups(base); - } - - @Override - public boolean inGroup(final Player base, final String group) - { - final List groups = getGroups(base); - if (groups == null || groups.isEmpty()) - { - return false; - } - return groups.contains(group); - } - - @Override - public boolean canBuild(final Player base, final String group) - { - return hasPermission(base, "bPermissions.build"); - } - - @Override - public String getPrefix(final Player base) - { - return info.getPrefix(base); - } - - @Override - public String getSuffix(final Player base) - { - return info.getSuffix(base); - } - -} diff --git a/Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java b/Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java deleted file mode 100644 index 6b5ff5b73..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/Permissions2Handler.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.earth2me.essentials.perm; - -import com.nijiko.permissions.PermissionHandler; -import com.nijikokun.bukkit.Permissions.Permissions; -import java.util.Arrays; -import java.util.List; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public class Permissions2Handler implements IPermissionsHandler -{ - private final transient PermissionHandler permissionHandler; - - public Permissions2Handler(final Plugin permissionsPlugin) - { - permissionHandler = ((Permissions)permissionsPlugin).getHandler(); - } - - @Override - public String getGroup(final Player base) - { - return permissionHandler.getGroup(base.getWorld().getName(), base.getName()); - } - - @Override - public List getGroups(final Player base) - { - return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName())); - } - - @Override - public boolean canBuild(final Player base, final String group) - { - return permissionHandler.canGroupBuild(base.getWorld().getName(), getGroup(base)); - } - - @Override - public boolean inGroup(final Player base, final String group) - { - return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group); - } - - @Override - public boolean hasPermission(final Player base, final String node) - { - return permissionHandler.permission(base, node); - } - - @Override - public String getPrefix(final Player base) - { - return permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base)); - } - - @Override - public String getSuffix(final Player base) - { - return permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base)); - } -} diff --git a/Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java b/Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java deleted file mode 100644 index 190d5b8c5..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/Permissions3Handler.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.earth2me.essentials.perm; - -import com.nijiko.permissions.PermissionHandler; -import com.nijikokun.bukkit.Permissions.Permissions; -import java.util.Arrays; -import java.util.List; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - - -public class Permissions3Handler implements IPermissionsHandler -{ - private final transient PermissionHandler permissionHandler; - - public Permissions3Handler(final Plugin permissionsPlugin) - { - permissionHandler = ((Permissions)permissionsPlugin).getHandler(); - } - - @Override - public String getGroup(final Player base) - { - return permissionHandler.getPrimaryGroup(base.getWorld().getName(), base.getName()); - } - - @Override - public List getGroups(final Player base) - { - return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName())); - } - - @Override - public boolean canBuild(final Player base, final String group) - { - return permissionHandler.canUserBuild(base.getWorld().getName(), base.getName()); - } - - @Override - public boolean inGroup(final Player base, final String group) - { - return permissionHandler.inGroup(base.getWorld().getName(), base.getName(), group); - } - - @Override - public boolean hasPermission(final Player base, final String node) - { - return permissionHandler.has(base, node); - } - - @Override - public String getPrefix(final Player base) - { - return permissionHandler.getUserPrefix(base.getWorld().getName(), base.getName()); - } - - @Override - public String getSuffix(final Player base) - { - return permissionHandler.getUserSuffix(base.getWorld().getName(), base.getName()); - } -} diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java index b0e77f761..044fbb913 100644 --- a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java @@ -1,7 +1,5 @@ package com.earth2me.essentials.perm; -import com.earth2me.essentials.utils.NumberUtil; -import com.earth2me.essentials.utils.StringUtil; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -160,44 +158,12 @@ public class PermissionsHandler implements IPermissionsHandler final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions"); if (bPermPlugin != null && bPermPlugin.isEnabled()) { - final String bVer = bPermPlugin.getDescription().getVersion().replace(".", ""); - if (NumberUtil.isInt(bVer) && Integer.parseInt(bVer) < 284) - { - if (!(handler instanceof BPermissionsHandler)) - { - LOGGER.log(Level.INFO, "Essentials: Using bPermissions based permissions."); - handler = new BPermissionsHandler(); - } - return; - } if (!(handler instanceof BPermissions2Handler)) { LOGGER.log(Level.INFO, "Essentials: Using bPermissions2 based permissions."); handler = new BPermissions2Handler(); } return; - - } - final Plugin permPlugin = pluginManager.getPlugin("Permissions"); - if (permPlugin != null && permPlugin.isEnabled()) - { - if (permPlugin.getDescription().getVersion().charAt(0) == '3') - { - if (!(handler instanceof Permissions3Handler)) - { - LOGGER.log(Level.INFO, "Essentials: Using Permissions 3 based permissions."); - handler = new Permissions3Handler(permPlugin); - } - } - else - { - if (!(handler instanceof Permissions2Handler)) - { - LOGGER.log(Level.INFO, "Essentials: Using Permissions 2 based permissions."); - handler = new Permissions2Handler(permPlugin); - } - } - return; } if (useSuperperms)