mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-11-20 10:09:25 +00:00
Remove '-' from valid account names again.
This could cause issues with NPC's converted to UUID before this version.
This commit is contained in:
parent
04666b66b4
commit
c12373bf41
4 changed files with 11 additions and 10 deletions
|
@ -548,7 +548,7 @@ public class EssentialsUpgrade
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.sleep(10000);
|
Thread.sleep(15000);
|
||||||
}
|
}
|
||||||
catch (InterruptedException ex)
|
catch (InterruptedException ex)
|
||||||
{
|
{
|
||||||
|
@ -595,7 +595,7 @@ public class EssentialsUpgrade
|
||||||
|
|
||||||
countFiles++;
|
countFiles++;
|
||||||
|
|
||||||
final String name = string.substring(0, string.length() - 4);
|
String name = string.substring(0, string.length() - 4);
|
||||||
EssentialsUserConf config;
|
EssentialsUserConf config;
|
||||||
UUID uuid = null;
|
UUID uuid = null;
|
||||||
try
|
try
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final String sanitizedName = StringUtil.sanitizeFileName(name);
|
final String sanitizedName = StringUtil.safeString(name);
|
||||||
if (names.containsKey(sanitizedName))
|
if (names.containsKey(sanitizedName))
|
||||||
{
|
{
|
||||||
final UUID uuid = names.get(sanitizedName);
|
final UUID uuid = names.get(sanitizedName);
|
||||||
|
@ -93,7 +93,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
|
|
||||||
for (Player player : ess.getServer().getOnlinePlayers())
|
for (Player player : ess.getServer().getOnlinePlayers())
|
||||||
{
|
{
|
||||||
String sanitizedPlayer = StringUtil.sanitizeFileName(player.getName());
|
String sanitizedPlayer = StringUtil.safeString(player.getName());
|
||||||
if (sanitizedPlayer.equalsIgnoreCase(sanitizedName))
|
if (sanitizedPlayer.equalsIgnoreCase(sanitizedName))
|
||||||
{
|
{
|
||||||
User user = new User(player, ess);
|
User user = new User(player, ess);
|
||||||
|
@ -144,7 +144,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
keys.add(uuid);
|
keys.add(uuid);
|
||||||
if (name != null && name.length() > 0)
|
if (name != null && name.length() > 0)
|
||||||
{
|
{
|
||||||
final String keyName = StringUtil.sanitizeFileName(name);
|
final String keyName = StringUtil.safeString(name);
|
||||||
if (!names.containsKey(keyName) || !names.get(keyName).equals(uuid))
|
if (!names.containsKey(keyName) || !names.get(keyName).equals(uuid))
|
||||||
{
|
{
|
||||||
names.put(keyName, uuid);
|
names.put(keyName, uuid);
|
||||||
|
@ -195,7 +195,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
users.invalidate(uuid);
|
users.invalidate(uuid);
|
||||||
}
|
}
|
||||||
names.remove(name);
|
names.remove(name);
|
||||||
names.remove(StringUtil.sanitizeFileName(name));
|
names.remove(StringUtil.safeString(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> getAllUniqueUsers()
|
public Set<UUID> getAllUniqueUsers()
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class Economy
|
||||||
private static void createNPCFile(String name)
|
private static void createNPCFile(String name)
|
||||||
{
|
{
|
||||||
File folder = new File(ess.getDataFolder(), "userdata");
|
File folder = new File(ess.getDataFolder(), "userdata");
|
||||||
|
name = StringUtil.safeString(name);
|
||||||
if (!folder.exists())
|
if (!folder.exists())
|
||||||
{
|
{
|
||||||
folder.mkdirs();
|
folder.mkdirs();
|
||||||
|
@ -450,4 +451,3 @@ public class Economy
|
||||||
deleteNPC(name);
|
deleteNPC(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,18 +7,19 @@ import java.util.regex.Pattern;
|
||||||
public class StringUtil
|
public class StringUtil
|
||||||
{
|
{
|
||||||
private static final Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9-]");
|
private static final Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9-]");
|
||||||
|
private static final Pattern STRICTINVALIDCHARS = Pattern.compile("[^a-z0-9]");
|
||||||
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-\uFFFC]");
|
||||||
|
|
||||||
//Used to clean file names before saving to disk
|
//Used to clean file names before saving to disk
|
||||||
public static String sanitizeFileName(final String name)
|
public static String sanitizeFileName(final String name)
|
||||||
{
|
{
|
||||||
return safeString(name);
|
return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Used to clean strings/names before saving as filenames/permissions
|
//Used to clean strings/names before saving as filenames/permissions
|
||||||
public static String safeString(final String string)
|
public static String safeString(final String string)
|
||||||
{
|
{
|
||||||
return INVALIDFILECHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
return STRICTINVALIDCHARS.matcher(string.toLowerCase(Locale.ENGLISH)).replaceAll("_");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Less restrictive string sanitizing, when not used as perm or filename
|
//Less restrictive string sanitizing, when not used as perm or filename
|
||||||
|
|
Loading…
Reference in a new issue