SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot 2024-06-03 07:18:14 +10:00
parent b0df4fc813
commit a3fb15bc23
23 changed files with 76 additions and 45 deletions

View file

@ -32,6 +32,16 @@
<property name="files" value=".*[\\/]src[\\/]test[\\/].*\.java$"/> <property name="files" value=".*[\\/]src[\\/]test[\\/].*\.java$"/>
</module> </module>
<!-- See SPIGOT-7676: Enforce Locale, to prevent issues with turkish 'I' and similar -->
<module name="RegexpSingleline">
<property name="format" value="\.toUpperCase\(\s*\)" />
<property name="message" value="Use toUpperCase(Locale.ROOT) instead of toUpperCase()" />
</module>
<module name="RegexpSingleline">
<property name="format" value="\.toLowerCase\(\s*\)" />
<property name="message" value="Use toLowerCase(Locale.ROOT) instead of toLowerCase()" />
</module>
<module name="TreeWalker"> <module name="TreeWalker">
<!-- See https://checkstyle.org/config_javadoc.html --> <!-- See https://checkstyle.org/config_javadoc.html -->
<module name="AtclauseOrder"/> <module name="AtclauseOrder"/>

View file

@ -3,6 +3,7 @@ package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -50,7 +51,7 @@ public enum Art implements Keyed {
this.id = id; this.id = id;
this.width = width; this.width = width;
this.height = height; 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) { public static Art getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null"); 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 { static {
for (Art art : values()) { for (Art art : values()) {
BY_ID.put(art.id, art); 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);
} }
} }
} }

View file

@ -3,6 +3,7 @@ package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -428,6 +429,6 @@ public final class Color implements ConfigurationSerializable {
@Override @Override
public String toString() { public String toString() {
return "Color:[argb0x" + Integer.toHexString(asARGB()).toUpperCase() + "]"; return "Color:[argb0x" + Integer.toHexString(asARGB()).toUpperCase(Locale.ROOT) + "]";
} }
} }

View file

@ -4954,7 +4954,7 @@ public enum Material implements Keyed, Translatable {
filtered = filtered.substring((NamespacedKey.MINECRAFT + ":").length()); filtered = filtered.substring((NamespacedKey.MINECRAFT + ":").length());
} }
filtered = filtered.toUpperCase(java.util.Locale.ENGLISH); filtered = filtered.toUpperCase(Locale.ROOT);
filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", ""); filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", "");
return getMaterial(filtered, legacyName); return getMaterial(filtered, legacyName);

View file

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -333,7 +334,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
default T match(@NotNull String input) { default T match(@NotNull String input) {
Preconditions.checkArgument(input != null, "input must not be null"); 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); NamespacedKey namespacedKey = NamespacedKey.fromString(filtered);
return (namespacedKey != null) ? get(namespacedKey) : null; return (namespacedKey != null) ? get(namespacedKey) : null;
} }

View file

@ -5,6 +5,7 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -86,7 +87,7 @@ public @interface Warning {
if (value == null) { if (value == null) {
return DEFAULT; return DEFAULT;
} }
WarningState state = values.get(value.toLowerCase()); WarningState state = values.get(value.toLowerCase(Locale.ROOT));
if (state == null) { if (state == null) {
return DEFAULT; return DEFAULT;
} }

View file

@ -1,6 +1,7 @@
package org.bukkit; package org.bukkit;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -39,7 +40,7 @@ public enum WorldType {
*/ */
@Nullable @Nullable
public static WorldType getByName(@NotNull String name) { 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 { static {

View file

@ -2,6 +2,7 @@ package org.bukkit.attribute;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -159,11 +160,11 @@ public class AttributeModifier implements ConfigurationSerializable {
@NotNull @NotNull
public static AttributeModifier deserialize(@NotNull Map<String, Object> args) { public static AttributeModifier deserialize(@NotNull Map<String, Object> args) {
if (args.containsKey("slot")) { 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) { if (slotGroup == null) {
slotGroup = EquipmentSlotGroup.ANY; 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) { if (slot != null) {
slotGroup = slot.getGroup(); slotGroup = slot.getGroup();
} }

View file

@ -8,6 +8,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
@ -67,8 +68,8 @@ public class SimpleCommandMap implements CommandMap {
*/ */
@Override @Override
public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) { public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) {
label = label.toLowerCase(java.util.Locale.ENGLISH).trim(); label = label.toLowerCase(Locale.ROOT).trim();
fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim(); fallbackPrefix = fallbackPrefix.toLowerCase(Locale.ROOT).trim();
boolean registered = register(label, command, false, fallbackPrefix); boolean registered = register(label, command, false, fallbackPrefix);
Iterator<String> iterator = command.getAliases().iterator(); Iterator<String> iterator = command.getAliases().iterator();
@ -136,7 +137,7 @@ public class SimpleCommandMap implements CommandMap {
return false; return false;
} }
String sentCommandLabel = args[0].toLowerCase(java.util.Locale.ENGLISH); String sentCommandLabel = args[0].toLowerCase(Locale.ROOT);
Command target = getCommand(sentCommandLabel); Command target = getCommand(sentCommandLabel);
if (target == null) { if (target == null) {
@ -168,7 +169,7 @@ public class SimpleCommandMap implements CommandMap {
@Override @Override
@Nullable @Nullable
public Command getCommand(@NotNull String name) { 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; return target;
} }
@ -272,9 +273,9 @@ public class SimpleCommandMap implements CommandMap {
// We register these as commands so they have absolute priority. // We register these as commands so they have absolute priority.
if (targets.size() > 0) { 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 { } else {
knownCommands.remove(alias.toLowerCase(java.util.Locale.ENGLISH)); knownCommands.remove(alias.toLowerCase(Locale.ROOT));
} }
} }
} }

View file

@ -15,6 +15,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -61,9 +62,9 @@ public class VersionCommand extends BukkitCommand {
} }
boolean found = false; boolean found = false;
pluginName = pluginName.toLowerCase(java.util.Locale.ENGLISH); pluginName = pluginName.toLowerCase(Locale.ROOT);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { 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); describeToSender(plugin, sender);
found = true; found = true;
} }
@ -133,7 +134,7 @@ public class VersionCommand extends BukkitCommand {
if (args.length == 1) { if (args.length == 1) {
List<String> completions = new ArrayList<String>(); List<String> completions = new ArrayList<String>();
String toComplete = args[0].toLowerCase(java.util.Locale.ENGLISH); String toComplete = args[0].toLowerCase(Locale.ROOT);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) { if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
completions.add(plugin.getName()); completions.add(plugin.getName());

View file

@ -2,6 +2,7 @@ package org.bukkit.enchantments;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Locale;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.MinecraftExperimental; import org.bukkit.MinecraftExperimental;
import org.bukkit.MinecraftExperimental.Requires; import org.bukkit.MinecraftExperimental.Requires;
@ -351,7 +352,7 @@ public abstract class Enchantment implements Keyed, Translatable {
return null; return null;
} }
return getByKey(NamespacedKey.fromString(name.toLowerCase())); return getByKey(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
} }
/** /**

View file

@ -2,6 +2,7 @@ package org.bukkit.entity;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Keyed; import org.bukkit.Keyed;
@ -331,7 +332,7 @@ public enum EntityType implements Keyed, Translatable {
static { static {
for (EntityType type : values()) { for (EntityType type : values()) {
if (type.name != null) { 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) { if (type.typeId > 0) {
ID_MAP.put(type.typeId, type); ID_MAP.put(type.typeId, type);
@ -402,7 +403,7 @@ public enum EntityType implements Keyed, Translatable {
if (name == null) { if (name == null) {
return null; return null;
} }
return NAME_MAP.get(name.toLowerCase(java.util.Locale.ENGLISH)); return NAME_MAP.get(name.toLowerCase(Locale.ROOT));
} }
/** /**

View file

@ -2,6 +2,7 @@ package org.bukkit.inventory;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@ -73,7 +74,7 @@ public final class EquipmentSlotGroup implements Predicate<EquipmentSlot> {
public static EquipmentSlotGroup getByName(@NotNull String name) { public static EquipmentSlotGroup getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null"); 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) { private static EquipmentSlotGroup get(@NotNull String key, @NotNull EquipmentSlot slot) {

View file

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -52,7 +53,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); 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 @Override
@ -70,7 +71,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); 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)) { if (isPermissionSet(name)) {
return permissions.get(name).getValue(); return permissions.get(name).getValue();
@ -91,7 +92,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission cannot be null"); 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)) { if (isPermissionSet(name)) {
return permissions.get(name).getValue(); return permissions.get(name).getValue();
@ -161,7 +162,7 @@ public class PermissibleBase implements Permissible {
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
for (Permission perm : defaults) { 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)); permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
calculateChildPermissions(perm.getChildren(), false, null); calculateChildPermissions(perm.getChildren(), false, null);
@ -191,7 +192,7 @@ public class PermissibleBase implements Permissible {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name); Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
boolean value = entry.getValue() ^ invert; 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)); permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);

View file

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -186,7 +187,7 @@ public class Permission {
@NotNull @NotNull
public Permission addParent(@NotNull String name, boolean value) { public Permission addParent(@NotNull String name, boolean value) {
PluginManager pm = Bukkit.getServer().getPluginManager(); PluginManager pm = Bukkit.getServer().getPluginManager();
String lname = name.toLowerCase(java.util.Locale.ENGLISH); String lname = name.toLowerCase(Locale.ROOT);
Permission perm = pm.getPermission(lname); Permission perm = pm.getPermission(lname);

View file

@ -1,6 +1,7 @@
package org.bukkit.permissions; package org.bukkit.permissions;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -89,7 +90,7 @@ public class PermissionAttachment {
* @param value New value of the permission * @param value New value of the permission
*/ */
public void setPermission(@NotNull String name, boolean value) { 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(); permissible.recalculatePermissions();
} }
@ -112,7 +113,7 @@ public class PermissionAttachment {
* @param name Name of the permission to remove * @param name Name of the permission to remove
*/ */
public void unsetPermission(@NotNull String name) { public void unsetPermission(@NotNull String name) {
permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH)); permissions.remove(name.toLowerCase(Locale.ROOT));
permissible.recalculatePermissions(); permissible.recalculatePermissions();
} }

View file

@ -1,6 +1,7 @@
package org.bukkit.permissions; package org.bukkit.permissions;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -51,7 +52,7 @@ public enum PermissionDefault {
*/ */
@Nullable @Nullable
public static PermissionDefault getByName(@NotNull String name) { 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 @Override

View file

@ -9,6 +9,7 @@ import java.io.Writer;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -1086,7 +1087,7 @@ public final class PluginDescriptionFile {
if (map.get("load") != null) { if (map.get("load") != null) {
try { 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) { } catch (ClassCastException ex) {
throw new InvalidDescriptionException(ex, "load is of wrong type"); throw new InvalidDescriptionException(ex, "load is of wrong type");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {

View file

@ -18,6 +18,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
@ -698,7 +699,7 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
@Nullable @Nullable
public Permission getPermission(@NotNull String name) { public Permission getPermission(@NotNull String name) {
return permissions.get(name.toLowerCase(java.util.Locale.ENGLISH)); return permissions.get(name.toLowerCase(Locale.ROOT));
} }
@Override @Override
@ -708,7 +709,7 @@ public final class SimplePluginManager implements PluginManager {
@Deprecated @Deprecated
public void addPermission(@NotNull Permission perm, boolean dirty) { 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)) { if (permissions.containsKey(name)) {
throw new IllegalArgumentException("The permission " + name + " is already defined!"); throw new IllegalArgumentException("The permission " + name + " is already defined!");
@ -731,12 +732,12 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
public void removePermission(@NotNull String name) { public void removePermission(@NotNull String name) {
permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH)); permissions.remove(name.toLowerCase(Locale.ROOT));
} }
@Override @Override
public void recalculatePermissionDefaults(@NotNull Permission perm) { 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(true).remove(perm);
defaultPerms.get(false).remove(perm); defaultPerms.get(false).remove(perm);
@ -775,7 +776,7 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
public void subscribeToPermission(@NotNull String permission, @NotNull Permissible permissible) { public void subscribeToPermission(@NotNull String permission, @NotNull Permissible permissible) {
String name = permission.toLowerCase(java.util.Locale.ENGLISH); String name = permission.toLowerCase(Locale.ROOT);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) { if (map == null) {
@ -788,7 +789,7 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
public void unsubscribeFromPermission(@NotNull String permission, @NotNull Permissible permissible) { public void unsubscribeFromPermission(@NotNull String permission, @NotNull Permissible permissible) {
String name = permission.toLowerCase(java.util.Locale.ENGLISH); String name = permission.toLowerCase(Locale.ROOT);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map != null) { if (map != null) {
@ -803,7 +804,7 @@ public final class SimplePluginManager implements PluginManager {
@Override @Override
@NotNull @NotNull
public Set<Permissible> getPermissionSubscriptions(@NotNull String permission) { public Set<Permissible> getPermissionSubscriptions(@NotNull String permission) {
String name = permission.toLowerCase(java.util.Locale.ENGLISH); String name = permission.toLowerCase(Locale.ROOT);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) { if (map == null) {

View file

@ -12,6 +12,7 @@ import java.io.Reader;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.Server;
@ -309,11 +310,11 @@ public abstract class JavaPlugin extends PluginBase {
*/ */
@Nullable @Nullable
public PluginCommand getCommand(@NotNull String name) { 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); PluginCommand command = getServer().getPluginCommand(alias);
if (command == null || command.getPlugin() != this) { 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) { if (command != null && command.getPlugin() == this) {

View file

@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.Locale;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -348,7 +349,7 @@ public abstract class PotionEffectType implements Keyed, Translatable {
@Deprecated @Deprecated
public static PotionEffectType getByName(@NotNull String name) { public static PotionEffectType getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "name cannot be null"); 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)));
} }
/** /**

View file

@ -3,6 +3,7 @@ package org.bukkit;
import static org.bukkit.support.MatcherAssert.*; import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Locale;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -31,7 +32,7 @@ public class ColorTest {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; 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);
} }
} }

View file

@ -3,6 +3,7 @@ package org.bukkit;
import static org.bukkit.support.MatcherAssert.*; import static org.bukkit.support.MatcherAssert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import java.util.Locale;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -66,7 +67,7 @@ public class MaterialTest {
@Test @Test
public void matchMaterialByLowerCaseAndSpaces() { public void matchMaterialByLowerCaseAndSpaces() {
for (Material material : Material.values()) { 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)); assertThat(Material.matchMaterial(name), is(material));
} }
} }