Allow different 'sets' of multiple homes, definable by permission.

- Not sure I like this, but it does seem to work
- changed config key for backwards compatibility (config node sets value on failure).
This commit is contained in:
KHobbits 2011-10-01 10:08:58 +01:00
parent 629dee3a91
commit ea76161ba5
4 changed files with 115 additions and 45 deletions

View File

@ -73,7 +73,11 @@ public interface ISettings extends IConf
boolean getRespawnAtHome();
int getMultipleHomes();
List getMultipleHomes();
int getHomeLimit(String set);
int getHomeLimit(User user);
boolean getSortListByGroups();

View File

@ -30,12 +30,6 @@ 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()
@ -43,6 +37,40 @@ public class Settings implements ISettings
return config.getBoolean("bed-sethome", false);
}
@Override
public List<String> getMultipleHomes()
{
return config.getKeys("sethome-multiple");
}
@Override
public int getHomeLimit(final User user)
{
final List<String> homeList = getMultipleHomes();
if (homeList == null)
{
//TODO: Replace this code to remove backwards compat, after settings are automatically updated
// return getHomeLimit("default");
return config.getInt("multiple-homes", 5);
}
int limit = getHomeLimit("default");
for (String set : homeList)
{
logger.log(Level.INFO, "Found home set: " + set);
if (user.hasPermission("essentials.sethome.multiple." + set) && limit < getHomeLimit(set))
{
limit = getHomeLimit(set);
}
}
return limit;
}
@Override
public int getHomeLimit(final String set)
{
return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3));
}
@Override
public int getChatRadius()
{
@ -60,7 +88,7 @@ public class Settings implements ISettings
{
return config.getInt("default-stack-size", 64);
}
@Override
public int getStartingBalance()
{
@ -84,7 +112,10 @@ public class Settings implements ISettings
{
for (String c : config.getStringList("disabled-commands", new ArrayList<String>(0)))
{
if (!c.equalsIgnoreCase(label)) continue;
if (!c.equalsIgnoreCase(label))
{
continue;
}
return true;
}
return config.getBoolean("disable-" + label.toLowerCase(), false);
@ -101,18 +132,24 @@ public class Settings implements ISettings
{
for (String c : config.getStringList("restricted-commands", new ArrayList<String>(0)))
{
if (!c.equalsIgnoreCase(label)) continue;
if (!c.equalsIgnoreCase(label))
{
continue;
}
return true;
}
return config.getBoolean("restrict-" + label.toLowerCase(), false);
}
@Override
public boolean isPlayerCommand(String label)
{
for (String c : config.getStringList("player-commands", new ArrayList<String>(0)))
{
if (!c.equalsIgnoreCase(label)) continue;
if (!c.equalsIgnoreCase(label))
{
continue;
}
return true;
}
return false;
@ -126,7 +163,9 @@ public class Settings implements ISettings
for (String c : config.getStringList("overridden-commands", defaultList))
{
if (!c.equalsIgnoreCase(name))
{
continue;
}
return true;
}
return config.getBoolean("override-" + name.toLowerCase(), false);
@ -143,7 +182,9 @@ public class Settings implements ISettings
{
double cost = config.getDouble("command-costs." + label, 0.0);
if (cost == 0.0)
{
cost = config.getDouble("cost-" + label, 0.0);
}
return cost;
}
@ -171,13 +212,14 @@ public class Settings implements ISettings
Map<String, Object> kits = (Map<String, Object>)config.getProperty("kits");
for (Map.Entry<String, Object> entry : kits.entrySet())
{
if (entry.getKey().equalsIgnoreCase(name.replace('.', '_').replace('/', '_'))) {
if (entry.getKey().equalsIgnoreCase(name.replace('.', '_').replace('/', '_')))
{
return entry.getValue();
}
}
return null;
}
@Override
public Map<String, Object> getKits()
{
@ -190,9 +232,13 @@ public class Settings implements ISettings
String colorName = config.getString("ops-name-color", null);
if (colorName == null)
{
return ChatColor.RED;
if("none".equalsIgnoreCase(colorName) || colorName.isEmpty())
}
if ("none".equalsIgnoreCase(colorName) || colorName.isEmpty())
{
throw new Exception();
}
try
{
@ -228,18 +274,18 @@ public class Settings implements ISettings
{
return config.getInt("spawnmob-limit", 10);
}
@Override
public boolean showNonEssCommandsInHelp()
{
return config.getBoolean("non-ess-in-help", true);
}
@Override
public boolean hidePermissionlessHelp()
public boolean hidePermissionlessHelp()
{
return config.getBoolean("hide-permissionless-help", true);
}
}
@Override
public int getProtectCreeperMaxHeight()
@ -301,12 +347,13 @@ public class Settings implements ISettings
{
return config.getString("newbies.spawnpoint", "default");
}
@Override
public boolean getPerWarpPermission()
public boolean getPerWarpPermission()
{
return config.getBoolean("per-warp-permission", false);
}
@Override
public boolean getSortListByGroups()
{
@ -314,7 +361,8 @@ public class Settings implements ISettings
}
@Override
public void reloadConfig() {
public void reloadConfig()
{
config.load();
}
@ -322,16 +370,21 @@ public class Settings implements ISettings
public List<Integer> itemSpawnBlacklist()
{
final List<Integer> epItemSpwn = new ArrayList<Integer>();
for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) {
for (String itemName : config.getString("item-spawn-blacklist", "").split(","))
{
itemName = itemName.trim();
if (itemName.isEmpty()) {
if (itemName.isEmpty())
{
continue;
}
ItemStack is;
try {
try
{
is = ess.getItemDb().get(itemName);
epItemSpwn.add(is.getTypeId());
} catch (Exception ex) {
}
catch (Exception ex)
{
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, "item-spawn-blacklist"));
}
}
@ -355,16 +408,17 @@ public class Settings implements ISettings
{
return config.getBoolean("nether.use-1to1-ratio", false);
}
@Override
public double getNetherRatio()
{
if (config.getBoolean("nether.use-1to1-ratio", false)) {
if (config.getBoolean("nether.use-1to1-ratio", false))
{
return 1.0;
}
return config.getDouble("nether.ratio", 8.0);
}
@Override
public boolean isDebug()
{
@ -374,9 +428,9 @@ public class Settings implements ISettings
@Override
public boolean warnOnSmite()
{
return config.getBoolean("warn-on-smite" ,true);
return config.getBoolean("warn-on-smite", true);
}
@Override
public boolean permissionBasedItemSpawn()
{
@ -410,23 +464,28 @@ public class Settings implements ISettings
@Override
public boolean getProtectPreventSpawn(final String creatureName)
{
return config.getBoolean("protect.prevent.spawn."+creatureName, false);
return config.getBoolean("protect.prevent.spawn." + creatureName, false);
}
@Override
public List<Integer> getProtectList(final String configName)
{
final List<Integer> list = new ArrayList<Integer>();
for (String itemName : config.getString(configName, "").split(",")) {
for (String itemName : config.getString(configName, "").split(","))
{
itemName = itemName.trim();
if (itemName.isEmpty()) {
if (itemName.isEmpty())
{
continue;
}
ItemStack itemStack;
try {
try
{
itemStack = ess.getItemDb().get(itemName);
list.add(itemStack.getTypeId());
} catch (Exception ex) {
}
catch (Exception ex)
{
logger.log(Level.SEVERE, Util.format("unknownItemInList", itemName, configName));
}
}
@ -444,12 +503,13 @@ public class Settings implements ISettings
{
return config.getBoolean(configName, def);
}
private final static double MAXMONEY = 10000000000000.0;
public double getMaxMoney()
{
double max = config.getDouble("max-money", MAXMONEY);
if (Math.abs(max) > MAXMONEY) {
if (Math.abs(max) > MAXMONEY)
{
max = max < 0 ? -MAXMONEY : MAXMONEY;
}
return max;
@ -459,7 +519,7 @@ public class Settings implements ISettings
{
return config.getBoolean("economy-log-enabled", false);
}
public boolean removeGodOnDisconnect()
{
return config.getBoolean("remove-god-on-disconnect", false);

View File

@ -28,14 +28,14 @@ public class Commandsethome extends EssentialsCommand
{
if (user.isAuthorized("essentials.sethome.multiple"))
{
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getMultipleHomes())
if ((user.isAuthorized("essentials.sethome.multiple.unlimited")) || (user.getHomes().size() < ess.getSettings().getHomeLimit(user))
|| (user.getHomes().contains(args[0].toLowerCase())))
{
user.setHome(args[0].toLowerCase());
}
else
{
throw new Exception(Util.format("maxHomes", ess.getSettings().getMultipleHomes()));
throw new Exception(Util.format("maxHomes", ess.getSettings().getHomeLimit(user)));
}
}

View File

@ -260,10 +260,16 @@ 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
# Allow players to have multiple homes.
# Define different amounts of multiple homes for different permissions, e.g. essentials.sethome.multiple.vip
# People with essentials.sethome.multiple.unlimited are not limited by these numbers.
sethome-multiple:
# essentials.sethome.multiple
default: 3
# essentials.sethome.multiple.vip
vip: 5
# essentials.sethome.multiple.staff
staff: 10
############################################################
# +------------------------------------------------------+ #