From 01023a29ed890860587bae41e01bfa7301fa9311 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 21 Jun 2014 02:12:32 +1200 Subject: [PATCH] Stupid hashsets and hashmaps and their unability to equalsignorecase on strings --- .../libraryaddict/disguise/LibsDisguises.java | 1 - .../disguise/disguisetypes/Disguise.java | 4 ++-- .../disguise/disguisetypes/DisguiseType.java | 2 +- .../disguise/utilities/DisguiseUtilities.java | 19 +++++++++++-------- .../disguise/utilities/ReflectionManager.java | 3 ++- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index b071fd6e..7406f4f9 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -10,7 +10,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Field; - import me.libraryaddict.disguise.commands.*; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index b7ab5d84..7bd156f2 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -447,7 +447,7 @@ public abstract class Disguise { if (isPlayerDisguise()) { String name = ((PlayerDisguise) this).getName(); - if (!DisguiseUtilities.getAddedByPlugins().contains(name)) { + if (!DisguiseUtilities.getAddedByPlugins().contains(name.toLowerCase())) { for (HashSet disguise : disguises.values()) { for (Disguise d : disguise) { if (d.isPlayerDisguise() && ((PlayerDisguise) d).getName().equals(name)) { @@ -455,7 +455,7 @@ public abstract class Disguise { } } } - DisguiseUtilities.getGameProfiles().remove(name); + DisguiseUtilities.getGameProfiles().remove(name.toLowerCase()); } } } diff --git a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java index 2d3a3972..a19a0ed4 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java @@ -224,7 +224,7 @@ public enum DisguiseType { public static DisguiseType getType(EntityType entityType) { try { - return DisguiseType.valueOf(entityType.name()); + return valueOf(entityType.name().toUpperCase()); } catch (Throwable ex) { return null; } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 45e65791..d0abbf05 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -121,7 +121,7 @@ public class DisguiseUtilities { public static void addGameProfile(String string, WrappedGameProfile gameProfile) { getGameProfiles().put(string, gameProfile); - addedByPlugins.add(string); + getAddedByPlugins().add(string.toLowerCase()); } /** @@ -291,7 +291,7 @@ public class DisguiseUtilities { } public static WrappedGameProfile getGameProfile(String playerName) { - return gameProfiles.get(playerName); + return gameProfiles.get(playerName.toLowerCase()); } public static HashMap getGameProfiles() { @@ -335,11 +335,14 @@ public class DisguiseUtilities { } public static WrappedGameProfile getProfileFromMojang(final PlayerDisguise disguise) { + final boolean remove = getAddedByPlugins().contains(disguise.getName().toLowerCase()); return getProfileFromMojang(disguise.getName(), new LibsProfileLookup() { @Override public void onLookup(WrappedGameProfile gameProfile) { - getAddedByPlugins().remove(disguise.getName()); + if (remove) { + getAddedByPlugins().remove(disguise.getName().toLowerCase()); + } if (DisguiseAPI.isDisguiseInUse(disguise)) { DisguiseUtilities.refreshTrackers(disguise); if (disguise.getEntity() instanceof Player && disguise.isSelfDisguiseVisible()) { @@ -358,8 +361,8 @@ public class DisguiseUtilities { return getProfileFromMojang(playerName, (Object) runnableIfCantReturn); } - private static WrappedGameProfile getProfileFromMojang(String name, final Object runnable) { - final String playerName = name.toLowerCase(); + private static WrappedGameProfile getProfileFromMojang(String origName, final Object runnable) { + final String playerName = origName.toLowerCase(); if (gameProfiles.containsKey(playerName)) { if (gameProfiles.get(playerName) != null) { return gameProfiles.get(playerName); @@ -413,7 +416,7 @@ public class DisguiseUtilities { } runnables.get(playerName).add(runnable); } - return ReflectionManager.getGameProfile(null, playerName); + return ReflectionManager.getGameProfile(null, origName); } /** @@ -556,11 +559,11 @@ public class DisguiseUtilities { @Deprecated public static void removeGameprofile(String string) { - gameProfiles.remove(string); + removeGameProfile(string); } public static void removeGameProfile(String string) { - gameProfiles.remove(string); + gameProfiles.remove(string.toLowerCase()); } public static void removeSelfDisguise(Player player) { diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index e7b356fa..891717d5 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -14,6 +14,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import com.google.common.collect.ImmutableMap; + import org.bukkit.Art; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -85,7 +86,7 @@ public class ReflectionManager { private static final Field pingField; private static Map, String> primitiveTypes; private static final Field trackerField; - + /* * This portion of code is originally Copyright (C) 2014-2014 Kane York. *