use Locale.ROOT for uppercase as well

This commit is contained in:
Jesse Boyd 2019-07-10 22:26:31 +10:00
parent a98a91e066
commit cafd4bfece
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
17 changed files with 43 additions and 30 deletions

View File

@ -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<Direction>) state.d().stream().map(e -> Direction.valueOf(((INamable) e).getName().toUpperCase())).collect(Collectors.toList()));
(List<Direction>) 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<String>) state.d().stream().map(e -> ((INamable) e).getName()).collect(Collectors.toList()));

View File

@ -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

View File

@ -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

View File

@ -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()) {

View File

@ -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;
}

View File

@ -181,7 +181,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}
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<BaseBlock> {
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<BaseBlock> {
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()));
}

View File

@ -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<Pattern> {
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);

View File

@ -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<Pattern> {
() -> {
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());
}
);

View File

@ -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<Direction> 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();
}

View File

@ -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());

View File

@ -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

View File

@ -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<String> suggestions = Lists.newArrayList();
for (String item : items) {
if (item.toLowerCase().startsWith(s)) {
if (item.toLowerCase(Locale.ROOT).startsWith(s)) {
suggestions.add(item);
}
}

View File

@ -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<T> implements CommandExecutor<T> {
public T call(CommandArgs args, CommandLocals locals) throws CommandException {
try {
String classifier = args.next();
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase());
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase(Locale.ROOT));
if (executor != null) {
return executor.call(args, locals);
} else {
@ -72,7 +73,7 @@ public abstract class BranchingCommand<T> implements CommandExecutor<T> {
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
String classifier = args.next();
try {
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase());
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase(Locale.ROOT));
if (executor != null) {
return executor.getSuggestions(args, locals);
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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":

View File

@ -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);