mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 12:15:53 +01:00
Use explicit locale for upper/lowercase. EXPERIMENTAL: may be bugs from this commit
This commit is contained in:
parent
147df027bb
commit
ea74254cdd
@ -13,6 +13,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -558,7 +559,7 @@ public class NPCCommands {
|
||||
if (permissions != null) {
|
||||
perms.addAll(Arrays.asList(permissions.split(",")));
|
||||
}
|
||||
if (command.toLowerCase().startsWith("npc select"))
|
||||
if (command.startsWith("npc select"))
|
||||
throw new CommandException("npc select not currently supported within commands. Use --id <id> instead");
|
||||
|
||||
try {
|
||||
@ -707,8 +708,8 @@ public class NPCCommands {
|
||||
flags = "mo")
|
||||
public void controllable(CommandContext args, CommandSender sender, NPC npc,
|
||||
@Flag("controls") BuiltInControls controls, @Flag("enabled") Boolean enabled) throws CommandException {
|
||||
if ((npc.isSpawned() && !sender.hasPermission(
|
||||
"citizens.npc.controllable." + npc.getEntity().getType().name().toLowerCase().replace("_", "")))
|
||||
if ((npc.isSpawned()
|
||||
&& !sender.hasPermission("citizens.npc.controllable." + Util.prettyEnum(npc.getEntity().getType())))
|
||||
|| !sender.hasPermission("citizens.npc.controllable"))
|
||||
throw new NoPermissionsException();
|
||||
if (!npc.hasTrait(Controllable.class) && enabled == null) {
|
||||
@ -801,7 +802,7 @@ public class NPCCommands {
|
||||
throw new CommandException();
|
||||
|
||||
if (!sender.hasPermission("citizens.npc.create.*") && !sender.hasPermission("citizens.npc.createall")
|
||||
&& !sender.hasPermission("citizens.npc.create." + type.name().toLowerCase().replace("_", "")))
|
||||
&& !sender.hasPermission("citizens.npc.create." + Util.prettyEnum(type)))
|
||||
throw new NoPermissionsException();
|
||||
|
||||
if ((at != null || registryName != null || traits != null || templateName != null)
|
||||
@ -1180,8 +1181,7 @@ public class NPCCommands {
|
||||
public void gamemode(CommandContext args, CommandSender sender, NPC npc, @Arg(1) GameMode mode) {
|
||||
Player player = (Player) npc.getEntity();
|
||||
if (args.argsLength() == 1) {
|
||||
Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(),
|
||||
player.getGameMode().name().toLowerCase());
|
||||
Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(), Util.prettyEnum(player.getGameMode()));
|
||||
return;
|
||||
}
|
||||
if (mode == null) {
|
||||
@ -2845,7 +2845,7 @@ public class NPCCommands {
|
||||
if (args.hasValueFlag("color")) {
|
||||
if (color != null) {
|
||||
trait.setColor(color);
|
||||
Messaging.sendTr(sender, Messages.SHEEP_COLOR_SET, color.toString().toLowerCase());
|
||||
Messaging.sendTr(sender, Messages.SHEEP_COLOR_SET, Util.prettyEnum(color));
|
||||
} else {
|
||||
Messaging.sendErrorTr(sender, Messages.INVALID_SHEEP_COLOR, Util.listValuesPretty(DyeColor.values()));
|
||||
}
|
||||
@ -2875,7 +2875,7 @@ public class NPCCommands {
|
||||
}
|
||||
NPCShop shop = npc != null ? npc.getOrAddTrait(ShopTrait.class).getDefaultShop() : null;
|
||||
if (args.argsLength() == 3) {
|
||||
shop = shops.getShop(args.getString(2).toLowerCase());
|
||||
shop = shops.getShop(args.getString(2));
|
||||
}
|
||||
if (shop == null)
|
||||
throw new CommandUsageException();
|
||||
@ -3653,7 +3653,7 @@ public class NPCCommands {
|
||||
trait.setInterested(!trait.isInterested());
|
||||
}
|
||||
if (variant != null) {
|
||||
variant = variant.toUpperCase();
|
||||
variant = variant.toUpperCase(Locale.US);
|
||||
try {
|
||||
Wolf.Variant.class.getField(variant);
|
||||
} catch (Throwable t) {
|
||||
|
@ -12,6 +12,7 @@ import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.trait.SheepTrait;
|
||||
import net.citizensnpcs.trait.WoolColor;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
public class SheepEquipper implements Equipper {
|
||||
@Override
|
||||
@ -28,7 +29,7 @@ public class SheepEquipper implements Equipper {
|
||||
DyeColor color = dye.getColor();
|
||||
toEquip.getOrAddTrait(WoolColor.class).setColor(color);
|
||||
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_SHEEP_COLOURED, toEquip.getName(),
|
||||
color.name().toLowerCase().replace("_", " "));
|
||||
Util.prettyEnum(color));
|
||||
|
||||
hand.setAmount(hand.getAmount() - 1);
|
||||
} else {
|
||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.npc;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -176,7 +177,7 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Trait> T getTrait(String name) {
|
||||
TraitInfo info = registered.get(name.toLowerCase());
|
||||
TraitInfo info = registered.get(name.toLowerCase(Locale.US));
|
||||
if (info == null)
|
||||
return null;
|
||||
return (T) create(info);
|
||||
@ -184,7 +185,7 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
|
||||
@Override
|
||||
public Class<? extends Trait> getTraitClass(String name) {
|
||||
TraitInfo info = registered.get(name.toLowerCase());
|
||||
TraitInfo info = registered.get(name.toLowerCase(Locale.US));
|
||||
return info == null ? null : info.getTraitClass();
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -509,7 +510,7 @@ public class CommandTrait extends Trait {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().charAt(0) + name().substring(1).toLowerCase();
|
||||
return name().charAt(0) + name().substring(1).toLowerCase(Locale.US);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,8 +52,7 @@ public class Controllable extends Trait implements Toggleable {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission(
|
||||
"citizens.npc.controllable." + npc.getEntity().getType().name().toLowerCase().replace("_", ""))
|
||||
if (!player.hasPermission("citizens.npc.controllable." + Util.prettyEnum(npc.getEntity().getType()))
|
||||
|| !player.hasPermission("citizens.npc.controllable")
|
||||
|| ownerRequired && !npc.getOrAddTrait(Owner.class).isOwnedBy(player))
|
||||
return;
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.trait;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
@ -803,7 +804,7 @@ public class HologramTrait extends Trait {
|
||||
public static class TabCompletions implements CompletionsProvider {
|
||||
@Override
|
||||
public Collection<String> getCompletions(CommandContext args, CommandSender sender, NPC npc) {
|
||||
if (args.length() > 1 && npc != null && LINE_ARGS.contains(args.getString(1).toLowerCase())) {
|
||||
if (args.length() > 1 && npc != null && LINE_ARGS.contains(args.getString(1).toLowerCase(Locale.US))) {
|
||||
HologramTrait ht = npc.getOrAddTrait(HologramTrait.class);
|
||||
return IntStream.range(0, ht.getLines().size()).mapToObj(Integer::toString)
|
||||
.collect(Collectors.toList());
|
||||
@ -811,7 +812,7 @@ public class HologramTrait extends Trait {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static Set<String> LINE_ARGS = ImmutableSet.of("set", "remove", "margintop", "marginbottom");
|
||||
private static final Set<String> LINE_ARGS = ImmutableSet.of("set", "remove", "margintop", "marginbottom");
|
||||
}
|
||||
|
||||
public static class TextDisplayRenderer extends SingleEntityHologramRenderer {
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -340,7 +341,7 @@ public class Util {
|
||||
}
|
||||
|
||||
public static String listValuesPretty(Enum<?>[] values) {
|
||||
return "<yellow>" + Joiner.on("<green>, <yellow>").join(values).toLowerCase();
|
||||
return "<yellow>" + Joiner.on("<green>, <yellow>").join(values).toLowerCase(Locale.US);
|
||||
}
|
||||
|
||||
public static boolean locationWithinRange(Location current, Location target, double range) {
|
||||
@ -350,15 +351,15 @@ public class Util {
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T matchEnum(T[] values, String toMatch) {
|
||||
toMatch = toMatch.toLowerCase().replace('-', '_').replace(' ', '_');
|
||||
toMatch = toMatch.replace('-', '_').replace(' ', '_');
|
||||
for (T check : values) {
|
||||
if (toMatch.equals(check.name().toLowerCase())
|
||||
|| toMatch.equals("item") && check.name().equals("DROPPED_ITEM"))
|
||||
if (toMatch.equalsIgnoreCase(check.name())
|
||||
|| toMatch.equalsIgnoreCase("item") && check.name().equals("DROPPED_ITEM"))
|
||||
return check; // check for an exact match first
|
||||
|
||||
}
|
||||
for (T check : values) {
|
||||
String name = check.name().toLowerCase();
|
||||
String name = check.name().toLowerCase(Locale.US);
|
||||
if (name.replace("_", "").equals(toMatch) || name.startsWith(toMatch))
|
||||
return check;
|
||||
|
||||
@ -442,7 +443,7 @@ public class Util {
|
||||
}
|
||||
|
||||
public static String prettyEnum(Enum<?> e) {
|
||||
return e.name().toLowerCase().replace('_', ' ');
|
||||
return e.name().toLowerCase(Locale.US).replace('_', ' ');
|
||||
}
|
||||
|
||||
public static String prettyPrintLocation(Location to) {
|
||||
@ -451,10 +452,6 @@ public class Util {
|
||||
TWO_DIGIT_DECIMAL.format(to.getYaw()), TWO_DIGIT_DECIMAL.format(to.getPitch()));
|
||||
}
|
||||
|
||||
public static String rawtype(Enum<?>[] values) {
|
||||
return "<yellow>" + Joiner.on("<green>, <yellow>").join(values).toLowerCase();
|
||||
}
|
||||
|
||||
public static void runCommand(NPC npc, Player clicker, String command, boolean op, boolean player) {
|
||||
List<String> split = Splitter.on(' ').omitEmptyStrings().trimResults().limit(2).splitToList(command);
|
||||
String bungeeServer = split.size() == 2 && split.get(0).equalsIgnoreCase("server") ? split.get(1) : null;
|
||||
|
Loading…
Reference in New Issue
Block a user