Uses Locale.ENGLISH for toLowerCase and toUpperCase (#1378)

The locale should be explicitly declared otherwise the default locale of
the operating system will be used, which may result in unexpected bugs.
This commit is contained in:
tastybento 2020-05-30 12:52:05 -07:00 committed by GitHub
parent d6b2a88b32
commit 6fa89b0b4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 59 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.jar.JarEntry;
@ -212,7 +213,7 @@ public abstract class Addon {
Bukkit.getLogger().severe("Could not save config! " + this.getDescription().getName() + " " + e.getMessage());
}
}
/**
* Discards any data in getConfig() and reloads from disk.
* @since 1.13.0
@ -419,7 +420,7 @@ public abstract class Addon {
* @return Permission prefix string
*/
public String getPermissionPrefix() {
return this.getDescription().getName().toLowerCase() + ".";
return this.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".";
}
/**
@ -437,7 +438,7 @@ public abstract class Addon {
* @return request response, null if no response.
*/
public Object request(String label, Map<String, Object> metaData) {
label = label.toLowerCase();
label = label.toLowerCase(Locale.ENGLISH);
AddonRequestHandler handler = requestHandlers.get(label);
if(handler != null) {
return handler.handle(metaData);

View File

@ -1,31 +1,32 @@
package world.bentobox.bentobox.api.addons.request;
import java.util.Locale;
import java.util.Map;
public abstract class AddonRequestHandler
{
private String label;
private String label;
public AddonRequestHandler(String label) {
this.label = label.toLowerCase();
}
public AddonRequestHandler(String label) {
this.label = label.toLowerCase(Locale.ENGLISH);
}
/**
* Get request handler label.
*
* @return label
*/
public String getLabel() {
return label;
}
/**
* Get request handler label.
*
* @return label
*/
public String getLabel() {
return label;
}
/**
* Handle an addon request.
* This is used only for Addons to respond to addon requests from plugins.
* Example: request island level from Levels addon.
*
* @param metaData meta data
* @return request response
*/
public abstract Object handle(Map<String, Object> metaData);
/**
* Handle an addon request.
* This is used only for Addons to respond to addon requests from plugins.
* Example: request island level from Levels addon.
*
* @param metaData meta data
* @return request response
*/
public abstract Object handle(Map<String, Object> metaData);
}

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.api.commands.island;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import org.bukkit.block.BlockFace;
@ -66,7 +67,7 @@ public class IslandNearCommand extends CompositeCommand {
if (!name.isEmpty()) {
noNeighbors = false;
user.sendMessage("commands.island.near.syntax",
"[direction]", user.getTranslation("commands.island.near." + face.name().toLowerCase()),
"[direction]", user.getTranslation("commands.island.near." + face.name().toLowerCase(Locale.ENGLISH)),
TextVariables.NAME, name);
}
}

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.api.configuration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -478,7 +479,7 @@ public interface WorldSettings extends ConfigObject {
*/
default String getAdminCommandAliases()
{
return this.getFriendlyName().toLowerCase() + "admin";
return this.getFriendlyName().toLowerCase(Locale.ENGLISH) + "admin";
}
@ -492,7 +493,7 @@ public interface WorldSettings extends ConfigObject {
*/
default String getPlayerCommandAliases()
{
return this.getFriendlyName().toLowerCase();
return this.getFriendlyName().toLowerCase(Locale.ENGLISH);
}

View File

@ -349,7 +349,7 @@ public class User {
public String getTranslation(World world, String reference, String... variables) {
// Get translation.
String addonPrefix = plugin.getIWM()
.getAddon(world).map(a -> a.getDescription().getName().toLowerCase() + ".").orElse("");
.getAddon(world).map(a -> a.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".").orElse("");
return translate(addonPrefix, reference, variables);
}
@ -363,7 +363,7 @@ public class User {
*/
public String getTranslation(String reference, String... variables) {
// Get addonPrefix
String addonPrefix = addon == null ? "" : addon.getDescription().getName().toLowerCase() + ".";
String addonPrefix = addon == null ? "" : addon.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".";
return translate(addonPrefix, reference, variables);
}

View File

@ -5,6 +5,7 @@ import java.math.RoundingMode;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
@ -418,7 +419,7 @@ public class BlueprintPaster {
// Sign text must be stored under the addon's name.sign.line0,1,2,3 in the yaml file
if (island != null && !lines.isEmpty() && lines.get(0).equalsIgnoreCase(TextVariables.START_TEXT)) {
// Get the addon that is operating in this world
String addonName = plugin.getIWM().getAddon(island.getWorld()).map(addon -> addon.getDescription().getName().toLowerCase()).orElse("");
String addonName = plugin.getIWM().getAddon(island.getWorld()).map(addon -> addon.getDescription().getName().toLowerCase(Locale.ENGLISH)).orElse("");
for (int i = 0; i < 4; i++) {
s.setLine(i, ChatColor.translateAlternateColorCodes('&', plugin.getLocalesManager().getOrDefault(User.getInstance(island.getOwner()),
addonName + ".sign.line" + i,"").replace(TextVariables.NAME, name)));

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox.blueprints.conversation;
import java.util.Locale;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
@ -44,7 +46,7 @@ public class NamePrompt extends StringPrompt {
return this;
}
// Make a uniqueid
StringBuilder uniqueId = new StringBuilder(ChatColor.stripColor(input).toLowerCase().replace(" ", "_"));
StringBuilder uniqueId = new StringBuilder(ChatColor.stripColor(input).toLowerCase(Locale.ENGLISH).replace(" ", "_"));
// Check if this name is unique
int max = 0;
while (max++ < 32 && addon.getPlugin().getBlueprintsManager().getBlueprintBundles(addon).containsKey(uniqueId.toString())) {

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.commands;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
@ -79,7 +80,7 @@ public class BentoBoxVersionCommand extends CompositeCommand {
});
user.sendMessage("commands.bentobox.version.loaded-addons");
getPlugin().getAddonsManager().getAddons().stream().sorted(Comparator.comparing(o -> o.getDescription().getName().toLowerCase()))
getPlugin().getAddonsManager().getAddons().stream().sorted(Comparator.comparing(o -> o.getDescription().getName().toLowerCase(Locale.ENGLISH)))
.forEach(a -> user.sendMessage("commands.bentobox.version.addon-syntax", TextVariables.NAME, a.getDescription().getName(),
TextVariables.VERSION, a.getDescription().getVersion(), "[state]", a.getState().toString()));

View File

@ -17,6 +17,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
@ -621,7 +622,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Find out the value
Class<Enum> enumClass = (Class<Enum>)clazz;
try {
value = Enum.valueOf(enumClass, ((String)value).toUpperCase());
value = Enum.valueOf(enumClass, ((String)value).toUpperCase(Locale.ENGLISH));
} catch (Exception e) {
// This value does not exist - probably admin typed it wrongly
// Show what is available and pick one at random

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.hooks;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Material;
@ -54,7 +55,7 @@ public class DynmapHook extends Hook {
String name = addon.getDescription().getName();
if (getMarkerSet(addon) == null) {
// From the javadoc: createMarkerSet(String id, String label, Set<MarkerIcon> allowedIcons, boolean persistent)
MarkerSet set = markerAPI.createMarkerSet(name.toLowerCase() + ".markers", name, null, true);
MarkerSet set = markerAPI.createMarkerSet(name.toLowerCase(Locale.ENGLISH) + ".markers", name, null, true);
markerSets.put(addon, set);
}
}
@ -69,7 +70,7 @@ public class DynmapHook extends Hook {
if (markerSets.containsKey(addon)) {
return markerSets.get(addon);
} else {
return markerAPI.getMarkerSet(addon.getDescription().getName().toLowerCase() + ".markers");
return markerAPI.getMarkerSet(addon.getDescription().getName().toLowerCase(Locale.ENGLISH) + ".markers");
}
}

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox.hooks;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
@ -30,7 +32,7 @@ public class MultiverseCoreHook extends Hook {
if (islandWorld) {
// Only register generator if one is defined in the addon (is not null)
String generator = BentoBox.getInstance().getIWM().getAddon(world).map(gm -> gm.getDefaultWorldGenerator(world.getName(), "") != null).orElse(false) ? " -g " + BentoBox.getInstance().getName() : "";
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase() + generator;
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase(Locale.ENGLISH) + generator;
String cmd2 = MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName();
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
if (!generator.isEmpty()) {
@ -39,7 +41,7 @@ public class MultiverseCoreHook extends Hook {
}
} else {
// Set the generator to null - this will remove any previous registration
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase();
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase(Locale.ENGLISH);
String cmd2 = MULTIVERSE_SET_GENERATOR + "null " + world.getName();
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2);

View File

@ -11,6 +11,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
@ -154,7 +155,7 @@ public class AddonsManager {
if (addon instanceof GameModeAddon) {
GameModeAddon gameMode = (GameModeAddon) addon;
if (!gameMode.getWorldSettings().getWorldName().isEmpty()) {
worldNames.put(gameMode.getWorldSettings().getWorldName().toLowerCase(), gameMode);
worldNames.put(gameMode.getWorldSettings().getWorldName().toLowerCase(Locale.ENGLISH), gameMode);
}
}
// Addon successfully loaded
@ -506,7 +507,7 @@ public class AddonsManager {
@Nullable
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
// Clean up world name
String w = worldName.replace("_nether", "").replace("_the_end", "").toLowerCase();
String w = worldName.replace("_nether", "").replace("_the_end", "").toLowerCase(Locale.ENGLISH);
if (worldNames.containsKey(w)) {
return worldNames.get(w).getDefaultWorldGenerator(worldName, id);
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@ -297,7 +298,7 @@ public class IslandWorldManager {
* @return the worldName
*/
public String getWorldName(@NonNull World world) {
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getWorldName().toLowerCase() : world.getName();
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getWorldName().toLowerCase(Locale.ENGLISH) : world.getName();
}
/**

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.versions;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
@ -74,7 +75,7 @@ public class ServerCompatibility {
GLOWSTONE(Compatibility.INCOMPATIBLE),
SPIGOT(Compatibility.COMPATIBLE),
PAPER(Compatibility.SUPPORTED),
TACOSPIGOT(Compatibility.NOT_SUPPORTED),
TACOSPIGOT(Compatibility.NOT_SUPPORTED),
AKARIN(Compatibility.NOT_SUPPORTED);
private Compatibility compatibility;
@ -129,7 +130,7 @@ public class ServerCompatibility {
*/
V1_15_2(Compatibility.COMPATIBLE)
;
private Compatibility compatibility;
@ -214,7 +215,7 @@ public class ServerCompatibility {
public ServerSoftware getServerSoftware() {
String serverSoftware = Bukkit.getServer().getVersion().substring(4).split("-")[0];
try {
return ServerSoftware.valueOf(serverSoftware.toUpperCase());
return ServerSoftware.valueOf(serverSoftware.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
return null;
}
@ -229,7 +230,7 @@ public class ServerCompatibility {
public ServerVersion getServerVersion() {
String serverVersion = Bukkit.getServer().getBukkitVersion().split("-")[0].replace(".", "_");
try {
return ServerVersion.valueOf("V" + serverVersion.toUpperCase());
return ServerVersion.valueOf("V" + serverVersion.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
return null;
}