summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-02-13 21:32:05 +0100
committersnowleo <schneeleo@gmail.com>2012-02-13 21:32:05 +0100
commita6ac333a7461ce271ee3eb4d85a18a4bbdb610cd (patch)
tree6c581b7a6d1f06e1634c059dd1e1d9d40d489b1d
parentbc2578b7887f38e8106a1d4c2ce000618c19bb23 (diff)
downloadEssentials-a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd.tar
Essentials-a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd.tar.gz
Essentials-a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd.tar.lz
Essentials-a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd.tar.xz
Essentials-a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd.zip
Less sanitizing for more performance
-rw-r--r--Essentials/src/com/earth2me/essentials/UserMap.java20
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java5
2 files changed, 15 insertions, 10 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java
index d15438c7d..f15e5edd9 100644
--- a/Essentials/src/com/earth2me/essentials/UserMap.java
+++ b/Essentials/src/com/earth2me/essentials/UserMap.java
@@ -61,7 +61,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{
try
{
- return users.get(Util.sanitizeFileName(name));
+ return users.get(name);
}
catch (ExecutionException ex)
{
@@ -76,18 +76,22 @@ public class UserMap extends CacheLoader<String, User> implements IConf
@Override
public User load(final String name) throws Exception
{
+ String sanitizedName = Util.sanitizeFileName(name);
+ if (!sanitizedName.equals(name)) {
+ return getUser(sanitizedName);
+ }
for (Player player : ess.getServer().getOnlinePlayers())
{
if (player.getName().equalsIgnoreCase(name))
{
- keys.add(Util.sanitizeFileName(name));
+ keys.add(sanitizedName);
return new User(player, ess);
}
}
- final File userFile = getUserFile(name);
+ final File userFile = getUserFile2(sanitizedName);
if (userFile.exists())
{
- keys.add(Util.sanitizeFileName(name));
+ keys.add(sanitizedName);
return new User(new OfflinePlayer(name, ess), ess);
}
throw new Exception("User not found!");
@@ -103,6 +107,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{
keys.remove(Util.sanitizeFileName(name));
users.invalidate(Util.sanitizeFileName(name));
+ users.invalidate(name);
}
public Set<String> getAllUniqueUsers()
@@ -117,7 +122,12 @@ public class UserMap extends CacheLoader<String, User> implements IConf
public File getUserFile(final String name)
{
+ return getUserFile2(Util.sanitizeFileName(name));
+ }
+
+ private File getUserFile2(final String name)
+ {
final File userFolder = new File(ess.getDataFolder(), "userdata");
- return new File(userFolder, Util.sanitizeFileName(name) + ".yml");
+ return new File(userFolder, name + ".yml");
}
}
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index c6df66165..3e3a7efd0 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -23,15 +23,10 @@ public class Util
private final static Logger logger = Logger.getLogger("Minecraft");
private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]");
private final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]");
- private static Map<String,String> sanitizedName = new HashMap<String,String>();
public static String sanitizeFileName(final String name)
{
- if (sanitizedName.containsKey(name)) {
- return sanitizedName.get(name);
- }
final String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
- sanitizedName.put(name, newName);
return newName;
}