Use fixed locale for toUpperCase/toLower #1126

This commit is contained in:
Myles 2019-05-12 13:00:14 +01:00
parent fbebf2d75e
commit fac7dafca5
12 changed files with 32 additions and 20 deletions

View File

@ -30,6 +30,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
@ -85,9 +86,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}
}
if ((Bukkit.getVersion().toLowerCase().contains("paper")
|| Bukkit.getVersion().toLowerCase().contains("taco")
|| Bukkit.getVersion().toLowerCase().contains("torch"))
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))
&& ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_12.getId()) {
plugin.getLogger().info("Enabling Paper/TacoSpigot/Torch patch: Fixes block placement.");
storeListener(new PaperPatch(plugin)).register();

View File

@ -28,17 +28,17 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
Preconditions.checkArgument(command.name().matches("^[a-z0-9_-]{3,15}$"), command.name() + " is not a valid sub-command name.");
if (hasSubCommand(command.name()))
throw new Exception("ViaSubCommand " + command.name() + " does already exists!"); //Maybe another exception later.
commandMap.put(command.name().toLowerCase(), command);
commandMap.put(command.name().toLowerCase(Locale.ROOT), command);
}
@Override
public boolean hasSubCommand(String name) {
return commandMap.containsKey(name.toLowerCase());
return commandMap.containsKey(name.toLowerCase(Locale.ROOT));
}
@Override
public ViaSubCommand getSubCommand(String name) {
return commandMap.get(name.toLowerCase());
return commandMap.get(name.toLowerCase(Locale.ROOT));
}
@Override
@ -76,7 +76,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
if (args.length == 1) {
if (!args[0].isEmpty()) {
for (ViaSubCommand sub : allowed)
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase()))
if (sub.name().toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
output.add(sub.name());
} else {
for (ViaSubCommand sub : allowed)

View File

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -33,7 +34,7 @@ public class AbstractStempConnectionHandler extends ConnectionHandler {
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), handler);
}
if (blockData.getMinecraftKey().equals(toKey)) {
String facing = blockData.getValue("facing").toUpperCase();
String facing = blockData.getValue("facing").toUpperCase(Locale.ROOT);
stemps.put(BlockFace.valueOf(facing), blockData.getSavedBlockStateId());
}
}

View File

@ -6,6 +6,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -19,10 +20,12 @@ class ChestConnectionHandler extends ConnectionHandler {
return new ConnectionData.ConnectorInitAction() {
@Override
public void check(WrappedBlockData blockData) {
if (!blockData.getMinecraftKey().equals("minecraft:chest") && !blockData.getMinecraftKey().equals("minecraft:trapped_chest")) return;
if (!blockData.getMinecraftKey().equals("minecraft:chest") && !blockData.getMinecraftKey().equals("minecraft:trapped_chest"))
return;
if (blockData.getValue("waterlogged").equals("true")) return;
chestFacings.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
if (blockData.getMinecraftKey().equalsIgnoreCase("minecraft:trapped_chest")) trappedChests.add(blockData.getSavedBlockStateId());
chestFacings.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
if (blockData.getMinecraftKey().equalsIgnoreCase("minecraft:trapped_chest"))
trappedChests.add(blockData.getSavedBlockStateId());
connectedStates.put(getStates(blockData), blockData.getSavedBlockStateId());
ConnectionData.connectionHandlerMap.put(blockData.getSavedBlockStateId(), connectionHandler);
}
@ -34,7 +37,7 @@ class ChestConnectionHandler extends ConnectionHandler {
String type = blockData.getValue("type");
if (type.equals("left")) states |= 1;
if (type.equals("right")) states |= 2;
states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase()).ordinal() << 2);
states |= (BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)).ordinal() << 2);
if (blockData.getMinecraftKey().equals("minecraft:trapped_chest")) states |= 16;
return states;
}

View File

@ -217,7 +217,7 @@ public class ConnectionData {
JsonObject object = type.getValue().getAsJsonObject();
boolean[] data = new boolean[6];
for (BlockFace value : BlockFace.values()) {
String face = value.toString().toLowerCase();
String face = value.toString().toLowerCase(Locale.ROOT);
if (object.has(face)) {
data[value.ordinal()] = object.getAsJsonPrimitive(face).getAsBoolean();
}

View File

@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class DoorConnectionHandler extends ConnectionHandler {
@ -40,7 +41,7 @@ public class DoorConnectionHandler extends ConnectionHandler {
blockData.getValue("hinge").equals("right"),
blockData.getValue("powered").equals("true"),
blockData.getValue("open").equals("true"),
BlockFace.valueOf(blockData.getValue("facing").toUpperCase()),
BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)),
type
);

View File

@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class StairConnectionHandler extends ConnectionHandler {
@ -58,7 +59,7 @@ public class StairConnectionHandler extends ConnectionHandler {
StairData stairData = new StairData(
blockData.getValue("half").equals("bottom"),
shape, (byte) type,
BlockFace.valueOf(blockData.getValue("facing").toUpperCase())
BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT))
);
stairDataMap.put(blockData.getSavedBlockStateId(), stairData);

View File

@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class TripwireConnectionHandler extends ConnectionHandler {
@ -21,7 +22,7 @@ public class TripwireConnectionHandler extends ConnectionHandler {
@Override
public void check(WrappedBlockData blockData) {
if (blockData.getMinecraftKey().equals("minecraft:tripwire_hook")) {
tripwireHooks.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase()));
tripwireHooks.put(blockData.getSavedBlockStateId(), BlockFace.valueOf(blockData.getValue("facing").toUpperCase(Locale.ROOT)));
} else if (blockData.getMinecraftKey().equals("minecraft:tripwire")) {
TripwireData tripwireData = new TripwireData(
blockData.getValue("attached").equals("true"),

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class NamedSoundRewriter {
@ -148,6 +149,6 @@ public class NamedSoundRewriter {
public static String getNewId(String old) {
String newId = oldToNew.get(old);
return newId != null ? newId : old.toLowerCase();
return newId != null ? newId : old.toLowerCase(Locale.ROOT);
}
}

View File

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers;
import com.google.common.base.Optional;
import us.myles.ViaVersion.api.platform.providers.Provider;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -45,7 +46,7 @@ public class PaintingProvider implements Provider {
public Optional<Integer> getIntByIdentifier(String motive) {
// Handle older versions
if (!motive.startsWith("minecraft:"))
motive = "minecraft:" + motive.toLowerCase();
motive = "minecraft:" + motive.toLowerCase(Locale.ROOT);
return Optional.fromNullable(paintings.get(motive));
}
}

View File

@ -3,6 +3,7 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@Getter
@ -284,7 +285,7 @@ public enum SoundEffect {
}
public static SoundEffect getByName(String name) {
name = name.toLowerCase();
name = name.toLowerCase(Locale.ROOT);
return effects.get(name);
}

View File

@ -12,6 +12,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import java.util.UUID;
public class UpdateUtil {
@ -81,7 +82,7 @@ public class UpdateUtil {
if (current.compareTo(newest) < 0)
return "There is a newer version available: " + newest.toString() + ", you're on: " + current.toString();
else if (console && current.compareTo(newest) != 0) {
if (current.getTag().toLowerCase().startsWith("dev") || current.getTag().toLowerCase().startsWith("snapshot")) {
if (current.getTag().toLowerCase(Locale.ROOT).startsWith("dev") || current.getTag().toLowerCase(Locale.ROOT).startsWith("snapshot")) {
return "You are running a development version, please report any bugs to GitHub.";
} else {
return "You are running a newer version than is released!";