From a60f280a1c286d6c553fac3e2e4aaf82dd21fd34 Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 5 Feb 2012 17:35:47 +0100 Subject: [PATCH] Fixing the Testcases --- .../src/com/earth2me/essentials/Teleport.java | 4 ++-- .../essentials/commands/Commandsethome.java | 12 ++++++------ .../com/earth2me/essentials/user/User.java | 2 +- .../earth2me/essentials/user/UserBase.java | 19 +++++++++++++------ .../earth2me/essentials/user/UserData.java | 6 +----- .../com/earth2me/essentials/StorageTest.java | 2 +- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 78844d7b1..971b11ba5 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -269,7 +269,7 @@ public class Teleport implements Runnable, ITeleport user.acquireReadLock(); try { - teleport(new Target(user.getData().getLastLocation()), chargeFor, TeleportCause.COMMAND); + teleport(new Target(user.getData().getLastLocation().getBukkitLocation()), chargeFor, TeleportCause.COMMAND); } finally { @@ -282,7 +282,7 @@ public class Teleport implements Runnable, ITeleport user.acquireReadLock(); try { - now(new Target(user.getData().getLastLocation()), TeleportCause.COMMAND); + now(new Target(user.getData().getLastLocation().getBukkitLocation()), TeleportCause.COMMAND); } finally { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index f2cf9d762..18693dd99 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -36,9 +36,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap()); + user.getData().setHomes(new HashMap()); } - user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), user.getLocation()); + user.getData().getHomes().put(args[0].toLowerCase(Locale.ENGLISH), new com.earth2me.essentials.storage.Location(user.getLocation())); } else { @@ -73,9 +73,9 @@ public class Commandsethome extends EssentialsCommand usersHome.acquireWriteLock(); if (usersHome.getData().getHomes() == null) { - usersHome.getData().setHomes(new HashMap()); + usersHome.getData().setHomes(new HashMap()); } - usersHome.getData().getHomes().put(name, user.getLocation()); + usersHome.getData().getHomes().put(name, new com.earth2me.essentials.storage.Location(user.getLocation())); } } } @@ -84,9 +84,9 @@ public class Commandsethome extends EssentialsCommand user.acquireWriteLock(); if (user.getData().getHomes() == null) { - user.getData().setHomes(new HashMap()); + user.getData().setHomes(new HashMap()); } - user.getData().getHomes().put("home", user.getLocation()); + user.getData().getHomes().put("home", new com.earth2me.essentials.storage.Location(user.getLocation())); } user.sendMessage(_("homeSet")); diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java index 1f64b0b05..ecd71f34d 100644 --- a/Essentials/src/com/earth2me/essentials/user/User.java +++ b/Essentials/src/com/earth2me/essentials/user/User.java @@ -190,7 +190,7 @@ public class User extends UserBase implements IUser acquireWriteLock(); try { - getData().setLastLocation(getLocation()); + getData().setLastLocation(new com.earth2me.essentials.storage.Location(getLocation())); } finally { diff --git a/Essentials/src/com/earth2me/essentials/user/UserBase.java b/Essentials/src/com/earth2me/essentials/user/UserBase.java index f913796c2..ac2197b33 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserBase.java +++ b/Essentials/src/com/earth2me/essentials/user/UserBase.java @@ -243,13 +243,13 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem acquireWriteLock(); try { - Map homes = getData().getHomes(); + Map homes = getData().getHomes(); if (homes == null) { - homes = new HashMap(); + homes = new HashMap(); getData().setHomes(homes); } - homes.put(Util.sanitizeKey(name), loc); + homes.put(Util.sanitizeKey(name), new com.earth2me.essentials.storage.Location(loc)); } finally { @@ -417,10 +417,17 @@ public abstract class UserBase extends AsyncStorageObjectHolder implem return null; } ArrayList worldHomes = new ArrayList(); - for (Location location : getData().getHomes().values()) + for (com.earth2me.essentials.storage.Location location : getData().getHomes().values()) { - if (location.getWorld().equals(loc.getWorld())) { - worldHomes.add(location); + if (location.getWorldName().equals(loc.getWorld().getName())) { + try + { + worldHomes.add(location.getBukkitLocation()); + } + catch (WorldNotLoadedException ex) + { + continue; + } } } if (worldHomes.isEmpty()) { diff --git a/Essentials/src/com/earth2me/essentials/user/UserData.java b/Essentials/src/com/earth2me/essentials/user/UserData.java index 7a11f5f9d..d61d21a49 100644 --- a/Essentials/src/com/earth2me/essentials/user/UserData.java +++ b/Essentials/src/com/earth2me/essentials/user/UserData.java @@ -1,13 +1,9 @@ package com.earth2me.essentials.user; -import com.earth2me.essentials.storage.ListType; -import com.earth2me.essentials.storage.MapKeyType; -import com.earth2me.essentials.storage.MapValueType; -import com.earth2me.essentials.storage.StorageObject; +import com.earth2me.essentials.storage.*; import java.util.*; import lombok.Data; import lombok.EqualsAndHashCode; -import org.bukkit.Location; import org.bukkit.Material; diff --git a/Essentials/test/com/earth2me/essentials/StorageTest.java b/Essentials/test/com/earth2me/essentials/StorageTest.java index a04c6b34f..21dc51b55 100644 --- a/Essentials/test/com/earth2me/essentials/StorageTest.java +++ b/Essentials/test/com/earth2me/essentials/StorageTest.java @@ -98,7 +98,7 @@ public class StorageTest extends TestCase for (int j = 0; j < 10000; j++) { - userdata.getHomes().put("home", new Location(world, j, j, j)); + userdata.getHomes().put("home", new com.earth2me.essentials.storage.Location(new Location(world, j, j, j))); } ext.mark("change home 10000 times"); final ByteArrayOutputStream baos = new ByteArrayOutputStream();