13
0
geforkt von Mirrors/Paper

BUILDTOOLS-251: Make much of Bukkit locale independent

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2016-06-26 19:31:59 +10:00
Ursprung b54985de63
Commit 7f7f1608e8
17 geänderte Dateien mit 41 neuen und 41 gelöschten Zeilen

Datei anzeigen

@ -99,13 +99,13 @@ public enum Art {
public static Art getByName(String name) { public static Art getByName(String name) {
Validate.notNull(name, "Name cannot be null"); Validate.notNull(name, "Name cannot be null");
return BY_NAME.get(name.toLowerCase().replaceAll("_", "")); return BY_NAME.get(name.toLowerCase(java.util.Locale.ENGLISH).replaceAll("_", ""));
} }
static { static {
for (Art art : values()) { for (Art art : values()) {
BY_ID.put(art.id, art); BY_ID.put(art.id, art);
BY_NAME.put(art.toString().toLowerCase().replaceAll("_", ""), art); BY_NAME.put(art.toString().toLowerCase(java.util.Locale.ENGLISH).replaceAll("_", ""), art);
} }
} }
} }

Datei anzeigen

@ -707,7 +707,7 @@ public enum Material {
} catch (NumberFormatException ex) {} } catch (NumberFormatException ex) {}
if (result == null) { if (result == null) {
String filtered = name.toUpperCase(); String filtered = name.toUpperCase(java.util.Locale.ENGLISH);
filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", ""); filtered = filtered.replaceAll("\\s+", "_").replaceAll("\\W", "");
result = BY_NAME.get(filtered); result = BY_NAME.get(filtered);

Datei anzeigen

@ -37,7 +37,7 @@ public enum WorldType {
* @return Requested WorldType, or null if not found * @return Requested WorldType, or null if not found
*/ */
public static WorldType getByName(String name) { public static WorldType getByName(String name) {
return BY_NAME.get(name.toUpperCase()); return BY_NAME.get(name.toUpperCase(java.util.Locale.ENGLISH));
} }
static { static {

Datei anzeigen

@ -60,8 +60,8 @@ public class SimpleCommandMap implements CommandMap {
* {@inheritDoc} * {@inheritDoc}
*/ */
public boolean register(String label, String fallbackPrefix, Command command) { public boolean register(String label, String fallbackPrefix, Command command) {
label = label.toLowerCase().trim(); label = label.toLowerCase(java.util.Locale.ENGLISH).trim();
fallbackPrefix = fallbackPrefix.toLowerCase().trim(); fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim();
boolean registered = register(label, command, false, fallbackPrefix); boolean registered = register(label, command, false, fallbackPrefix);
Iterator<String> iterator = command.getAliases().iterator(); Iterator<String> iterator = command.getAliases().iterator();
@ -128,7 +128,7 @@ public class SimpleCommandMap implements CommandMap {
return false; return false;
} }
String sentCommandLabel = args[0].toLowerCase(); String sentCommandLabel = args[0].toLowerCase(java.util.Locale.ENGLISH);
Command target = getCommand(sentCommandLabel); Command target = getCommand(sentCommandLabel);
if (target == null) { if (target == null) {
@ -157,7 +157,7 @@ public class SimpleCommandMap implements CommandMap {
} }
public Command getCommand(String name) { public Command getCommand(String name) {
Command target = knownCommands.get(name.toLowerCase()); Command target = knownCommands.get(name.toLowerCase(java.util.Locale.ENGLISH));
return target; return target;
} }
@ -252,9 +252,9 @@ public class SimpleCommandMap implements CommandMap {
// We register these as commands so they have absolute priority. // We register these as commands so they have absolute priority.
if (targets.size() > 0) { if (targets.size() > 0) {
knownCommands.put(alias.toLowerCase(), new FormattedCommandAlias(alias.toLowerCase(), targets.toArray(new String[targets.size()]))); knownCommands.put(alias.toLowerCase(java.util.Locale.ENGLISH), new FormattedCommandAlias(alias.toLowerCase(java.util.Locale.ENGLISH), targets.toArray(new String[targets.size()])));
} else { } else {
knownCommands.remove(alias.toLowerCase()); knownCommands.remove(alias.toLowerCase(java.util.Locale.ENGLISH));
} }
} }
} }

Datei anzeigen

@ -54,7 +54,7 @@ public class EnchantCommand extends VanillaCommand {
String itemName = item.getType().toString().replaceAll("_", " "); String itemName = item.getType().toString().replaceAll("_", " ");
itemName = WordUtils.capitalizeFully(itemName); itemName = WordUtils.capitalizeFully(itemName);
Enchantment enchantment = getEnchantment(args[1].toUpperCase()); Enchantment enchantment = getEnchantment(args[1].toUpperCase(java.util.Locale.ENGLISH));
if (enchantment == null) { if (enchantment == null) {
sender.sendMessage(String.format("Enchantment does not exist: %s", args[1])); sender.sendMessage(String.format("Enchantment does not exist: %s", args[1]));
} else { } else {

Datei anzeigen

@ -436,7 +436,7 @@ public class ScoreboardCommand extends VanillaCommand {
sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'"); sender.sendMessage(ChatColor.RED + "No team was found by the name '" + teamName + "'");
return false; return false;
} }
String option = args[3].toLowerCase(); String option = args[3].toLowerCase(java.util.Locale.ENGLISH);
if (!option.equals("friendlyfire") && !option.equals("color") && !option.equals("seefriendlyinvisibles")) { if (!option.equals("friendlyfire") && !option.equals("color") && !option.equals("seefriendlyinvisibles")) {
sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>"); sender.sendMessage(ChatColor.RED + "/scoreboard teams option <team> <friendlyfire|color|seefriendlyinvisibles> <value>");
return false; return false;
@ -448,7 +448,7 @@ public class ScoreboardCommand extends VanillaCommand {
sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false"); sender.sendMessage(ChatColor.RED + "Valid values for option " + option + " are: true and false");
} }
} else { } else {
String value = args[4].toLowerCase(); String value = args[4].toLowerCase(java.util.Locale.ENGLISH);
if (option.equals("color")) { if (option.equals("color")) {
ChatColor color = TEAMS_OPTION_COLOR.get(value); ChatColor color = TEAMS_OPTION_COLOR.get(value);
if (color == null) { if (color == null) {

Datei anzeigen

@ -64,9 +64,9 @@ public class VersionCommand extends BukkitCommand {
} }
boolean found = false; boolean found = false;
pluginName = pluginName.toLowerCase(); pluginName = pluginName.toLowerCase(java.util.Locale.ENGLISH);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (plugin.getName().toLowerCase().contains(pluginName)) { if (plugin.getName().toLowerCase(java.util.Locale.ENGLISH).contains(pluginName)) {
describeToSender(plugin, sender); describeToSender(plugin, sender);
found = true; found = true;
} }
@ -131,7 +131,7 @@ public class VersionCommand extends BukkitCommand {
if (args.length == 1) { if (args.length == 1) {
List<String> completions = new ArrayList<String>(); List<String> completions = new ArrayList<String>();
String toComplete = args[0].toLowerCase(); String toComplete = args[0].toLowerCase(java.util.Locale.ENGLISH);
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) { if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
completions.add(plugin.getName()); completions.add(plugin.getName());

Datei anzeigen

@ -215,7 +215,7 @@ public enum EntityType {
static { static {
for (EntityType type : values()) { for (EntityType type : values()) {
if (type.name != null) { if (type.name != null) {
NAME_MAP.put(type.name.toLowerCase(), type); NAME_MAP.put(type.name.toLowerCase(java.util.Locale.ENGLISH), type);
} }
if (type.typeId > 0) { if (type.typeId > 0) {
ID_MAP.put(type.typeId, type); ID_MAP.put(type.typeId, type);
@ -272,7 +272,7 @@ public enum EntityType {
if (name == null) { if (name == null) {
return null; return null;
} }
return NAME_MAP.get(name.toLowerCase()); return NAME_MAP.get(name.toLowerCase(java.util.Locale.ENGLISH));
} }
/** /**

Datei anzeigen

@ -50,7 +50,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); throw new IllegalArgumentException("Permission name cannot be null");
} }
return permissions.containsKey(name.toLowerCase()); return permissions.containsKey(name.toLowerCase(java.util.Locale.ENGLISH));
} }
public boolean isPermissionSet(Permission perm) { public boolean isPermissionSet(Permission perm) {
@ -66,7 +66,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission name cannot be null"); throw new IllegalArgumentException("Permission name cannot be null");
} }
String name = inName.toLowerCase(); String name = inName.toLowerCase(java.util.Locale.ENGLISH);
if (isPermissionSet(name)) { if (isPermissionSet(name)) {
return permissions.get(name).getValue(); return permissions.get(name).getValue();
@ -86,7 +86,7 @@ public class PermissibleBase implements Permissible {
throw new IllegalArgumentException("Permission cannot be null"); throw new IllegalArgumentException("Permission cannot be null");
} }
String name = perm.getName().toLowerCase(); String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
if (isPermissionSet(name)) { if (isPermissionSet(name)) {
return permissions.get(name).getValue(); return permissions.get(name).getValue();
@ -151,7 +151,7 @@ public class PermissibleBase implements Permissible {
Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent); Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
for (Permission perm : defaults) { for (Permission perm : defaults) {
String name = perm.getName().toLowerCase(); String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true)); permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
calculateChildPermissions(perm.getChildren(), false, null); calculateChildPermissions(perm.getChildren(), false, null);
@ -181,7 +181,7 @@ public class PermissibleBase implements Permissible {
for (String name : keys) { for (String name : keys) {
Permission perm = Bukkit.getServer().getPluginManager().getPermission(name); Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
boolean value = children.get(name) ^ invert; boolean value = children.get(name) ^ invert;
String lname = name.toLowerCase(); String lname = name.toLowerCase(java.util.Locale.ENGLISH);
permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value)); permissions.put(lname, new PermissionAttachmentInfo(parent, lname, attachment, value));
Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent); Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);

Datei anzeigen

@ -181,7 +181,7 @@ public class Permission {
*/ */
public Permission addParent(String name, boolean value) { public Permission addParent(String name, boolean value) {
PluginManager pm = Bukkit.getServer().getPluginManager(); PluginManager pm = Bukkit.getServer().getPluginManager();
String lname = name.toLowerCase(); String lname = name.toLowerCase(java.util.Locale.ENGLISH);
Permission perm = pm.getPermission(lname); Permission perm = pm.getPermission(lname);

Datei anzeigen

@ -83,7 +83,7 @@ public class PermissionAttachment {
* @param value New value of the permission * @param value New value of the permission
*/ */
public void setPermission(String name, boolean value) { public void setPermission(String name, boolean value) {
permissions.put(name.toLowerCase(), value); permissions.put(name.toLowerCase(java.util.Locale.ENGLISH), value);
permissible.recalculatePermissions(); permissible.recalculatePermissions();
} }
@ -106,7 +106,7 @@ public class PermissionAttachment {
* @param name Name of the permission to remove * @param name Name of the permission to remove
*/ */
public void unsetPermission(String name) { public void unsetPermission(String name) {
permissions.remove(name.toLowerCase()); permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH));
permissible.recalculatePermissions(); permissible.recalculatePermissions();
} }

Datei anzeigen

@ -48,7 +48,7 @@ public enum PermissionDefault {
* @return Specified value, or null if not found * @return Specified value, or null if not found
*/ */
public static PermissionDefault getByName(String name) { public static PermissionDefault getByName(String name) {
return lookup.get(name.toLowerCase().replaceAll("[^a-z!]", "")); return lookup.get(name.toLowerCase(java.util.Locale.ENGLISH).replaceAll("[^a-z!]", ""));
} }
@Override @Override

Datei anzeigen

@ -974,7 +974,7 @@ public final class PluginDescriptionFile {
if (map.get("load") != null) { if (map.get("load") != null) {
try { try {
order = PluginLoadOrder.valueOf(((String) map.get("load")).toUpperCase().replaceAll("\\W", "")); order = PluginLoadOrder.valueOf(((String) map.get("load")).toUpperCase(java.util.Locale.ENGLISH).replaceAll("\\W", ""));
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
throw new InvalidDescriptionException(ex, "load is of wrong type"); throw new InvalidDescriptionException(ex, "load is of wrong type");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {

Datei anzeigen

@ -588,11 +588,11 @@ public final class SimplePluginManager implements PluginManager {
} }
public Permission getPermission(String name) { public Permission getPermission(String name) {
return permissions.get(name.toLowerCase()); return permissions.get(name.toLowerCase(java.util.Locale.ENGLISH));
} }
public void addPermission(Permission perm) { public void addPermission(Permission perm) {
String name = perm.getName().toLowerCase(); String name = perm.getName().toLowerCase(java.util.Locale.ENGLISH);
if (permissions.containsKey(name)) { if (permissions.containsKey(name)) {
throw new IllegalArgumentException("The permission " + name + " is already defined!"); throw new IllegalArgumentException("The permission " + name + " is already defined!");
@ -611,11 +611,11 @@ public final class SimplePluginManager implements PluginManager {
} }
public void removePermission(String name) { public void removePermission(String name) {
permissions.remove(name.toLowerCase()); permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH));
} }
public void recalculatePermissionDefaults(Permission perm) { public void recalculatePermissionDefaults(Permission perm) {
if (perm != null && permissions.containsKey(perm.getName().toLowerCase())) { if (perm != null && permissions.containsKey(perm.getName().toLowerCase(java.util.Locale.ENGLISH))) {
defaultPerms.get(true).remove(perm); defaultPerms.get(true).remove(perm);
defaultPerms.get(false).remove(perm); defaultPerms.get(false).remove(perm);
@ -643,7 +643,7 @@ public final class SimplePluginManager implements PluginManager {
} }
public void subscribeToPermission(String permission, Permissible permissible) { public void subscribeToPermission(String permission, Permissible permissible) {
String name = permission.toLowerCase(); String name = permission.toLowerCase(java.util.Locale.ENGLISH);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) { if (map == null) {
@ -655,7 +655,7 @@ public final class SimplePluginManager implements PluginManager {
} }
public void unsubscribeFromPermission(String permission, Permissible permissible) { public void unsubscribeFromPermission(String permission, Permissible permissible) {
String name = permission.toLowerCase(); String name = permission.toLowerCase(java.util.Locale.ENGLISH);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map != null) { if (map != null) {
@ -668,7 +668,7 @@ public final class SimplePluginManager implements PluginManager {
} }
public Set<Permissible> getPermissionSubscriptions(String permission) { public Set<Permissible> getPermissionSubscriptions(String permission) {
String name = permission.toLowerCase(); String name = permission.toLowerCase(java.util.Locale.ENGLISH);
Map<Permissible, Boolean> map = permSubs.get(name); Map<Permissible, Boolean> map = permSubs.get(name);
if (map == null) { if (map == null) {

Datei anzeigen

@ -398,11 +398,11 @@ public abstract class JavaPlugin extends PluginBase {
* @return the plugin command if found, otherwise null * @return the plugin command if found, otherwise null
*/ */
public PluginCommand getCommand(String name) { public PluginCommand getCommand(String name) {
String alias = name.toLowerCase(); String alias = name.toLowerCase(java.util.Locale.ENGLISH);
PluginCommand command = getServer().getPluginCommand(alias); PluginCommand command = getServer().getPluginCommand(alias);
if (command == null || command.getPlugin() != this) { if (command == null || command.getPlugin() != this) {
command = getServer().getPluginCommand(description.getName().toLowerCase() + ":" + alias); command = getServer().getPluginCommand(description.getName().toLowerCase(java.util.Locale.ENGLISH) + ":" + alias);
} }
if (command != null && command.getPlugin() == this) { if (command != null && command.getPlugin() == this) {

Datei anzeigen

@ -249,7 +249,7 @@ public abstract class PotionEffectType {
*/ */
public static PotionEffectType getByName(String name) { public static PotionEffectType getByName(String name) {
Validate.notNull(name, "name cannot be null"); Validate.notNull(name, "name cannot be null");
return byName.get(name.toLowerCase()); return byName.get(name.toLowerCase(java.util.Locale.ENGLISH));
} }
/** /**
@ -260,7 +260,7 @@ public abstract class PotionEffectType {
* @param type PotionType to register * @param type PotionType to register
*/ */
public static void registerPotionEffectType(PotionEffectType type) { public static void registerPotionEffectType(PotionEffectType type) {
if (byId[type.id] != null || byName.containsKey(type.getName().toLowerCase())) { if (byId[type.id] != null || byName.containsKey(type.getName().toLowerCase(java.util.Locale.ENGLISH))) {
throw new IllegalArgumentException("Cannot set already-set type"); throw new IllegalArgumentException("Cannot set already-set type");
} else if (!acceptingNew) { } else if (!acceptingNew) {
throw new IllegalStateException( throw new IllegalStateException(
@ -268,7 +268,7 @@ public abstract class PotionEffectType {
} }
byId[type.id] = type; byId[type.id] = type;
byName.put(type.getName().toLowerCase(), type); byName.put(type.getName().toLowerCase(java.util.Locale.ENGLISH), type);
} }
/** /**

Datei anzeigen

@ -78,7 +78,7 @@ public class MaterialTest {
@Test @Test
public void matchMaterialByLowerCaseAndSpaces() { public void matchMaterialByLowerCaseAndSpaces() {
for (Material material : Material.values()) { for (Material material : Material.values()) {
String name = material.toString().replaceAll("_", " ").toLowerCase(); String name = material.toString().replaceAll("_", " ").toLowerCase(java.util.Locale.ENGLISH);
assertThat(Material.matchMaterial(name), is(material)); assertThat(Material.matchMaterial(name), is(material));
} }
} }