From bc2578b7887f38e8106a1d4c2ce000618c19bb23 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 13 Feb 2012 19:40:33 +0000 Subject: [PATCH 1/6] Caching regex return in user cleanup. (Pushing this for testing purposes). --- Essentials/src/com/earth2me/essentials/Util.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 65077a7fc..c6df66165 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -22,11 +22,17 @@ 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 final static Pattern INVALIDCHARS = Pattern.compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFC]"); + private static Map sanitizedName = new HashMap(); public static String sanitizeFileName(final String name) { - return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + if (sanitizedName.containsKey(name)) { + return sanitizedName.get(name); + } + final String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); + sanitizedName.put(name, newName); + return newName; } public static String sanitizeString(final String string) From a6ac333a7461ce271ee3eb4d85a18a4bbdb610cd Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 13 Feb 2012 21:32:05 +0100 Subject: [PATCH 2/6] Less sanitizing for more performance --- .../src/com/earth2me/essentials/UserMap.java | 20 ++++++++++++++----- .../src/com/earth2me/essentials/Util.java | 5 ----- 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 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 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 implements IConf { keys.remove(Util.sanitizeFileName(name)); users.invalidate(Util.sanitizeFileName(name)); + users.invalidate(name); } public Set getAllUniqueUsers() @@ -116,8 +121,13 @@ public class UserMap extends CacheLoader 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 sanitizedName = new HashMap(); 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; } From 9fe119e720fa5dc640adc2a6c35992d8f3230eb6 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Tue, 14 Feb 2012 14:16:34 -0500 Subject: [PATCH 3/6] fix typo in config.yml --- Essentials/src/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 63770a293..e43e63d45 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -335,7 +335,7 @@ non-ess-in-help: true # Hide plugins which dont give a permission # You can override a true value here for a single plugin by adding a permission to a user/group. -# The indervidual permission is: essentials.help., anyone with essentials.* or '*' will see all help this setting reguardless. +# The individual permission is: essentials.help., anyone with essentials.* or '*' will see all help this setting reguardless. # You can use negitive permissions to remove access to just a single plugins help if the following is enabled. hide-permissionless-help: true From 3b7d194902810cd38155766cb6fbfbd8b75a8932 Mon Sep 17 00:00:00 2001 From: Iaccidentally Date: Tue, 14 Feb 2012 14:21:07 -0500 Subject: [PATCH 4/6] fix typo in config.yml (another one) --- Essentials/src/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 63770a293..5c338a8df 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -519,7 +519,7 @@ protect: build: true # Should people with build: false in permissions be allowed to use items - # Set true to disable useing for those people + # Set true to disable using for those people use: true # Should we tell people they are not allowed to build From 3c98718387cf8c612e11f00df216c9ffb268568e Mon Sep 17 00:00:00 2001 From: snowleo Date: Tue, 14 Feb 2012 20:29:45 +0100 Subject: [PATCH 5/6] Don't return null, throw an exception --- .../src/com/earth2me/essentials/UserMap.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java index f15e5edd9..94b504241 100644 --- a/Essentials/src/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/com/earth2me/essentials/UserMap.java @@ -77,8 +77,17 @@ public class UserMap extends CacheLoader implements IConf public User load(final String name) throws Exception { String sanitizedName = Util.sanitizeFileName(name); - if (!sanitizedName.equals(name)) { - return getUser(sanitizedName); + if (!sanitizedName.equals(name)) + { + User user = getUser(sanitizedName); + if (user == null) + { + throw new Exception("User not found!"); + } + else + { + return user; + } } for (Player player : ess.getServer().getOnlinePlayers()) { @@ -119,12 +128,12 @@ public class UserMap extends CacheLoader implements IConf { return keys.size(); } - + 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"); From f0c0ee1a8dd90de1524032e92c65df5e823a7b1f Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 14 Feb 2012 23:55:29 +0000 Subject: [PATCH 6/6] /spawnmob - Only list mobs you have permission to spawn. --- .../essentials/commands/Commandspawnmob.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index f867a1503..948c82871 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import java.util.Locale; import java.util.Random; +import java.util.Set; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Server; @@ -26,7 +27,19 @@ public class Commandspawnmob extends EssentialsCommand { if (args.length < 1) { - throw new NotEnoughArgumentsException(_("mobsAvailable", Util.joinList(Mob.getMobList()))); + Set availableList = Mob.getMobList(); + for (String mob : availableList) + { + if (!user.isAuthorized("essentials.spawnmob." + mob.toLowerCase())) + { + availableList.remove(mob); + } + } + if (availableList.isEmpty()) + { + availableList.add(_("none")); + } + throw new NotEnoughArgumentsException(_("mobsAvailable", Util.joinList(availableList))); } @@ -79,7 +92,7 @@ public class Commandspawnmob extends EssentialsCommand User otherUser = null; if (args.length >= 3) { - otherUser = getPlayer(ess.getServer(), args, 2); + otherUser = getPlayer(ess.getServer(), args, 2); } final Location loc = (otherUser == null) ? block.getLocation() : otherUser.getLocation(); final Location sloc = Util.getSafeDestination(loc);