mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-15 12:41:24 +01:00
Added multiple homes.
Permissions currently: essentials.sethome.multiple and essentials.sethome.multiple.unlimited New config setting: multiple-homes (default value 5)
This commit is contained in:
parent
1138e32292
commit
0592c1fe11
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ public interface ISettings extends IConf
|
||||
|
||||
boolean getRespawnAtHome();
|
||||
|
||||
int getMultipleHomes();
|
||||
|
||||
boolean getSortListByGroups();
|
||||
|
||||
int getSpawnMobLimit();
|
||||
|
@ -45,7 +45,9 @@ public interface IUser
|
||||
|
||||
void setLastLocation();
|
||||
|
||||
Location getHome(Location location);
|
||||
Location getHome(String name);
|
||||
|
||||
Location getHome(Location loc);
|
||||
|
||||
String getName();
|
||||
|
||||
|
@ -31,6 +31,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()
|
||||
{
|
||||
|
@ -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;
|
||||
@ -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())
|
||||
|
@ -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;
|
||||
|
||||
@ -191,14 +192,19 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
return !ess.getSettings().itemSpawnBlacklist().contains(itemId);
|
||||
}
|
||||
|
||||
public void setHome()
|
||||
public Location getHome()
|
||||
{
|
||||
setHome(getLocation(), true);
|
||||
return getHome(getHomes().get(0));
|
||||
}
|
||||
|
||||
public void setHome(boolean defaultHome)
|
||||
public void setHome()
|
||||
{
|
||||
setHome(getLocation(), defaultHome);
|
||||
setHome("home", getLocation());
|
||||
}
|
||||
|
||||
public void setHome(String name)
|
||||
{
|
||||
setHome(name, getLocation());
|
||||
}
|
||||
|
||||
public void setLastLocation()
|
||||
|
@ -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,6 +88,63 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
config.setProperty("money", value);
|
||||
config.save();
|
||||
}
|
||||
private Map<String, Object> homes;
|
||||
|
||||
private Map<String, Object> _getHomes()
|
||||
{
|
||||
Object o = config.getProperty("homes");
|
||||
|
||||
if (o instanceof Map)
|
||||
{
|
||||
return (Map<String, Object>)o;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Location getHome(String name)
|
||||
{
|
||||
Location loc = (Location)homes.get(name);
|
||||
if (loc == null)
|
||||
{
|
||||
loc = (Location)homes.get(getHomes().get(Integer.parseInt(name) - 1));
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Location getHome(Location world)
|
||||
{
|
||||
Location loc;
|
||||
for (String home : getHomes())
|
||||
{
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
public void setHome(String name, Location loc)
|
||||
{
|
||||
homes.put(name, loc);
|
||||
config.setProperty("homes." + name, loc);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public boolean hasHome()
|
||||
{
|
||||
@ -99,40 +155,6 @@ public abstract class UserData extends PlayerExtension implements IConf
|
||||
return false;
|
||||
}
|
||||
|
||||
public Location getHome(Location location)
|
||||
{
|
||||
if (!hasHome())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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)
|
||||
{
|
||||
String worldName = loc.getWorld().getName().toLowerCase();
|
||||
if (worldName == null || worldName.isEmpty())
|
||||
{
|
||||
logger.log(Level.WARNING, Util.i18n("emptyWorldName"));
|
||||
return;
|
||||
}
|
||||
if (b || !config.hasProperty("home.default"))
|
||||
{
|
||||
config.setProperty("home.default", worldName);
|
||||
}
|
||||
|
||||
config.setProperty("home.worlds." + worldName, loc);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public String getNickname()
|
||||
{
|
||||
return config.getString("nickname");
|
||||
@ -176,7 +198,7 @@ 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");
|
||||
|
||||
|
@ -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,9 +19,36 @@ 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)
|
||||
{
|
||||
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
|
||||
{
|
||||
//TODO: move to messages file
|
||||
user.sendMessage("Homes: " + homes.toString());
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
User u;
|
||||
String homeName;
|
||||
String[] nameParts = args[0].split(":");
|
||||
if (nameParts.length == 1)
|
||||
{
|
||||
u = user;
|
||||
homeName = nameParts[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
u = getPlayer(server, args, 0);
|
||||
@ -33,9 +61,9 @@ public class Commandhome extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(Util.i18n("playerNotFound"));
|
||||
}
|
||||
user.getTeleport().home(u, charge);
|
||||
return;
|
||||
homeName = nameParts[1];
|
||||
}
|
||||
user.getTeleport().home(u, homeName, charge);
|
||||
}
|
||||
user.getTeleport().home(charge);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,14 @@ 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
|
||||
{
|
||||
@ -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"));
|
||||
|
@ -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
|
||||
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
|
Loading…
Reference in New Issue
Block a user