diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserData.java b/Essentials/src/main/java/com/earth2me/essentials/UserData.java index ae71b0cabb1..47ea441f9b7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserData.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserData.java @@ -143,10 +143,12 @@ private String getHomeName(String search) { } return search; } - + //Optimize character compatibility public Location getHome(final String name) { - final String search = getHomeName(name); - final LazyLocation loc = holder.homes().get(search); + LazyLocation loc = holder.homes().get(getHomeName(name)); + if (loc == null) { + loc = holder.homes().get(getHomeName(StringUtil.safeString(name))); + } return loc != null ? loc.location() : null; } @@ -179,28 +181,32 @@ public List getHomes() { public void setHome(String name, final Location loc) { //Invalid names will corrupt the yaml - name = StringUtil.safeString(name); + name = StringUtil.new_safeString(name); holder.homes().put(name, LazyLocation.fromLocation(loc)); config.save(); } public void delHome(final String name) throws Exception { String search = getHomeName(name); - if (!holder.homes().containsKey(search)) { - search = StringUtil.safeString(search); - } - if (holder.homes().containsKey(search)) { - holder.homes().remove(search); + String safeSearch = StringUtil.new_safeString(search); + String oldSafeSearch = StringUtil.safeString(search); + if (holder.homes().containsKey(safeSearch)) { + holder.homes().remove(safeSearch); + config.save(); + } else if (holder.homes().containsKey(oldSafeSearch)) { + holder.homes().remove(oldSafeSearch); config.save(); } else { throw new TranslatableException("invalidHome", search); } } + public void renameHome(final String name, final String newName) throws Exception { final LazyLocation location = holder.homes().remove(name); + //If possible, it is necessary to improve the compatibility here to make it support underscores if (location != null) { - holder.homes().put(StringUtil.safeString(newName), location); + holder.homes().put(StringUtil.new_safeString(newName), location); config.save(); } else { throw new TranslatableException("invalidHome", name); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Worth.java b/Essentials/src/main/java/com/earth2me/essentials/Worth.java index d02d1853ca1..8e6c1505efe 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Worth.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Worth.java @@ -32,6 +32,7 @@ public Worth(final File dataFolder) { public BigDecimal getPrice(final IEssentials ess, final ItemStack itemStack) { BigDecimal result = BigDecimal.ONE.negate(); + final String itemname = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", ""); if (VersionUtil.PRE_FLATTENING) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java index a8017dcbf8a..078ba2f8316 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java @@ -15,6 +15,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Optional; import java.util.concurrent.CompletableFuture; public class Commandhome extends EssentialsCommand { @@ -124,7 +125,9 @@ private void goHome(final User user, final User player, final String home, final if (home.length() < 1) { throw new NotEnoughArgumentsException(); } - final Location loc = player.getHome(home); + + final Location loc = player.getHome(home); + if (loc == null) { throw new NotEnoughArgumentsException(); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/StringUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/StringUtil.java index d9d6602d7b1..4d6132587a1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/StringUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/StringUtil.java @@ -10,17 +10,18 @@ import java.util.regex.Pattern; public final class StringUtil { - private static final Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9-]"); + private static final Pattern INVALIDCHARACTER = Pattern.compile("[/\\\\:*?\"<>|\\x00-\\x1F]"); private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]"); @SuppressWarnings("CheckStyle") - private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]"); + private static final Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]"); + private StringUtil() { } //Used to clean file names before saving to disk public static String sanitizeFileName(final String name) { - return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + return INVALIDCHARACTER.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); } //Used to clean strings/names before saving as filenames/permissions @@ -30,6 +31,12 @@ public static String safeString(final String string) { } return STRICTINVALIDCHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_"); } + public static String new_safeString(final String string) { + if (string == null) { + return null; + } + return INVALIDCHARACTER.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + } //Less restrictive string sanitizing, when not used as perm or filename public static String sanitizeString(final String string) {