From 64942cbb5e78f570190f570f6811f9d0cd2b6ac1 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 25 Jul 2016 14:09:23 -0400 Subject: [PATCH] Make much of ProtocolLib locale independent Fixes #242 --- .../src/main/java/com/comphenix/protocol/PacketType.java | 3 ++- .../main/java/com/comphenix/protocol/ProtocolConfig.java | 3 ++- .../java/com/comphenix/protocol/wrappers/EnumWrappers.java | 7 ++++--- .../java/com/comphenix/protocol/wrappers/MinecraftKey.java | 5 +++-- .../main/java/com/comphenix/protocol/PacketTypeParser.java | 3 ++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/API/src/main/java/com/comphenix/protocol/PacketType.java b/modules/API/src/main/java/com/comphenix/protocol/PacketType.java index 621037f5..772c8dde 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/PacketType.java +++ b/modules/API/src/main/java/com/comphenix/protocol/PacketType.java @@ -4,6 +4,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.UUID; import java.util.concurrent.Callable; @@ -542,7 +543,7 @@ public class PacketType implements Serializable, Cloneable, Comparable(); for (Particle particle : values()) { - BY_NAME.put(particle.getName().toLowerCase(), particle); + BY_NAME.put(particle.getName().toLowerCase(Locale.ENGLISH), particle); BY_ID.put(particle.getId(), particle); } } @@ -264,7 +265,7 @@ public abstract class EnumWrappers { } public static Particle getByName(String name) { - return BY_NAME.get(name.toLowerCase()); + return BY_NAME.get(name.toLowerCase(Locale.ENGLISH)); } public static Particle getById(int id) { @@ -302,7 +303,7 @@ public abstract class EnumWrappers { } public static SoundCategory getByKey(String key) { - return LOOKUP.get(key.toLowerCase()); + return LOOKUP.get(key.toLowerCase(Locale.ENGLISH)); } } diff --git a/modules/API/src/main/java/com/comphenix/protocol/wrappers/MinecraftKey.java b/modules/API/src/main/java/com/comphenix/protocol/wrappers/MinecraftKey.java index 10cb1362..ba4830c4 100644 --- a/modules/API/src/main/java/com/comphenix/protocol/wrappers/MinecraftKey.java +++ b/modules/API/src/main/java/com/comphenix/protocol/wrappers/MinecraftKey.java @@ -17,6 +17,7 @@ package com.comphenix.protocol.wrappers; import java.lang.reflect.Constructor; +import java.util.Locale; import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.StructureModifier; @@ -70,7 +71,7 @@ public class MinecraftKey { * @return The resulting key */ public static MinecraftKey fromEnum(Enum value) { - return new MinecraftKey(value.name().toLowerCase().replace("_", ".")); + return new MinecraftKey(value.name().toLowerCase(Locale.ENGLISH).replace("_", ".")); } /** @@ -104,7 +105,7 @@ public class MinecraftKey { * @return The enum format */ public String getEnumFormat() { - return key.toUpperCase().replace(".", "_"); + return key.toUpperCase(Locale.ENGLISH).replace(".", "_"); } private static Constructor constructor = null; diff --git a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java index ab95a398..947616ed 100644 --- a/modules/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java +++ b/modules/ProtocolLib/src/main/java/com/comphenix/protocol/PacketTypeParser.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.Deque; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Set; import com.comphenix.protocol.PacketType.Protocol; @@ -53,7 +54,7 @@ class PacketTypeParser { // And finally, parse packet names if we have a protocol if (protocol != null) { for (Iterator it = arguments.iterator(); it.hasNext(); ) { - String name = it.next().toUpperCase(); + String name = it.next().toUpperCase(Locale.ENGLISH); Collection names = PacketType.fromName(name); for (PacketType type : names) {