1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-14 18:44:48 +02:00

Cleanup delhome to match normal home cases properly.

This commit is contained in:
KHobbits
2012-09-22 20:43:27 +01:00
parent 80a96e2a73
commit da01bdc2b0

View File

@@ -28,8 +28,9 @@ public abstract class UserData extends PlayerExtension implements IConf
config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml")); config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml"));
reloadConfig(); reloadConfig();
} }
public final void reset () { public final void reset()
{
config.getFile().delete(); config.getFile().delete();
config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml")); config = new EssentialsConf(new File(folder, Util.sanitizeFileName(base.getName()) + ".yml"));
reloadConfig(); reloadConfig();
@@ -108,26 +109,25 @@ public abstract class UserData extends PlayerExtension implements IConf
return new HashMap<String, Object>(); return new HashMap<String, Object>();
} }
public Location getHome(String name) throws Exception private String getHomeName(String search)
{ {
Location loc = config.getLocation("homes." + name, getServer()); if (Util.isInt(search))
if (loc == null)
{ {
try try
{ {
loc = config.getLocation("homes." + getHomes().get(Integer.parseInt(name) - 1), getServer()); search = getHomes().get(Integer.parseInt(search) - 1);
} }
catch (IndexOutOfBoundsException e) catch (Exception e)
{ {
return null;
}
catch (NumberFormatException e)
{
return null;
} }
} }
return search;
return loc; }
public Location getHome(String name) throws Exception
{
String search = getHomeName(name);
return config.getLocation("homes." + search, getServer());
} }
public Location getHome(final Location world) public Location getHome(final Location world)
@@ -169,20 +169,20 @@ public abstract class UserData extends PlayerExtension implements IConf
public void delHome(String name) throws Exception public void delHome(String name) throws Exception
{ {
String search = name; String search = getHomeName(name);
if (!homes.containsKey(search)) if (!homes.containsKey(search))
{ {
search = Util.sanitizeFileName(name); search = Util.sanitizeFileName(search);
} }
if (homes.containsKey(search)) if (homes.containsKey(search))
{ {
homes.remove(name); homes.remove(search);
config.removeProperty("homes." + name); config.removeProperty("homes." + search);
config.save(); config.save();
} }
else else
{ {
throw new Exception(_("invalidHome", name)); throw new Exception(_("invalidHome", search));
} }
} }