Merge branch 'master' into release

This commit is contained in:
KHobbits 2012-02-14 23:56:02 +00:00
commit 1a2acb43ae
4 changed files with 45 additions and 12 deletions

View file

@ -61,7 +61,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{ {
try try
{ {
return users.get(Util.sanitizeFileName(name)); return users.get(name);
} }
catch (ExecutionException ex) catch (ExecutionException ex)
{ {
@ -76,18 +76,31 @@ public class UserMap extends CacheLoader<String, User> implements IConf
@Override @Override
public User load(final String name) throws Exception public User load(final String name) throws Exception
{ {
String sanitizedName = Util.sanitizeFileName(name);
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()) for (Player player : ess.getServer().getOnlinePlayers())
{ {
if (player.getName().equalsIgnoreCase(name)) if (player.getName().equalsIgnoreCase(name))
{ {
keys.add(Util.sanitizeFileName(name)); keys.add(sanitizedName);
return new User(player, ess); return new User(player, ess);
} }
} }
final File userFile = getUserFile(name); final File userFile = getUserFile2(sanitizedName);
if (userFile.exists()) if (userFile.exists())
{ {
keys.add(Util.sanitizeFileName(name)); keys.add(sanitizedName);
return new User(new OfflinePlayer(name, ess), ess); return new User(new OfflinePlayer(name, ess), ess);
} }
throw new Exception("User not found!"); throw new Exception("User not found!");
@ -103,6 +116,7 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{ {
keys.remove(Util.sanitizeFileName(name)); keys.remove(Util.sanitizeFileName(name));
users.invalidate(Util.sanitizeFileName(name)); users.invalidate(Util.sanitizeFileName(name));
users.invalidate(name);
} }
public Set<String> getAllUniqueUsers() public Set<String> getAllUniqueUsers()
@ -114,10 +128,15 @@ public class UserMap extends CacheLoader<String, User> implements IConf
{ {
return keys.size(); return keys.size();
} }
public File getUserFile(final String name) 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"); final File userFolder = new File(ess.getDataFolder(), "userdata");
return new File(userFolder, Util.sanitizeFileName(name) + ".yml"); return new File(userFolder, name + ".yml");
} }
} }

View file

@ -22,11 +22,12 @@ public class Util
} }
private final static Logger logger = Logger.getLogger("Minecraft"); private final static Logger logger = Logger.getLogger("Minecraft");
private final static Pattern INVALIDFILECHARS = Pattern.compile("[^a-z0-9]"); 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]");
public static String sanitizeFileName(final String name) public static String sanitizeFileName(final String name)
{ {
return INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_"); final String newName = INVALIDFILECHARS.matcher(name.toLowerCase(Locale.ENGLISH)).replaceAll("_");
return newName;
} }
public static String sanitizeString(final String string) public static String sanitizeString(final String string)

View file

@ -7,6 +7,7 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.Util; import com.earth2me.essentials.Util;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.Set;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
@ -26,7 +27,19 @@ public class Commandspawnmob extends EssentialsCommand
{ {
if (args.length < 1) if (args.length < 1)
{ {
throw new NotEnoughArgumentsException(_("mobsAvailable", Util.joinList(Mob.getMobList()))); Set<String> 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; User otherUser = null;
if (args.length >= 3) 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 loc = (otherUser == null) ? block.getLocation() : otherUser.getLocation();
final Location sloc = Util.getSafeDestination(loc); final Location sloc = Util.getSafeDestination(loc);

View file

@ -335,7 +335,7 @@ non-ess-in-help: true
# Hide plugins which dont give a permission # 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. # 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.<plugin>, anyone with essentials.* or '*' will see all help this setting reguardless. # The individual permission is: essentials.help.<plugin>, 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. # You can use negitive permissions to remove access to just a single plugins help if the following is enabled.
hide-permissionless-help: true hide-permissionless-help: true
@ -519,7 +519,7 @@ protect:
build: true build: true
# Should people with build: false in permissions be allowed to use items # 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 use: true
# Should we tell people they are not allowed to build # Should we tell people they are not allowed to build