summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-09-15 19:55:12 +0100
committerKHobbits <rob@khobbits.co.uk>2012-09-15 19:55:12 +0100
commita2886d76d2df4176a515e44346f13ec117c33565 (patch)
tree536b485f4328ddfb88e2ea6ba56cc90e0abf7456
parentcc0a65bacefded3ef91282c77653bfbf1f1e4668 (diff)
downloadEssentials-a2886d76d2df4176a515e44346f13ec117c33565.tar
Essentials-a2886d76d2df4176a515e44346f13ec117c33565.tar.gz
Essentials-a2886d76d2df4176a515e44346f13ec117c33565.tar.lz
Essentials-a2886d76d2df4176a515e44346f13ec117c33565.tar.xz
Essentials-a2886d76d2df4176a515e44346f13ec117c33565.zip
Fix Essentials /sethome to more strictly obey home limits.
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java21
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsethome.java70
-rw-r--r--Essentials/test/com/earth2me/essentials/UserTest.java2
4 files changed, 48 insertions, 55 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 5264292d1..90310cedb 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -54,19 +54,21 @@ public class Settings implements ISettings
@Override
public int getHomeLimit(final User user)
{
- final Set<String> homeList = getMultipleHomes();
- if (homeList == null)
+ int limit = 1;
+ if (user.isAuthorized("essentials.sethome.multiple"))
{
- //TODO: Replace this code to remove backwards compat, after settings are automatically updated
- // return getHomeLimit("default");
- return config.getInt("multiple-homes", 5);
+ limit = getHomeLimit("default");
}
- int limit = getHomeLimit("default");
- for (String set : homeList)
+
+ final Set<String> homeList = getMultipleHomes();
+ if (homeList != null)
{
- if (user.isAuthorized("essentials.sethome.multiple." + set) && (limit < getHomeLimit(set)))
+ for (String set : homeList)
{
- limit = getHomeLimit(set);
+ if (user.isAuthorized("essentials.sethome.multiple." + set) && (limit < getHomeLimit(set)))
+ {
+ limit = getHomeLimit(set);
+ }
}
}
return limit;
@@ -530,7 +532,6 @@ public class Settings implements ISettings
}
return newSigns;
}
-
private boolean warnOnBuildDisallow;
private boolean _warnOnBuildDisallow()
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 50213d02f..dbd56df12 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -248,16 +248,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return getHome(getHomes().get(0));
}
- public void setHome()
- {
- setHome("home", getLocation());
- }
-
- public void setHome(final String name)
- {
- setHome(name, getLocation());
- }
-
@Override
public void setLastLocation()
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java
index f622094d2..7ec1ba11d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.Locale;
+import org.bukkit.Location;
import org.bukkit.Server;
@@ -16,6 +17,10 @@ public class Commandsethome extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, String[] args) throws Exception
{
+ User usersHome = user;
+ String name = "home";
+ final Location location = user.getLocation();
+
if (args.length > 0)
{
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
@@ -27,33 +32,13 @@ public class Commandsethome extends EssentialsCommand
if (args.length < 2)
{
- if (user.isAuthorized("essentials.sethome.multiple"))
- {
- if ("bed".equals(args[0].toLowerCase(Locale.ENGLISH)))
- {
- throw new NotEnoughArgumentsException();
- }
- if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getHomeLimit(user))
- || (user.getHomes().contains(args[0].toLowerCase(Locale.ENGLISH))))
- {
- user.setHome(args[0].toLowerCase(Locale.ENGLISH));
- }
- else
- {
- throw new Exception(_("maxHomes", ess.getSettings().getHomeLimit(user)));
- }
-
- }
- else
- {
- throw new Exception(_("maxHomes", 1));
- }
+ name = args[0].toLowerCase(Locale.ENGLISH);
}
else
{
if (user.isAuthorized("essentials.sethome.others"))
{
- User usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
+ usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
if (usersHome == null)
{
usersHome = ess.getOfflineUser(args[0]);
@@ -62,24 +47,41 @@ public class Commandsethome extends EssentialsCommand
{
throw new Exception(_("playerNotFound"));
}
- String name = args[1].toLowerCase(Locale.ENGLISH);
- if (!user.isAuthorized("essentials.sethome.multiple"))
- {
- name = "home";
- }
- if ("bed".equals(name.toLowerCase(Locale.ENGLISH)))
- {
- throw new NotEnoughArgumentsException();
- }
- usersHome.setHome(name, user.getLocation());
+ name = args[1].toLowerCase(Locale.ENGLISH);
}
}
}
- else
+ if (checkHomeLimit(user, usersHome, name))
+ {
+ name = "home";
+ }
+ if ("bed".equals(name))
{
- user.setHome();
+ throw new NotEnoughArgumentsException();
}
+ usersHome.setHome(name, location);
user.sendMessage(_("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()));
}
+
+ private boolean checkHomeLimit(final User user, final User usersHome, String name) throws Exception
+ {
+ if (!user.isAuthorized("essentials.sethome.multiple.unlimited"))
+ {
+ int limit = ess.getSettings().getHomeLimit(user);
+ if (usersHome.getHomes().size() == limit && usersHome.getHomes().contains(name))
+ {
+ return false;
+ }
+ if (usersHome.getHomes().size() >= limit)
+ {
+ throw new Exception(_("maxHomes", ess.getSettings().getHomeLimit(user)));
+ }
+ if (limit == 1)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/Essentials/test/com/earth2me/essentials/UserTest.java b/Essentials/test/com/earth2me/essentials/UserTest.java
index ef9ab515d..5b096431f 100644
--- a/Essentials/test/com/earth2me/essentials/UserTest.java
+++ b/Essentials/test/com/earth2me/essentials/UserTest.java
@@ -51,7 +51,7 @@ public class UserTest extends TestCase
{
User user = ess.getUser(base1);
Location loc = base1.getLocation();
- user.setHome();
+ user.setHome("home", loc);
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
User user2 = ess.getUser(base2);