diff options
author | KHobbits <rob@khobbits.co.uk> | 2011-08-23 03:42:32 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2011-08-23 03:42:32 +0100 |
commit | 0592c1fe11de349800c34a566d70f7b1c88956fb (patch) | |
tree | 5b17fbb79940396b6769c68a2452e6cb0b6b3b91 | |
parent | 1138e322926d3ae6cb6afdd47ce6de75f5b0099e (diff) | |
download | Essentials-0592c1fe11de349800c34a566d70f7b1c88956fb.tar Essentials-0592c1fe11de349800c34a566d70f7b1c88956fb.tar.gz Essentials-0592c1fe11de349800c34a566d70f7b1c88956fb.tar.lz Essentials-0592c1fe11de349800c34a566d70f7b1c88956fb.tar.xz Essentials-0592c1fe11de349800c34a566d70f7b1c88956fb.zip |
Added multiple homes.
Permissions currently: essentials.sethome.multiple and essentials.sethome.multiple.unlimited
New config setting: multiple-homes (default value 5)
10 files changed, 196 insertions, 106 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 2ebc73c75..25bf6291d 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -287,12 +287,12 @@ public class EssentialsUpgrade } if (world != null) { - user.setHome(new Location(world, + user.setHome("home", new Location(world, ((Number)vals.get(0)).doubleValue(), ((Number)vals.get(1)).doubleValue(), ((Number)vals.get(2)).doubleValue(), ((Number)vals.get(3)).floatValue(), - ((Number)vals.get(4)).floatValue()), true); + ((Number)vals.get(4)).floatValue())); } } } @@ -513,5 +513,6 @@ public class EssentialsUpgrade moveUsersDataToUserdataFolder(); convertWarps(); updateUsersPowerToolsFormat(); + //TODO: Convert 2.5.7 homes to new format } } diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 13717f469..cf8301d2a 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -72,6 +72,8 @@ public interface ISettings extends IConf boolean getReclaimSetting(); boolean getRespawnAtHome(); + + int getMultipleHomes(); boolean getSortListByGroups(); diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 5b2e7075e..0f470a7ab 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -45,7 +45,9 @@ public interface IUser void setLastLocation(); - Location getHome(Location location); + Location getHome(String name); + + Location getHome(Location loc); String getName(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 1700dec3a..03b810c90 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -30,6 +30,12 @@ public class Settings implements ISettings { return config.getBoolean("respawn-at-home", false); } + + @Override + public int getMultipleHomes() + { + return config.getInt("multiple-homes", 5); + } @Override public boolean getBedSetsHome() diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 9fb9b7433..badc0e267 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -10,6 +10,8 @@ import org.bukkit.entity.Entity; public class Teleport implements Runnable { private static final double MOVE_CONSTANT = 0.3; + + private static class Target { private final Location location; @@ -57,9 +59,9 @@ public class Teleport implements Runnable this.started = System.currentTimeMillis(); this.delay = delay; this.health = user.getHealth(); - this.initX = Math.round(user.getLocation().getX()*MOVE_CONSTANT); - this.initY = Math.round(user.getLocation().getY()*MOVE_CONSTANT); - this.initZ = Math.round(user.getLocation().getZ()*MOVE_CONSTANT); + this.initX = Math.round(user.getLocation().getX() * MOVE_CONSTANT); + this.initY = Math.round(user.getLocation().getY() * MOVE_CONSTANT); + this.initZ = Math.round(user.getLocation().getZ() * MOVE_CONSTANT); this.teleportTarget = target; this.chargeFor = chargeFor; } @@ -72,9 +74,9 @@ public class Teleport implements Runnable cancel(); return; } - if (Math.round(user.getLocation().getX()*MOVE_CONSTANT) != initX - || Math.round(user.getLocation().getY()*MOVE_CONSTANT) != initY - || Math.round(user.getLocation().getZ()*MOVE_CONSTANT) != initZ + if (Math.round(user.getLocation().getX() * MOVE_CONSTANT) != initX + || Math.round(user.getLocation().getY() * MOVE_CONSTANT) != initY + || Math.round(user.getLocation().getZ() * MOVE_CONSTANT) != initZ || user.getHealth() < health) { // user moved, cancel teleport cancel(true); @@ -92,7 +94,7 @@ public class Teleport implements Runnable user.sendMessage(Util.i18n("teleportationCommencing")); try { - + now(teleportTarget); if (chargeFor != null) { @@ -229,7 +231,7 @@ public class Teleport implements Runnable cooldown(false); now(new Target(loc)); } - + public void now(Location loc, Trade chargeFor) throws Exception { cooldown(false); @@ -261,9 +263,19 @@ public class Teleport implements Runnable home(user, chargeFor); } + public void home(String home, Trade chargeFor) throws Exception + { + home(user, home, chargeFor); + } + public void home(IUser user, Trade chargeFor) throws Exception { - Location loc = user.getHome(this.user.getLocation()); + home(user, "0", chargeFor); + } + + public void home(IUser user, String home, Trade chargeFor) throws Exception + { + final Location loc = user.getHome(home); if (loc == null) { if (ess.getSettings().spawnIfNoHome()) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 6c18c03ae..f8f7d7afa 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -6,6 +6,7 @@ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.logging.Logger; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -20,44 +21,44 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser private final Teleport teleport; private long lastActivity; private boolean hidden = false; - + User(Player base, IEssentials ess) { super(base, ess); teleport = new Teleport(this, ess); } - + User update(Player base) { setBase(base); return this; } - + public boolean isAuthorized(IEssentialsCommand cmd) { return isAuthorized(cmd, "essentials."); } - + public boolean isAuthorized(IEssentialsCommand cmd, String permissionPrefix) { return isAuthorized(permissionPrefix + (cmd.getName().equals("r") ? "msg" : cmd.getName())); } - + public boolean isAuthorized(String node) { if (isOp()) { return true; } - + if (isJailed()) { return false; } - + return ess.getPermissionsHandler().hasPermission(this, node); } - + public void healCooldown() throws Exception { Calendar now = new GregorianCalendar(); @@ -75,12 +76,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser } setLastHealTimestamp(now.getTimeInMillis()); } - + public void giveMoney(double value) { giveMoney(value, null); } - + public void giveMoney(double value, CommandSender initiator) { if (value == 0) @@ -94,7 +95,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser initiator.sendMessage((Util.format("addedToOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()))); } } - + public void payUser(User reciever, double value) throws Exception { if (value == 0) @@ -113,12 +114,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser reciever.sendMessage(Util.format("moneyRecievedFrom", Util.formatCurrency(value, ess), getDisplayName())); } } - + public void takeMoney(double value) { takeMoney(value, null); } - + public void takeMoney(double value, CommandSender initiator) { if (value == 0) @@ -132,43 +133,43 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser initiator.sendMessage((Util.format("takenFromOthersAccount", Util.formatCurrency(value, ess), this.getDisplayName()))); } } - + public boolean canAfford(double cost) { double mon = getMoney(); return mon >= cost || isAuthorized("essentials.eco.loan"); } - + public void dispose() { this.base = new OfflinePlayer(getName(), ess); } - + public boolean getJustPortaled() { return justPortaled; } - + public void setJustPortaled(boolean value) { justPortaled = value; } - + public void setReplyTo(CommandSender user) { replyTo = user; } - + public CommandSender getReplyTo() { return replyTo; } - + public int compareTo(User t) { return ChatColor.stripColor(this.getDisplayName()).compareToIgnoreCase(ChatColor.stripColor(t.getDisplayName())); } - + @Override public boolean equals(Object o) { @@ -177,51 +178,56 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser return false; } return ChatColor.stripColor(this.getDisplayName()).equalsIgnoreCase(ChatColor.stripColor(((User)o).getDisplayName())); - + } - + @Override public int hashCode() { return ChatColor.stripColor(this.getDisplayName()).hashCode(); } - + public Boolean canSpawnItem(int itemId) { return !ess.getSettings().itemSpawnBlacklist().contains(itemId); } - + + public Location getHome() + { + return getHome(getHomes().get(0)); + } + public void setHome() { - setHome(getLocation(), true); + setHome("home", getLocation()); } - - public void setHome(boolean defaultHome) + + public void setHome(String name) { - setHome(getLocation(), defaultHome); + setHome(name, getLocation()); } - + public void setLastLocation() { setLastLocation(getLocation()); } - + public void requestTeleport(User player, boolean here) { teleportRequester = player; teleportRequestHere = here; } - + public User getTeleportRequest() { return teleportRequester; } - + public boolean isTeleportRequestHere() { return teleportRequestHere; } - + public String getNick() { final StringBuilder nickname = new StringBuilder(); @@ -245,12 +251,12 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser { } } - + if (ess.getSettings().addPrefixSuffix()) { final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); - + nickname.insert(0, prefix); nickname.append(suffix); if (suffix.length() < 2 || !suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§")) @@ -258,25 +264,25 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser nickname.append("§f"); } } - + return nickname.toString(); } - + public Teleport getTeleport() { return teleport; } - + public long getLastActivity() { return lastActivity; } - + public void setLastActivity(long timestamp) { lastActivity = timestamp; } - + @Override public double getMoney() { @@ -298,7 +304,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser } return super.getMoney(); } - + @Override public void setMoney(double value) { @@ -320,14 +326,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser } super.setMoney(value); } - + @Override public void setAfk(boolean set) { this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : set); super.setAfk(set); } - + @Override public boolean toggleAfk() { @@ -335,17 +341,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser this.setSleepingIgnored(this.isAuthorized("essentials.sleepingignored") ? true : now); return now; } - + public boolean isHidden() { return hidden; } - + public void setHidden(boolean hidden) { this.hidden = hidden; } - + public void checkJailTimeout(final long currentTime) { if (getJailTimeout() > 0 && getJailTimeout() < currentTime && isJailed()) @@ -363,7 +369,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser } } } - + public void checkMuteTimeout(final long currentTime) { if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted()) @@ -373,7 +379,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser setMuted(false); } } - + public void checkBanTimeout(final long currentTime) { if (getBanTimeout() > 0 && getBanTimeout() < currentTime && ess.getBans().isNameBanned(getName())) diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index b72f105ee..1467f496d 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -5,11 +5,9 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -36,7 +34,8 @@ public abstract class UserData extends PlayerExtension implements IConf config.load(); money = _getMoney(); unlimited = _getUnlimited(); - powertools = getPowertools(); + powertools = _getPowertools(); + homes = _getHomes(); lastLocation = _getLastLocation(); lastTeleportTimestamp = _getLastTeleportTimestamp(); lastHealTimestamp = _getLastHealTimestamp(); @@ -89,50 +88,73 @@ public abstract class UserData extends PlayerExtension implements IConf config.setProperty("money", value); config.save(); } + private Map<String, Object> homes; - public boolean hasHome() + private Map<String, Object> _getHomes() { - if (config.hasProperty("home")) + Object o = config.getProperty("homes"); + + if (o instanceof Map) { - return true; + return (Map<String, Object>)o; } - return false; + else + { + return new HashMap<String, Object>(); + } + } - public Location getHome(Location location) + public Location getHome(String name) { - if (!hasHome()) + Location loc = (Location)homes.get(name); + if (loc == null) { - return null; + loc = (Location)homes.get(getHomes().get(Integer.parseInt(name) - 1)); } - World world = location.getWorld(); - String worldHome = "home.worlds." + world.getName().toLowerCase(); - if (!config.hasProperty(worldHome)) - { - String defaultWorld = config.getString("home.default"); - worldHome = "home.worlds." + defaultWorld; - } - Location loc = config.getLocation(worldHome, getServer()); + return loc; } - public void setHome(Location loc, boolean b) + public Location getHome(Location world) { - String worldName = loc.getWorld().getName().toLowerCase(); - if (worldName == null || worldName.isEmpty()) + Location loc; + for (String home : getHomes()) { - logger.log(Level.WARNING, Util.i18n("emptyWorldName")); - return; - } - if (b || !config.hasProperty("home.default")) - { - config.setProperty("home.default", worldName); + loc = (Location)homes.get(home); + if (world.getWorld() == loc.getWorld()) + { + return loc; + } + } + loc = (Location)homes.get(getHomes().get(0)); + return loc; + } + + public List<String> getHomes() + { + List<String> list = new ArrayList(homes.keySet()); + return list; - config.setProperty("home.worlds." + worldName, loc); + } + + public void setHome(String name, Location loc) + { + homes.put(name, loc); + config.setProperty("homes." + name, loc); config.save(); } + public boolean hasHome() + { + if (config.hasProperty("home")) + { + return true; + } + return false; + } + public String getNickname() { return config.getString("nickname"); @@ -176,10 +198,10 @@ public abstract class UserData extends PlayerExtension implements IConf private Map<Integer, Object> powertools; @SuppressWarnings("unchecked") - private Map<Integer, Object> getPowertools() + private Map<Integer, Object> _getPowertools() { Object o = config.getProperty("powertools"); - + if (o instanceof Map) { return (Map<Integer, Object>)o; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 2649a9cb0..cb7ba57ae 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.Trade; import org.bukkit.Server; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; +import java.util.List; public class Commandhome extends EssentialsCommand @@ -18,24 +19,51 @@ public class Commandhome extends EssentialsCommand { Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); - if(args.length > 0 && user.isAuthorized("essentials.home.others")) + if (args.length == 0) { - User u; - try + List<String> homes = user.getHomes(); + if (homes.isEmpty()) + { + throw new Exception(Util.i18n("noHomeSet")); + } + else if (homes.size() == 1) + { + user.getTeleport().home(homes.get(0), charge); + } + else { - u = getPlayer(server, args, 0); + //TODO: move to messages file + user.sendMessage("Homes: " + homes.toString()); } - catch(NoSuchFieldException ex) + + } + else + { + User u; + String homeName; + String[] nameParts = args[0].split(":"); + if (nameParts.length == 1) { - u = ess.getOfflineUser(args[0]); + u = user; + homeName = nameParts[0]; } - if (u == null) + else { - throw new Exception(Util.i18n("playerNotFound")); + try + { + u = getPlayer(server, args, 0); + } + catch (NoSuchFieldException ex) + { + u = ess.getOfflineUser(args[0]); + } + if (u == null) + { + throw new Exception(Util.i18n("playerNotFound")); + } + homeName = nameParts[1]; } - user.getTeleport().home(u, charge); - return; + user.getTeleport().home(u, homeName, charge); } - user.getTeleport().home(charge); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index 154017d43..bb0d136c5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -19,14 +19,21 @@ public class Commandsethome extends EssentialsCommand { if (args.length < 2) { - user.setHome(args[0].equalsIgnoreCase("default")); + if (user.isAuthorized("essentials.sethome.multiple")) + { + if (user.isAuthorized("essentials.sethome.multiple.unlimited") || user.getHomes().size() <= ess.getSettings().getMultipleHomes()) + { + user.setHome(args[0]); + } + + } } else { if (user.isAuthorized("essentials.sethome.others")) { User usersHome = ess.getUser(ess.getServer().getPlayer(args[0])); - if(usersHome == null) + if (usersHome == null) { usersHome = ess.getOfflineUser(args[0]); } @@ -34,13 +41,13 @@ public class Commandsethome extends EssentialsCommand { throw new Exception(Util.i18n("playerNotFound")); } - usersHome.setHome(user.getLocation(), args[1].equalsIgnoreCase("default")); + usersHome.setHome(args[1], user.getLocation()); } } } else { - user.setHome(false); + user.setHome(); } charge(user); user.sendMessage(Util.i18n("homeSet")); diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 5e3f581b8..885d16047 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -246,6 +246,10 @@ bed-sethome: false #if no home is set send you to spawn when /home is used spawn-if-no-home: false +# If users have essentials.sethome.multiple how many homes can they have +# People with essentials.sethome.multiple.unlimited are not limited by this number +multiple-homes: 5 + ############################################################ # +------------------------------------------------------+ # |