Skip to content

Commit

Permalink
Force English locale on toUpperCase and toLowerCase calls, fixes issu…
Browse files Browse the repository at this point in the history
…es on systems with a different locale
  • Loading branch information
UnlikePaladin committed Feb 10, 2024
1 parent 6780d9f commit 52da5ff
Show file tree
Hide file tree
Showing 36 changed files with 93 additions and 83 deletions.
Expand Up @@ -510,7 +510,7 @@ public String getLoop() {
)
public Animation setLoop(@LuaNotNil String loop) {
try {
this.loop = LoopMode.valueOf(loop.toUpperCase());
this.loop = LoopMode.valueOf(loop.toUpperCase(Locale.US));
return this;
} catch (Exception ignored) {
throw new LuaError("Illegal LoopMode: \"" + loop + "\".");
Expand Down
Expand Up @@ -1044,7 +1044,7 @@ private void loadAnimations() {
Animation.LoopMode loop = Animation.LoopMode.ONCE;
if (animNbt.contains("loop")) {
try {
loop = Animation.LoopMode.valueOf(animNbt.getString("loop").toUpperCase());
loop = Animation.LoopMode.valueOf(animNbt.getString("loop").toUpperCase(Locale.US));
} catch (Exception ignored) {}
}

Expand Down
13 changes: 7 additions & 6 deletions common/src/main/java/org/figuramc/figura/avatar/Badges.java
Expand Up @@ -16,6 +16,7 @@
import org.figuramc.figura.utils.ui.UIHelper;

import java.util.BitSet;
import java.util.Locale;
import java.util.Optional;
import java.util.UUID;

Expand Down Expand Up @@ -79,7 +80,7 @@ else if (avatar.nbt != null) {
MutableComponent badge = System.PERMISSIONS.badge.copy();
MutableComponent desc = System.PERMISSIONS.desc.copy().append("\n");
for (Permissions t : avatar.noPermissions)
desc.append("\n• ").append(FiguraText.of("badges.no_permissions." + t.name.toLowerCase()));
desc.append("\n• ").append(FiguraText.of("badges.no_permissions." + t.name.toLowerCase(Locale.US)));

badges.append(badge.withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, desc))));
}
Expand All @@ -95,8 +96,8 @@ else if (avatar.nbt != null) {
if (specialSet.get(i)) {
Special special = specialValues[i];
Integer color = special.color;
if (avatar.badgeToColor.containsKey(special.name().toLowerCase())) {
color = ColorUtils.rgbToInt(ColorUtils.userInputHex(avatar.badgeToColor.get(special.name().toLowerCase())));
if (avatar.badgeToColor.containsKey(special.name().toLowerCase(Locale.US))) {
color = ColorUtils.rgbToInt(ColorUtils.userInputHex(avatar.badgeToColor.get(special.name().toLowerCase(Locale.US))));
}
Component badge = color != null ? special.badge.copy().withStyle(Style.EMPTY.withColor(color)) : special.badge;
badges.append(badge);
Expand Down Expand Up @@ -159,7 +160,7 @@ public enum System {
public final Component desc;

System(String unicode) {
this.desc = FiguraText.of("badges.system." + this.name().toLowerCase());
this.desc = FiguraText.of("badges.system." + this.name().toLowerCase(Locale.US));
this.badge = Component.literal(unicode).withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, desc)));
}
}
Expand Down Expand Up @@ -195,7 +196,7 @@ public enum Pride {
public final Component desc;

Pride(String unicode) {
this.desc = FiguraText.of("badges.pride." + this.name().toLowerCase());
this.desc = FiguraText.of("badges.pride." + this.name().toLowerCase(Locale.US));
this.badge = Component.literal(unicode).withStyle(Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, desc)));
}
}
Expand All @@ -218,7 +219,7 @@ public enum Special {
}

Special(String unicode, Integer color) {
this.desc = FiguraText.of("badges.special." + this.name().toLowerCase());
this.desc = FiguraText.of("badges.special." + this.name().toLowerCase(Locale.US));
Style style = Style.EMPTY.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, desc));
if (color != null) style = style.withColor(color);
this.color = color;
Expand Down
Expand Up @@ -13,10 +13,7 @@

import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

Expand Down Expand Up @@ -261,8 +258,8 @@ public AvatarPath(Path path, Path folder, Path theActualPathForThis) {
}

public boolean search(String query) {
String q = query.toLowerCase();
return this.getName().toLowerCase().contains(q) || IOUtils.getFileNameOrEmpty(path).contains(q);
String q = query.toLowerCase(Locale.US);
return this.getName().toLowerCase(Locale.US).contains(q) || IOUtils.getFileNameOrEmpty(path).contains(q);
}

public Path getPath() {
Expand Down
Expand Up @@ -264,7 +264,7 @@ private static CompoundTag loadModels(Path avatarFolder, Path currentFile, Block
BlockbenchModelParser.parseParent(name, subfolder);
children.add(subfolder);
}
} else if (file.toString().toLowerCase().endsWith(".bbmodel")) {
} else if (file.toString().toLowerCase(Locale.US).endsWith(".bbmodel")) {
BlockbenchModelParser.ModelData data = parser.parseModel(avatarFolder, file, IOUtils.readFile(file), name.substring(0, name.length() - 8), folders);
children.add(data.modelNbt());
animations.addAll(data.animationList());
Expand Down Expand Up @@ -373,7 +373,7 @@ public static Path getLastLoadedPath() {
}

public static String getLoadState() {
return loadState.name().toLowerCase();
return loadState.name().toLowerCase(Locale.US);
}

public static String getLoadError() {
Expand Down
Expand Up @@ -9,10 +9,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public final class ConfigManager {

Expand Down Expand Up @@ -41,7 +38,7 @@ public static void loadConfig() {
update(json, version.getAsInt());
} else {
for (ConfigType<?> config : REGISTRY) {
JsonElement object = json.get(config.id.toLowerCase());
JsonElement object = json.get(config.id.toLowerCase(Locale.US));
if (object == null)
continue;
if (config instanceof ConfigType.SerializableConfig s) {
Expand Down
@@ -1,5 +1,7 @@
package org.figuramc.figura.gui.cards;

import java.util.Locale;

public enum CardBackground {
DEFAULT,
CHEESE,
Expand All @@ -12,7 +14,7 @@ public enum CardBackground {

public static CardBackground parse(String string) {
try {
return CardBackground.valueOf(string.toUpperCase());
return CardBackground.valueOf(string.toUpperCase(Locale.US));
} catch (Exception ignored) {
return DEFAULT;
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.figuramc.figura.utils.ui.UIHelper;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class ConfigScreen extends AbstractPanelScreen {
Expand Down Expand Up @@ -56,7 +57,7 @@ protected void init() {
int width = Math.min(this.width - 8, 420);
list = new ConfigList((this.width - width) / 2, 52, width, height - 80, this);

this.addRenderableWidget(new SearchBar(this.width / 2 - 122, 28, 244, 20, query -> list.updateSearch(query.toLowerCase())));
this.addRenderableWidget(new SearchBar(this.width / 2 - 122, 28, 244, 20, query -> list.updateSearch(query.toLowerCase(Locale.US))));
this.addRenderableWidget(list);

// -- bottom buttons -- //
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.figuramc.figura.utils.TextUtils;
import org.figuramc.figura.utils.ui.UIHelper;

import java.util.Locale;
import java.util.function.Consumer;

public class TextField extends AbstractContainerElement {
Expand Down Expand Up @@ -169,7 +170,7 @@ public enum HintType {
private final Component hint;

HintType() {
this.hint = FiguraText.of("gui.text_hint." + this.name().toLowerCase());
this.hint = FiguraText.of("gui.text_hint." + this.name().toLowerCase(Locale.US));
}
}
}
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
import java.util.Locale;

public abstract class AbstractAvatarWidget extends AbstractContainerElement implements Comparable<AbstractAvatarWidget> {

Expand Down Expand Up @@ -114,7 +115,7 @@ public boolean isMouseOver(double mouseX, double mouseY) {

public void update(LocalAvatarFetcher.AvatarPath path, String filter) {
this.avatar = path;
this.filter = filter.toLowerCase();
this.filter = filter.toLowerCase(Locale.US);
}

public Component getName() {
Expand All @@ -134,7 +135,7 @@ public void setY(int y) {
}

public boolean filtered() {
return this.getName().getString().toLowerCase().contains(filter.toLowerCase());
return this.getName().getString().toLowerCase(Locale.US).contains(filter.toLowerCase(Locale.US));
}

@Override
Expand All @@ -157,7 +158,7 @@ else if (this instanceof AvatarWidget && other instanceof AvatarFolderWidget)
return 1;

// then compare names
else return this.getName().getString().toLowerCase().compareTo(other.getName().getString().toLowerCase());
else return this.getName().getString().toLowerCase(Locale.US).compareTo(other.getName().getString().toLowerCase(Locale.US));
}

@Override
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.figuramc.figura.gui.widgets.lists.ConfigList;
import org.figuramc.figura.utils.ui.UIHelper;

import java.util.Locale;
import java.util.Objects;

public abstract class AbstractConfigElement extends AbstractContainerElement {
Expand Down Expand Up @@ -105,6 +106,6 @@ public void updateFilter(String query) {
}

public boolean matchesFilter() {
return config.name.getString().toLowerCase().contains(filter) || config.tooltip.getString().toLowerCase().contains(filter);
return config.name.getString().toLowerCase(Locale.US).contains(filter) || config.tooltip.getString().toLowerCase(Locale.US).contains(filter);
}
}
Expand Up @@ -17,10 +17,7 @@
import org.figuramc.figura.wizards.AvatarWizard;
import org.figuramc.figura.wizards.WizardEntry;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class AvatarWizardList extends AbstractList {

Expand Down Expand Up @@ -128,7 +125,7 @@ private void generate() {
children.addAll(lastList);
}

lastName = FiguraText.of("gui.avatar_wizard." + value.name.toLowerCase());
lastName = FiguraText.of("gui.avatar_wizard." + value.name.toLowerCase(Locale.US));
lastList = new ArrayList<>();
}
case TEXT -> lastList.add(new WizardInputBox(x, width, this, value));
Expand All @@ -150,7 +147,7 @@ public WizardInputBox(int x, int width, AvatarWizardList parent, WizardEntry ent
super(x, 0, width, 20, HintType.ANY, s -> parent.wizard.changeEntry(entry, s));
this.parent = parent;
this.entry = entry;
this.name = FiguraText.of("gui.avatar_wizard." + entry.name.toLowerCase());
this.name = FiguraText.of("gui.avatar_wizard." + entry.name.toLowerCase(Locale.US));
this.getField().setValue(String.valueOf(parent.wizard.getEntry(entry, "")));
}

Expand Down Expand Up @@ -178,7 +175,7 @@ private static class WizardToggleButton extends SwitchButton {
private final WizardEntry entry;

public WizardToggleButton(int x, int width, AvatarWizardList parent, WizardEntry entry) {
super(x, 0, width, 20, FiguraText.of("gui.avatar_wizard." + entry.name.toLowerCase()), false);
super(x, 0, width, 20, FiguraText.of("gui.avatar_wizard." + entry.name.toLowerCase(Locale.US)), false);
this.parent = parent;
this.entry = entry;
this.setToggled((boolean) parent.wizard.getEntry(entry, false));
Expand Down
Expand Up @@ -116,7 +116,7 @@ private List<GuiEventListener> generateWidgets(PermissionPack container, Collect
int lineHeight = Minecraft.getInstance().font.lineHeight;

GuiEventListener widget;
String text = id + ".permissions.value." + permissions.name.toLowerCase();
String text = id + ".permissions.value." + permissions.name.toLowerCase(Locale.US);
if (!permissions.isToggle) {
if (!precise)
widget = new PermissionSlider(x + 8, y, width - 30, 11 + lineHeight, container, permissions, this, id, text);
Expand Down
Expand Up @@ -168,7 +168,7 @@ private void loadPlayers() {
Avatar avatar = AvatarManager.getAvatarForPlayer(uuid);

// filter check
if ((!name.toLowerCase().contains(filter.toLowerCase()) && !uuid.toString().contains(filter.toLowerCase())) || (showFigura.isToggled() && !FiguraMod.isLocal(uuid) && (avatar == null || avatar.nbt == null)))
if ((!name.toLowerCase(Locale.US).contains(filter.toLowerCase(Locale.US)) && !uuid.toString().contains(filter.toLowerCase(Locale.US))) || (showFigura.isToggled() && !FiguraMod.isLocal(uuid) && (avatar == null || avatar.nbt == null)))
continue;

// player is not missing
Expand Down
Expand Up @@ -12,6 +12,8 @@
import org.figuramc.figura.utils.MathUtils;
import org.figuramc.figura.utils.ui.UIHelper;

import java.util.Locale;

public class AbstractPermPackElement extends Button implements Comparable<AbstractPermPackElement>, FiguraWidget {

protected final PlayerList parent;
Expand Down Expand Up @@ -102,7 +104,7 @@ public int compareTo(AbstractPermPackElement other) {
return 1;

// and then compare names
return player1.getName().toLowerCase().compareTo(player2.getName().toLowerCase());
return player1.getName().toLowerCase(Locale.US).compareTo(player2.getName().toLowerCase(Locale.US));
}
}

Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/org/figuramc/figura/lua/api/FileAPI.java
Expand Up @@ -18,6 +18,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;

@LuaWhitelist
@LuaTypeDoc(name = "FileAPI", value = "file")
Expand Down Expand Up @@ -168,7 +169,7 @@ public FiguraOutputStream openWriteStream(@LuaNotNil String path) {
public String readString(@LuaNotNil String path, String encoding) {
try (FiguraInputStream fis = openReadStream(path)) {
byte[] data = fis.readAllBytes();
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase()) {
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase(Locale.US)) {
case "utf_16", "utf16" -> StandardCharsets.UTF_16;
case "utf_16be", "utf16be" -> StandardCharsets.UTF_16BE;
case "utf_16le", "utf16le" -> StandardCharsets.UTF_16LE;
Expand All @@ -192,7 +193,7 @@ public String readString(@LuaNotNil String path, String encoding) {
)
public void writeString(@LuaNotNil String path, @LuaNotNil String data, String encoding) {
try (FiguraOutputStream fos = openWriteStream(path)) {
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase()) {
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase(Locale.US)) {
case "utf_16", "utf16" -> StandardCharsets.UTF_16;
case "utf_16be", "utf16be" -> StandardCharsets.UTF_16BE;
case "utf_16le", "utf16le" -> StandardCharsets.UTF_16LE;
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Predicate;

Expand Down Expand Up @@ -87,15 +88,15 @@ public Object[] block(Object x, Object y, Object z, Object w, Object t, Object h

ClipContext.Block blockContext;
try{
blockContext = blockCastType != null ? ClipContext.Block.valueOf(blockCastType.toUpperCase()) : ClipContext.Block.COLLIDER;
blockContext = blockCastType != null ? ClipContext.Block.valueOf(blockCastType.toUpperCase(Locale.US)) : ClipContext.Block.COLLIDER;
}
catch(IllegalArgumentException e){
throw new LuaError("Invalid blockRaycastType provided");
}

ClipContext.Fluid fluidContext;
try{
fluidContext = fluidCastType != null ? ClipContext.Fluid.valueOf(fluidCastType.toUpperCase()) : ClipContext.Fluid.NONE;
fluidContext = fluidCastType != null ? ClipContext.Fluid.valueOf(fluidCastType.toUpperCase(Locale.US)) : ClipContext.Fluid.NONE;
}
catch(IllegalArgumentException e){
throw new LuaError("Invalid fluidRaycastType provided");
Expand Down
Expand Up @@ -17,6 +17,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.Locale;
import java.util.Stack;

@LuaWhitelist
Expand Down Expand Up @@ -233,7 +234,7 @@ public double readDoubleLE() {
public String readString(Integer length, String encoding) {
checkIsClosed();
length = length == null ? available() : Math.max(length, 0);
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase()) {
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase(Locale.US)) {
case "utf_16", "utf16" -> StandardCharsets.UTF_16;
case "utf_16be", "utf16be" -> StandardCharsets.UTF_16BE;
case "utf_16le", "utf16le" -> StandardCharsets.UTF_16LE;
Expand Down Expand Up @@ -523,7 +524,7 @@ public void writeDoubleLE(@LuaNotNil Double val) {
)
public int writeString(@LuaNotNil String val, String encoding) {
checkIsClosed();
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase()) {
Charset charset = encoding == null ? StandardCharsets.UTF_8 : switch (encoding.toLowerCase(Locale.US)) {
case "utf_16", "utf16" -> StandardCharsets.UTF_16;
case "utf_16be", "utf16be" -> StandardCharsets.UTF_16BE;
case "utf_16le", "utf16le" -> StandardCharsets.UTF_16LE;
Expand Down

0 comments on commit 52da5ff

Please sign in to comment.