From cafd4bfece0b4c710159b9d67e1a148621cf3912 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 10 Jul 2019 22:26:31 +1000 Subject: [PATCH] use Locale.ROOT for uppercase as well --- .../fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java | 3 ++- .../java/com/sk89q/worldedit/bukkit/BukkitEntity.java | 3 ++- .../java/com/sk89q/worldedit/bukkit/BukkitPlayer.java | 3 ++- .../com/sk89q/worldedit/bukkit/WorldEditPlugin.java | 2 +- .../worldedit/bukkit/adapter/IBukkitAdapter.java | 6 +++--- .../extension/factory/parser/DefaultBlockParser.java | 10 +++++----- .../parser/pattern/BlockCategoryPatternParser.java | 3 ++- .../factory/parser/pattern/DefaultPatternParser.java | 3 ++- .../extent/transform/BlockTransformExtent.java | 11 ++++++----- .../sk89q/worldedit/registry/state/PropertyKey.java | 3 ++- .../worldedit/util/command/SimpleDispatcher.java | 5 +++-- .../util/command/argument/ArgumentUtils.java | 3 ++- .../util/command/composition/BranchingCommand.java | 5 +++-- .../util/command/parametric/ParametricCallable.java | 5 +++-- .../com/sk89q/worldedit/world/block/BlockTypes.java | 2 +- .../com/sk89q/worldedit/world/entity/EntityTypes.java | 3 ++- .../com/sk89q/worldedit/world/item/ItemTypes.java | 3 ++- 17 files changed, 43 insertions(+), 30 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java index d16684bcd..c0ec1e082 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java @@ -64,6 +64,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.function.Supplier; @@ -365,7 +366,7 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit property = new BooleanProperty(state.a(), ImmutableList.copyOf(state.d())); } else if (state instanceof BlockStateDirection) { property = new DirectionalProperty(state.a(), - (List) state.d().stream().map(e -> Direction.valueOf(((INamable) e).getName().toUpperCase())).collect(Collectors.toList())); + (List) state.d().stream().map(e -> Direction.valueOf(((INamable) e).getName().toUpperCase(Locale.ROOT))).collect(Collectors.toList())); } else if (state instanceof BlockStateEnum) { property = new EnumProperty(state.a(), (List) state.d().stream().map(e -> ((INamable) e).getName()).collect(Collectors.toList())); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java index 5ac3b1893..d21ddcd4c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitEntity.java @@ -34,6 +34,7 @@ import com.sk89q.worldedit.world.entity.EntityTypes; import org.bukkit.entity.EntityType; import java.lang.ref.WeakReference; +import java.util.Locale; import javax.annotation.Nullable; @@ -88,7 +89,7 @@ public class BukkitEntity implements Entity { @Override public com.sk89q.worldedit.world.entity.EntityType getType() { - return EntityTypes.get(type.getName().toUpperCase()); + return EntityTypes.get(type.getName().toUpperCase(Locale.ROOT)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 9b25740c6..d926d07fa 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -53,6 +53,7 @@ import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.UUID; @@ -185,7 +186,7 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public GameMode getGameMode() { - return GameModes.get(player.getGameMode().name().toLowerCase()); + return GameModes.get(player.getGameMode().name().toLowerCase(Locale.ROOT)); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index ee7bf48cf..f822e493c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -210,7 +210,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter public void setupRegistries() { // Biome for (Biome biome : Biome.values()) { - BiomeType.REGISTRY.register("minecraft:" + biome.name().toLowerCase(), new BiomeType("minecraft:" + biome.name().toLowerCase())); + BiomeType.REGISTRY.register("minecraft:" + biome.name().toLowerCase(Locale.ROOT), new BiomeType("minecraft:" + biome.name().toLowerCase(Locale.ROOT))); } // Block & Item for (Material material : Material.values()) { diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java index 6ae11c23a..194ccc2c6 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java @@ -207,7 +207,7 @@ public interface IBukkitAdapter { if (!itemType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft items"); } - return Material.getMaterial(itemType.getId().substring(10).toUpperCase()); + return Material.getMaterial(itemType.getId().substring(10).toUpperCase(Locale.ROOT)); } /** @@ -221,7 +221,7 @@ public interface IBukkitAdapter { if (!blockType.getId().startsWith("minecraft:")) { throw new IllegalArgumentException("Bukkit only supports Minecraft blocks"); } - String id = blockType.getId().substring(10).toUpperCase(); + String id = blockType.getId().substring(10).toUpperCase(Locale.ROOT); return Material.getMaterial(id); } @@ -366,7 +366,7 @@ public interface IBukkitAdapter { throw new IllegalArgumentException("Bukkit only supports vanilla biomes"); } try { - return Biome.valueOf(biomeType.getId().substring(10).toUpperCase()); + return Biome.valueOf(biomeType.getId().substring(10).toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException e) { return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java index bec4903bf..dfedaae08 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/DefaultBlockParser.java @@ -181,7 +181,7 @@ public class DefaultBlockParser extends InputParser { } state = LegacyMapper.getInstance().getBlockFromLegacy(id, data); } else { - BlockType type = BlockTypes.get(split[0].toLowerCase()); + BlockType type = BlockTypes.get(split[0].toLowerCase(Locale.ROOT)); if (type != null) { int data = Integer.parseInt(split[1]); if (data < 0 || data >= 16) { @@ -247,7 +247,7 @@ public class DefaultBlockParser extends InputParser { state = item.getType().getBlockType().getDefaultState(); nbt = item.getNbtData(); } else { - BlockType type = BlockTypes.parse(typeString.toLowerCase()); + BlockType type = BlockTypes.parse(typeString.toLowerCase(Locale.ROOT)); if (type != null) { state = type.getDefaultState(); @@ -309,15 +309,15 @@ public class DefaultBlockParser extends InputParser { if (blockAndExtraData.length > 1) { String mobName = blockAndExtraData[1]; for (MobType mobType : MobType.values()) { - if (mobType.getName().toLowerCase().equals(mobName.toLowerCase())) { + if (mobType.getName().toLowerCase().equals(mobName.toLowerCase(Locale.ROOT))) { mobName = mobType.getName(); break; } } if (!worldEdit.getPlatformManager().queryCapability(Capability.USER_COMMANDS).isValidMobType(mobName)) { - String finalMobName = mobName.toLowerCase(); + String finalMobName = mobName.toLowerCase(Locale.ROOT); throw new SuggestInputParseException("Unknown mob type '" + mobName + "'", mobName, () -> Stream.of(MobType.values()) - .map(m -> m.getName().toLowerCase()) + .map(m -> m.getName().toLowerCase(Locale.ROOT)) .filter(s -> s.startsWith(finalMobName)) .collect(Collectors.toList())); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java index 9cc922368..a657a8683 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.world.block.BlockCategory; import com.sk89q.worldedit.world.block.BlockType; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.stream.Collectors; @@ -49,7 +50,7 @@ public class BlockCategoryPatternParser extends InputParser { if (!input.startsWith("##")) { return null; } - String tag = input.substring(2).toLowerCase(); + String tag = input.substring(2).toLowerCase(Locale.ROOT); boolean anyState = false; if (tag.startsWith("*")) { tag = tag.substring(1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java index bb5e353ae..b56a849fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/DefaultPatternParser.java @@ -49,6 +49,7 @@ import com.sk89q.worldedit.world.block.BlockTypes; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -107,7 +108,7 @@ public class DefaultPatternParser extends FaweParser { () -> { if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases()); return dispatcher.getAliases().stream().filter( - s -> s.startsWith(command.toLowerCase()) + s -> s.startsWith(command.toLowerCase(Locale.ROOT)) ).collect(Collectors.toList()); } ); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 8c7d7c78e..ee3f0e001 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -50,6 +50,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -127,7 +128,7 @@ public class BlockTransformExtent extends ResettableExtent { case FACING: { List directions = new ArrayList<>(); for (Object value : values) { - directions.add(Direction.valueOf(value.toString().toUpperCase())); + directions.add(Direction.valueOf(value.toString().toUpperCase(Locale.ROOT))); } return adapt(directions.toArray(new Direction[0])); } @@ -331,10 +332,10 @@ public class BlockTransformExtent extends ResettableExtent { Object southState = tmp.getState(PropertyKey.SOUTH); Object westState = tmp.getState(PropertyKey.WEST); - tmp = tmp.with(PropertyKey.valueOf(newNorth.name().toUpperCase()), northState); - tmp = tmp.with(PropertyKey.valueOf(newEast.name().toUpperCase()), eastState); - tmp = tmp.with(PropertyKey.valueOf(newSouth.name().toUpperCase()), southState); - tmp = tmp.with(PropertyKey.valueOf(newWest.name().toUpperCase()), westState); + tmp = tmp.with(PropertyKey.valueOf(newNorth.name().toUpperCase(Locale.ROOT)), northState); + tmp = tmp.with(PropertyKey.valueOf(newEast.name().toUpperCase(Locale.ROOT)), eastState); + tmp = tmp.with(PropertyKey.valueOf(newSouth.name().toUpperCase(Locale.ROOT)), southState); + tmp = tmp.with(PropertyKey.valueOf(newWest.name().toUpperCase(Locale.ROOT)), westState); newMaskedId = tmp.getInternalId(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyKey.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyKey.java index ef6c77d24..34f941ae0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyKey.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/state/PropertyKey.java @@ -6,6 +6,7 @@ import com.sk89q.util.ReflectionUtil; import com.sk89q.worldedit.world.block.BlockTypes; import java.util.HashMap; +import java.util.Locale; import java.util.Map; /** @@ -100,7 +101,7 @@ public enum PropertyKey { PropertyKey property = PropertyKey.get(id); if (property == null) { Fawe.debug("Registering property " + id); - property = ReflectionUtils.addEnum(PropertyKey.class, id.toUpperCase()); + property = ReflectionUtils.addEnum(PropertyKey.class, id.toUpperCase(Locale.ROOT)); if (property.getId() == null) { try { ReflectionUtils.setFailsafeFieldValue(PropertyKey.class.getDeclaredField("id"), property, property.name().toLowerCase()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java index 949869cdd..24b06f5d1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/SimpleDispatcher.java @@ -35,6 +35,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -104,12 +105,12 @@ public class SimpleDispatcher implements Dispatcher { @Override public boolean contains(String alias) { - return commands.containsKey(alias.toLowerCase()); + return commands.containsKey(alias.toLowerCase(Locale.ROOT)); } @Override public CommandMapping get(String alias) { - return commands.get(alias.toLowerCase()); + return commands.get(alias.toLowerCase(Locale.ROOT)); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/argument/ArgumentUtils.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/argument/ArgumentUtils.java index 22141fedd..259853571 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/argument/ArgumentUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/argument/ArgumentUtils.java @@ -23,6 +23,7 @@ import com.google.common.collect.Lists; import java.util.Collection; import java.util.List; +import java.util.Locale; public final class ArgumentUtils { @@ -35,7 +36,7 @@ public final class ArgumentUtils { } List suggestions = Lists.newArrayList(); for (String item : items) { - if (item.toLowerCase().startsWith(s)) { + if (item.toLowerCase(Locale.ROOT).startsWith(s)) { suggestions.add(item); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/BranchingCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/BranchingCommand.java index ce4ba58fe..6ffe01174 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/BranchingCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/composition/BranchingCommand.java @@ -30,6 +30,7 @@ import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.argument.MissingArgumentException; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -55,7 +56,7 @@ public abstract class BranchingCommand implements CommandExecutor { public T call(CommandArgs args, CommandLocals locals) throws CommandException { try { String classifier = args.next(); - CommandExecutor executor = options.get(classifier.toLowerCase()); + CommandExecutor executor = options.get(classifier.toLowerCase(Locale.ROOT)); if (executor != null) { return executor.call(args, locals); } else { @@ -72,7 +73,7 @@ public abstract class BranchingCommand implements CommandExecutor { public List getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException { String classifier = args.next(); try { - CommandExecutor executor = options.get(classifier.toLowerCase()); + CommandExecutor executor = options.get(classifier.toLowerCase(Locale.ROOT)); if (executor != null) { return executor.getSuggestions(args, locals); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index c5bc616b4..7f4cc5370 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -43,6 +43,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; /** @@ -348,10 +349,10 @@ public class ParametricCallable extends AParametricCallable { */ private static String generateName(Type type, Annotation classifier, int index) { if (classifier != null) { - return classifier.annotationType().getSimpleName().toLowerCase(); + return classifier.annotationType().getSimpleName().toLowerCase(Locale.ROOT); } else { if (type instanceof Class) { - return ((Class) type).getSimpleName().toLowerCase(); + return ((Class) type).getSimpleName().toLowerCase(Locale.ROOT); } else { return "unknown" + index; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index 9a7bf8323..2626346c8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -859,7 +859,7 @@ public final class BlockTypes { // Get the enum name (remove namespace if minecraft:) int propStart = id.indexOf('['); String typeName = id.substring(0, propStart == -1 ? id.length() : propStart); - String enumName = (typeName.startsWith("minecraft:") ? typeName.substring(10) : typeName).toUpperCase(); + String enumName = (typeName.startsWith("minecraft:") ? typeName.substring(10) : typeName).toUpperCase(Locale.ROOT); BlockType existing = new BlockType(id, internalId, states); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java index 1d35cadf3..4c332729e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityTypes.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.world.entity; import javax.annotation.Nullable; +import java.util.Locale; public class EntityTypes { @@ -162,7 +163,7 @@ public class EntityTypes { } return parse(result.toString()); } - switch (id.toLowerCase()) { + switch (id.toLowerCase(Locale.ROOT)) { case "xp_orb": return EntityTypes.EXPERIENCE_ORB; case "xp_bottle": diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java index 4b896af0e..00d70ef3c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/item/ItemTypes.java @@ -24,6 +24,7 @@ import com.sk89q.worldedit.world.registry.LegacyMapper; import javax.annotation.Nullable; import java.util.Collection; +import java.util.Locale; public final class ItemTypes { @@ -823,7 +824,7 @@ public final class ItemTypes { @Nullable public static ItemType parse(String input) { - input = input.toLowerCase(); + input = input.toLowerCase(Locale.ROOT); if (!Character.isAlphabetic(input.charAt(0))) { try { ItemType legacy = LegacyMapper.getInstance().getItemFromLegacy(input);