From a3fb15bc23e325efb240c8dafad167105bfa76b6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Mon, 3 Jun 2024 07:18:14 +1000 Subject: [PATCH] SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale By: DerFrZocker --- paper-api/checkstyle.xml | 10 ++++++++++ paper-api/src/main/java/org/bukkit/Art.java | 7 ++++--- paper-api/src/main/java/org/bukkit/Color.java | 3 ++- paper-api/src/main/java/org/bukkit/Material.java | 2 +- paper-api/src/main/java/org/bukkit/Registry.java | 3 ++- paper-api/src/main/java/org/bukkit/Warning.java | 3 ++- paper-api/src/main/java/org/bukkit/WorldType.java | 3 ++- .../org/bukkit/attribute/AttributeModifier.java | 5 +++-- .../java/org/bukkit/command/SimpleCommandMap.java | 13 +++++++------ .../bukkit/command/defaults/VersionCommand.java | 7 ++++--- .../java/org/bukkit/enchantments/Enchantment.java | 3 ++- .../main/java/org/bukkit/entity/EntityType.java | 5 +++-- .../org/bukkit/inventory/EquipmentSlotGroup.java | 3 ++- .../org/bukkit/permissions/PermissibleBase.java | 11 ++++++----- .../java/org/bukkit/permissions/Permission.java | 3 ++- .../bukkit/permissions/PermissionAttachment.java | 5 +++-- .../org/bukkit/permissions/PermissionDefault.java | 3 ++- .../org/bukkit/plugin/PluginDescriptionFile.java | 3 ++- .../org/bukkit/plugin/SimplePluginManager.java | 15 ++++++++------- .../java/org/bukkit/plugin/java/JavaPlugin.java | 5 +++-- .../java/org/bukkit/potion/PotionEffectType.java | 3 ++- paper-api/src/test/java/org/bukkit/ColorTest.java | 3 ++- .../src/test/java/org/bukkit/MaterialTest.java | 3 ++- 23 files changed, 76 insertions(+), 45 deletions(-) diff --git a/paper-api/checkstyle.xml b/paper-api/checkstyle.xml index 4b26154353..118f0e3f11 100644 --- a/paper-api/checkstyle.xml +++ b/paper-api/checkstyle.xml @@ -32,6 +32,16 @@ + + + + + + + + + + diff --git a/paper-api/src/main/java/org/bukkit/Art.java b/paper-api/src/main/java/org/bukkit/Art.java index ac420f0059..0c20c6bf44 100644 --- a/paper-api/src/main/java/org/bukkit/Art.java +++ b/paper-api/src/main/java/org/bukkit/Art.java @@ -3,6 +3,7 @@ package org.bukkit; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import java.util.HashMap; +import java.util.Locale; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +51,7 @@ public enum Art implements Keyed { this.id = id; this.width = width; this.height = height; - this.key = NamespacedKey.minecraft(name().toLowerCase(java.util.Locale.ENGLISH)); + this.key = NamespacedKey.minecraft(name().toLowerCase(Locale.ROOT)); } /** @@ -113,13 +114,13 @@ public enum Art implements Keyed { public static Art getByName(@NotNull String name) { Preconditions.checkArgument(name != null, "Name cannot be null"); - return BY_NAME.get(name.toLowerCase(java.util.Locale.ENGLISH)); + return BY_NAME.get(name.toLowerCase(Locale.ROOT)); } static { for (Art art : values()) { BY_ID.put(art.id, art); - BY_NAME.put(art.toString().toLowerCase(java.util.Locale.ENGLISH), art); + BY_NAME.put(art.toString().toLowerCase(Locale.ROOT), art); } } } diff --git a/paper-api/src/main/java/org/bukkit/Color.java b/paper-api/src/main/java/org/bukkit/Color.java index e088390ec3..f8edb964c4 100644 --- a/paper-api/src/main/java/org/bukkit/Color.java +++ b/paper-api/src/main/java/org/bukkit/Color.java @@ -3,6 +3,7 @@ package org.bukkit; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.Arrays; +import java.util.Locale; import java.util.Map; import java.util.Objects; import org.bukkit.configuration.serialization.ConfigurationSerializable; @@ -428,6 +429,6 @@ public final class Color implements ConfigurationSerializable { @Override public String toString() { - return "Color:[argb0x" + Integer.toHexString(asARGB()).toUpperCase() + "]"; + return "Color:[argb0x" + Integer.toHexString(asARGB()).toUpperCase(Locale.ROOT) + "]"; } } diff --git a/paper-api/src/main/java/org/bukkit/Material.java b/paper-api/src/main/java/org/bukkit/Material.java index 0a5dfd728a..da961703ba 100644 --- a/paper-api/src/main/java/org/bukkit/Material.java +++ b/paper-api/src/main/java/org/bukkit/Material.java @@ -4954,7 +4954,7 @@ public enum Material implements Keyed, Translatable { filtered = filtered.substring((NamespacedKey.MINECRAFT + ":").length()); } - filtered = filtered.toUpperCase(java.util.Locale.ENGLISH); + filtered = filtered.toUpperCase(Locale.ROOT); filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", ""); return getMaterial(filtered, legacyName); diff --git a/paper-api/src/main/java/org/bukkit/Registry.java b/paper-api/src/main/java/org/bukkit/Registry.java index 57dfc408fc..e723bafe37 100644 --- a/paper-api/src/main/java/org/bukkit/Registry.java +++ b/paper-api/src/main/java/org/bukkit/Registry.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.function.Predicate; @@ -333,7 +334,7 @@ public interface Registry extends Iterable { default T match(@NotNull String input) { Preconditions.checkArgument(input != null, "input must not be null"); - String filtered = input.toLowerCase().replaceAll("\\s+", "_"); + String filtered = input.toLowerCase(Locale.ROOT).replaceAll("\\s+", "_"); NamespacedKey namespacedKey = NamespacedKey.fromString(filtered); return (namespacedKey != null) ? get(namespacedKey) : null; } diff --git a/paper-api/src/main/java/org/bukkit/Warning.java b/paper-api/src/main/java/org/bukkit/Warning.java index efb97712cc..0208fc2bcd 100644 --- a/paper-api/src/main/java/org/bukkit/Warning.java +++ b/paper-api/src/main/java/org/bukkit/Warning.java @@ -5,6 +5,7 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.Locale; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -86,7 +87,7 @@ public @interface Warning { if (value == null) { return DEFAULT; } - WarningState state = values.get(value.toLowerCase()); + WarningState state = values.get(value.toLowerCase(Locale.ROOT)); if (state == null) { return DEFAULT; } diff --git a/paper-api/src/main/java/org/bukkit/WorldType.java b/paper-api/src/main/java/org/bukkit/WorldType.java index c48b5579f7..652b75bb65 100644 --- a/paper-api/src/main/java/org/bukkit/WorldType.java +++ b/paper-api/src/main/java/org/bukkit/WorldType.java @@ -1,6 +1,7 @@ package org.bukkit; import com.google.common.collect.Maps; +import java.util.Locale; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +40,7 @@ public enum WorldType { */ @Nullable public static WorldType getByName(@NotNull String name) { - return BY_NAME.get(name.toUpperCase(java.util.Locale.ENGLISH)); + return BY_NAME.get(name.toUpperCase(Locale.ROOT)); } static { diff --git a/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java b/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java index 8ba00f743b..9b47cbb933 100644 --- a/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java +++ b/paper-api/src/main/java/org/bukkit/attribute/AttributeModifier.java @@ -2,6 +2,7 @@ package org.bukkit.attribute; import com.google.common.base.Preconditions; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -159,11 +160,11 @@ public class AttributeModifier implements ConfigurationSerializable { @NotNull public static AttributeModifier deserialize(@NotNull Map args) { if (args.containsKey("slot")) { - EquipmentSlotGroup slotGroup = EquipmentSlotGroup.getByName(args.get("slot").toString().toLowerCase()); + EquipmentSlotGroup slotGroup = EquipmentSlotGroup.getByName(args.get("slot").toString().toLowerCase(Locale.ROOT)); if (slotGroup == null) { slotGroup = EquipmentSlotGroup.ANY; - EquipmentSlot slot = EquipmentSlot.valueOf((args.get("slot").toString().toUpperCase())); + EquipmentSlot slot = EquipmentSlot.valueOf((args.get("slot").toString().toUpperCase(Locale.ROOT))); if (slot != null) { slotGroup = slot.getGroup(); } diff --git a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java b/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java index 73906146e8..c399c14977 100644 --- a/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java +++ b/paper-api/src/main/java/org/bukkit/command/SimpleCommandMap.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import org.bukkit.Location; import org.bukkit.Server; @@ -67,8 +68,8 @@ public class SimpleCommandMap implements CommandMap { */ @Override public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) { - label = label.toLowerCase(java.util.Locale.ENGLISH).trim(); - fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim(); + label = label.toLowerCase(Locale.ROOT).trim(); + fallbackPrefix = fallbackPrefix.toLowerCase(Locale.ROOT).trim(); boolean registered = register(label, command, false, fallbackPrefix); Iterator iterator = command.getAliases().iterator(); @@ -136,7 +137,7 @@ public class SimpleCommandMap implements CommandMap { return false; } - String sentCommandLabel = args[0].toLowerCase(java.util.Locale.ENGLISH); + String sentCommandLabel = args[0].toLowerCase(Locale.ROOT); Command target = getCommand(sentCommandLabel); if (target == null) { @@ -168,7 +169,7 @@ public class SimpleCommandMap implements CommandMap { @Override @Nullable public Command getCommand(@NotNull String name) { - Command target = knownCommands.get(name.toLowerCase(java.util.Locale.ENGLISH)); + Command target = knownCommands.get(name.toLowerCase(Locale.ROOT)); return target; } @@ -272,9 +273,9 @@ public class SimpleCommandMap implements CommandMap { // We register these as commands so they have absolute priority. if (targets.size() > 0) { - knownCommands.put(alias.toLowerCase(java.util.Locale.ENGLISH), new FormattedCommandAlias(alias.toLowerCase(java.util.Locale.ENGLISH), targets.toArray(new String[targets.size()]))); + knownCommands.put(alias.toLowerCase(Locale.ROOT), new FormattedCommandAlias(alias.toLowerCase(Locale.ROOT), targets.toArray(new String[targets.size()]))); } else { - knownCommands.remove(alias.toLowerCase(java.util.Locale.ENGLISH)); + knownCommands.remove(alias.toLowerCase(Locale.ROOT)); } } } diff --git a/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java index 04b4fb6859..263208d3cb 100644 --- a/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java +++ b/paper-api/src/main/java/org/bukkit/command/defaults/VersionCommand.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; import org.bukkit.Bukkit; @@ -61,9 +62,9 @@ public class VersionCommand extends BukkitCommand { } boolean found = false; - pluginName = pluginName.toLowerCase(java.util.Locale.ENGLISH); + pluginName = pluginName.toLowerCase(Locale.ROOT); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - if (plugin.getName().toLowerCase(java.util.Locale.ENGLISH).contains(pluginName)) { + if (plugin.getName().toLowerCase(Locale.ROOT).contains(pluginName)) { describeToSender(plugin, sender); found = true; } @@ -133,7 +134,7 @@ public class VersionCommand extends BukkitCommand { if (args.length == 1) { List completions = new ArrayList(); - String toComplete = args[0].toLowerCase(java.util.Locale.ENGLISH); + String toComplete = args[0].toLowerCase(Locale.ROOT); for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) { completions.add(plugin.getName()); diff --git a/paper-api/src/main/java/org/bukkit/enchantments/Enchantment.java b/paper-api/src/main/java/org/bukkit/enchantments/Enchantment.java index 18983f405b..f52cff3abc 100644 --- a/paper-api/src/main/java/org/bukkit/enchantments/Enchantment.java +++ b/paper-api/src/main/java/org/bukkit/enchantments/Enchantment.java @@ -2,6 +2,7 @@ package org.bukkit.enchantments; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import java.util.Locale; import org.bukkit.Keyed; import org.bukkit.MinecraftExperimental; import org.bukkit.MinecraftExperimental.Requires; @@ -351,7 +352,7 @@ public abstract class Enchantment implements Keyed, Translatable { return null; } - return getByKey(NamespacedKey.fromString(name.toLowerCase())); + return getByKey(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); } /** diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index c308f6a9f3..19705de005 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -2,6 +2,7 @@ package org.bukkit.entity; import com.google.common.base.Preconditions; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Keyed; @@ -331,7 +332,7 @@ public enum EntityType implements Keyed, Translatable { static { for (EntityType type : values()) { if (type.name != null) { - NAME_MAP.put(type.name.toLowerCase(java.util.Locale.ENGLISH), type); + NAME_MAP.put(type.name.toLowerCase(Locale.ROOT), type); } if (type.typeId > 0) { ID_MAP.put(type.typeId, type); @@ -402,7 +403,7 @@ public enum EntityType implements Keyed, Translatable { if (name == null) { return null; } - return NAME_MAP.get(name.toLowerCase(java.util.Locale.ENGLISH)); + return NAME_MAP.get(name.toLowerCase(Locale.ROOT)); } /** diff --git a/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java b/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java index 82416a078f..0019c8d91e 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java +++ b/paper-api/src/main/java/org/bukkit/inventory/EquipmentSlotGroup.java @@ -2,6 +2,7 @@ package org.bukkit.inventory; import com.google.common.base.Preconditions; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.function.Predicate; import org.jetbrains.annotations.ApiStatus; @@ -73,7 +74,7 @@ public final class EquipmentSlotGroup implements Predicate { public static EquipmentSlotGroup getByName(@NotNull String name) { Preconditions.checkArgument(name != null, "Name cannot be null"); - return BY_NAME.get(name.toLowerCase(java.util.Locale.ENGLISH)); + return BY_NAME.get(name.toLowerCase(Locale.ROOT)); } private static EquipmentSlotGroup get(@NotNull String key, @NotNull EquipmentSlot slot) { diff --git a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java index 728fc46daf..d0fd41a0dd 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java +++ b/paper-api/src/main/java/org/bukkit/permissions/PermissibleBase.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -52,7 +53,7 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission name cannot be null"); } - return permissions.containsKey(name.toLowerCase(java.util.Locale.ENGLISH)); + return permissions.containsKey(name.toLowerCase(Locale.ROOT)); } @Override @@ -70,7 +71,7 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission name cannot be null"); } - String name = inName.toLowerCase(java.util.Locale.ENGLISH); + String name = inName.toLowerCase(Locale.ROOT); if (isPermissionSet(name)) { return permissions.get(name).getValue(); @@ -91,7 +92,7 @@ public class PermissibleBase implements Permissible { throw new IllegalArgumentException("Permission cannot be null"); } - String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH); + String name = perm.getName().toLowerCase(Locale.ROOT); if (isPermissionSet(name)) { return permissions.get(name).getValue(); @@ -161,7 +162,7 @@ public class PermissibleBase implements Permissible { Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); for (Permission perm : defaults) { - String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH); + String name = perm.getName().toLowerCase(Locale.ROOT); permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true)); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); calculateChildPermissions(perm.getChildren(), false, null); @@ -191,7 +192,7 @@ public class PermissibleBase implements Permissible { Permission perm = Bukkit.getServer().getPluginManager().getPermission(name); boolean value = entry.getValue() ^ invert; - String lname = name.toLowerCase(java.util.Locale.ENGLISH); + String lname = name.toLowerCase(Locale.ROOT); permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value)); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); diff --git a/paper-api/src/main/java/org/bukkit/permissions/Permission.java b/paper-api/src/main/java/org/bukkit/permissions/Permission.java index 894f07b91d..54a9bb696c 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/Permission.java +++ b/paper-api/src/main/java/org/bukkit/permissions/Permission.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -186,7 +187,7 @@ public class Permission { @NotNull public Permission addParent(@NotNull String name, boolean value) { PluginManager pm = Bukkit.getServer().getPluginManager(); - String lname = name.toLowerCase(java.util.Locale.ENGLISH); + String lname = name.toLowerCase(Locale.ROOT); Permission perm = pm.getPermission(lname); diff --git a/paper-api/src/main/java/org/bukkit/permissions/PermissionAttachment.java b/paper-api/src/main/java/org/bukkit/permissions/PermissionAttachment.java index cd8ac371a1..b36bde6a67 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/PermissionAttachment.java +++ b/paper-api/src/main/java/org/bukkit/permissions/PermissionAttachment.java @@ -1,6 +1,7 @@ package org.bukkit.permissions; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; @@ -89,7 +90,7 @@ public class PermissionAttachment { * @param value New value of the permission */ public void setPermission(@NotNull String name, boolean value) { - permissions.put(name.toLowerCase(java.util.Locale.ENGLISH), value); + permissions.put(name.toLowerCase(Locale.ROOT), value); permissible.recalculatePermissions(); } @@ -112,7 +113,7 @@ public class PermissionAttachment { * @param name Name of the permission to remove */ public void unsetPermission(@NotNull String name) { - permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH)); + permissions.remove(name.toLowerCase(Locale.ROOT)); permissible.recalculatePermissions(); } diff --git a/paper-api/src/main/java/org/bukkit/permissions/PermissionDefault.java b/paper-api/src/main/java/org/bukkit/permissions/PermissionDefault.java index 449df7c798..7a85f97d86 100644 --- a/paper-api/src/main/java/org/bukkit/permissions/PermissionDefault.java +++ b/paper-api/src/main/java/org/bukkit/permissions/PermissionDefault.java @@ -1,6 +1,7 @@ package org.bukkit.permissions; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,7 +52,7 @@ public enum PermissionDefault { */ @Nullable public static PermissionDefault getByName(@NotNull String name) { - return lookup.get(name.toLowerCase(java.util.Locale.ENGLISH).replaceAll("[^a-z!]", "")); + return lookup.get(name.toLowerCase(Locale.ROOT).replaceAll("[^a-z!]", "")); } @Override diff --git a/paper-api/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java b/paper-api/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java index f48bdeb628..8e44f7eaf9 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java +++ b/paper-api/src/main/java/org/bukkit/plugin/PluginDescriptionFile.java @@ -9,6 +9,7 @@ import java.io.Writer; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; @@ -1086,7 +1087,7 @@ public final class PluginDescriptionFile { if (map.get("load") != null) { try { - order = PluginLoadOrder.valueOf(((String) map.get("load")).toUpperCase(java.util.Locale.ENGLISH).replaceAll("\\W", "")); + order = PluginLoadOrder.valueOf(((String) map.get("load")).toUpperCase(Locale.ROOT).replaceAll("\\W", "")); } catch (ClassCastException ex) { throw new InvalidDescriptionException(ex, "load is of wrong type"); } catch (IllegalArgumentException ex) { diff --git a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java index 6fac84b3a6..04dda4d227 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/paper-api/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -18,6 +18,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; @@ -698,7 +699,7 @@ public final class SimplePluginManager implements PluginManager { @Override @Nullable public Permission getPermission(@NotNull String name) { - return permissions.get(name.toLowerCase(java.util.Locale.ENGLISH)); + return permissions.get(name.toLowerCase(Locale.ROOT)); } @Override @@ -708,7 +709,7 @@ public final class SimplePluginManager implements PluginManager { @Deprecated public void addPermission(@NotNull Permission perm, boolean dirty) { - String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH); + String name = perm.getName().toLowerCase(Locale.ROOT); if (permissions.containsKey(name)) { throw new IllegalArgumentException("The permission " + name + " is already defined!"); @@ -731,12 +732,12 @@ public final class SimplePluginManager implements PluginManager { @Override public void removePermission(@NotNull String name) { - permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH)); + permissions.remove(name.toLowerCase(Locale.ROOT)); } @Override public void recalculatePermissionDefaults(@NotNull Permission perm) { - if (perm != null && permissions.containsKey(perm.getName().toLowerCase(java.util.Locale.ENGLISH))) { + if (perm != null && permissions.containsKey(perm.getName().toLowerCase(Locale.ROOT))) { defaultPerms.get(true).remove(perm); defaultPerms.get(false).remove(perm); @@ -775,7 +776,7 @@ public final class SimplePluginManager implements PluginManager { @Override public void subscribeToPermission(@NotNull String permission, @NotNull Permissible permissible) { - String name = permission.toLowerCase(java.util.Locale.ENGLISH); + String name = permission.toLowerCase(Locale.ROOT); Map map = permSubs.get(name); if (map == null) { @@ -788,7 +789,7 @@ public final class SimplePluginManager implements PluginManager { @Override public void unsubscribeFromPermission(@NotNull String permission, @NotNull Permissible permissible) { - String name = permission.toLowerCase(java.util.Locale.ENGLISH); + String name = permission.toLowerCase(Locale.ROOT); Map map = permSubs.get(name); if (map != null) { @@ -803,7 +804,7 @@ public final class SimplePluginManager implements PluginManager { @Override @NotNull public Set getPermissionSubscriptions(@NotNull String permission) { - String name = permission.toLowerCase(java.util.Locale.ENGLISH); + String name = permission.toLowerCase(Locale.ROOT); Map map = permSubs.get(name); if (map == null) { diff --git a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java index ee100b7ad8..7fca39df00 100644 --- a/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java +++ b/paper-api/src/main/java/org/bukkit/plugin/java/JavaPlugin.java @@ -12,6 +12,7 @@ import java.io.Reader; import java.net.URL; import java.net.URLConnection; import java.util.List; +import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Server; @@ -309,11 +310,11 @@ public abstract class JavaPlugin extends PluginBase { */ @Nullable public PluginCommand getCommand(@NotNull String name) { - String alias = name.toLowerCase(java.util.Locale.ENGLISH); + String alias = name.toLowerCase(Locale.ROOT); PluginCommand command = getServer().getPluginCommand(alias); if (command == null || command.getPlugin() != this) { - command = getServer().getPluginCommand(description.getName().toLowerCase(java.util.Locale.ENGLISH) + ":" + alias); + command = getServer().getPluginCommand(description.getName().toLowerCase(Locale.ROOT) + ":" + alias); } if (command != null && command.getPlugin() == this) { diff --git a/paper-api/src/main/java/org/bukkit/potion/PotionEffectType.java b/paper-api/src/main/java/org/bukkit/potion/PotionEffectType.java index 8b4032c82a..6bbfebab2e 100644 --- a/paper-api/src/main/java/org/bukkit/potion/PotionEffectType.java +++ b/paper-api/src/main/java/org/bukkit/potion/PotionEffectType.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Lists; +import java.util.Locale; import org.bukkit.Color; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; @@ -348,7 +349,7 @@ public abstract class PotionEffectType implements Keyed, Translatable { @Deprecated public static PotionEffectType getByName(@NotNull String name) { Preconditions.checkArgument(name != null, "name cannot be null"); - return Registry.EFFECT.get(NamespacedKey.fromString(name.toLowerCase(java.util.Locale.ENGLISH))); + return Registry.EFFECT.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); } /** diff --git a/paper-api/src/test/java/org/bukkit/ColorTest.java b/paper-api/src/test/java/org/bukkit/ColorTest.java index f29fd7bc65..37481403e8 100644 --- a/paper-api/src/test/java/org/bukkit/ColorTest.java +++ b/paper-api/src/test/java/org/bukkit/ColorTest.java @@ -3,6 +3,7 @@ package org.bukkit; import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; +import java.util.Locale; import org.bukkit.configuration.file.YamlConfiguration; import org.junit.jupiter.api.Test; @@ -31,7 +32,7 @@ public class ColorTest { this.r = r; this.g = g; this.b = b; - this.name = id + ":" + Integer.toHexString(argb).toUpperCase() + "_" + Integer.toHexString(rgb).toUpperCase() + "_" + Integer.toHexString(bgr).toUpperCase() + "-a" + Integer.toHexString(a).toUpperCase() + "-r" + Integer.toHexString(r).toUpperCase() + "-g" + Integer.toHexString(g).toUpperCase() + "-b" + Integer.toHexString(b).toUpperCase(); + this.name = id + ":" + Integer.toHexString(argb).toUpperCase(Locale.ROOT) + "_" + Integer.toHexString(rgb).toUpperCase(Locale.ROOT) + "_" + Integer.toHexString(bgr).toUpperCase(Locale.ROOT) + "-a" + Integer.toHexString(a).toUpperCase(Locale.ROOT) + "-r" + Integer.toHexString(r).toUpperCase(Locale.ROOT) + "-g" + Integer.toHexString(g).toUpperCase(Locale.ROOT) + "-b" + Integer.toHexString(b).toUpperCase(Locale.ROOT); } } diff --git a/paper-api/src/test/java/org/bukkit/MaterialTest.java b/paper-api/src/test/java/org/bukkit/MaterialTest.java index 818aa21d3b..f295c11383 100644 --- a/paper-api/src/test/java/org/bukkit/MaterialTest.java +++ b/paper-api/src/test/java/org/bukkit/MaterialTest.java @@ -3,6 +3,7 @@ package org.bukkit; import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; +import java.util.Locale; import org.bukkit.material.MaterialData; import org.junit.jupiter.api.Test; @@ -66,7 +67,7 @@ public class MaterialTest { @Test public void matchMaterialByLowerCaseAndSpaces() { for (Material material : Material.values()) { - String name = material.toString().replaceAll("_", " ").toLowerCase(java.util.Locale.ENGLISH); + String name = material.toString().replaceAll("_", " ").toLowerCase(Locale.ROOT); assertThat(Material.matchMaterial(name), is(material)); } }