diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index fc0d44e1..b65b1a28 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -36,6 +36,7 @@ import net.md_5.bungee.packet.Packet9Respawn; import net.md_5.bungee.packet.PacketCCSettings; import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFFKick; +import net.md_5.bungee.util.CaseInsensitiveSet; @RequiredArgsConstructor public final class UserConnection implements ProxiedPlayer @@ -72,8 +73,8 @@ public final class UserConnection implements ProxiedPlayer @Setter private int ping = 100; /*========================================================================*/ - private final Collection groups = new HashSet<>(); - private final Collection permissions = new HashSet<>(); + private final Collection groups = new CaseInsensitiveSet(); + private final Collection permissions = new CaseInsensitiveSet(); /*========================================================================*/ @Getter private int clientEntityId; diff --git a/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java new file mode 100644 index 00000000..984c43d0 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveHashingStrategy.java @@ -0,0 +1,21 @@ +package net.md_5.bungee.util; + +import gnu.trove.strategy.HashingStrategy; + +class CaseInsensitiveHashingStrategy implements HashingStrategy +{ + + static final CaseInsensitiveHashingStrategy INSTANCE = new CaseInsensitiveHashingStrategy(); + + @Override + public int computeHashCode(String object) + { + return object.toLowerCase().hashCode(); + } + + @Override + public boolean equals(String o1, String o2) + { + return o1.toLowerCase().equals( o2.toLowerCase() ); + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveMap.java b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveMap.java index 88773b85..ddfa7f52 100644 --- a/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveMap.java +++ b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveMap.java @@ -1,34 +1,18 @@ package net.md_5.bungee.util; import gnu.trove.map.hash.TCustomHashMap; -import gnu.trove.strategy.HashingStrategy; import java.util.Map; public class CaseInsensitiveMap extends TCustomHashMap { - private static final HashingStrategy hashingStrategy = new HashingStrategy() - { - @Override - public int computeHashCode(String object) - { - return object.toLowerCase().hashCode(); - } - - @Override - public boolean equals(String o1, String o2) - { - return o1.toLowerCase().equals( o2.toLowerCase() ); - } - }; - public CaseInsensitiveMap() { - super( hashingStrategy ); + super( CaseInsensitiveHashingStrategy.INSTANCE ); } public CaseInsensitiveMap(Map map) { - super( hashingStrategy, map ); + super( CaseInsensitiveHashingStrategy.INSTANCE, map ); } } diff --git a/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveSet.java b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveSet.java new file mode 100644 index 00000000..579c6fd9 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/util/CaseInsensitiveSet.java @@ -0,0 +1,18 @@ +package net.md_5.bungee.util; + +import gnu.trove.set.hash.TCustomHashSet; +import java.util.Collection; + +public class CaseInsensitiveSet extends TCustomHashSet +{ + + public CaseInsensitiveSet() + { + super( CaseInsensitiveHashingStrategy.INSTANCE ); + } + + public CaseInsensitiveSet(Collection collection) + { + super( CaseInsensitiveHashingStrategy.INSTANCE, collection ); + } +} diff --git a/proxy/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java b/proxy/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java index f29cd85c..67ce8b15 100644 --- a/proxy/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java +++ b/proxy/src/test/java/net/md_5/bungee/util/CaseInsensitiveTest.java @@ -16,4 +16,10 @@ public class CaseInsensitiveTest Assert.assertTrue( map.contains( "foo" ) ); // Assert that it is case insensitive Assert.assertTrue( map.entrySet().iterator().next().getKey().equals( "FOO" ) ); // Asert that case is preserved } + + @Test + public void testSets() + { + throw new UnsupportedOperationException( "Need a unit test!!!" ); + } }