From ef81a1c2f01a902bba6e78a9a0fdd4eee9d631b2 Mon Sep 17 00:00:00 2001 From: TreemanK Date: Fri, 21 Jun 2024 02:23:38 +1000 Subject: [PATCH] style: change method name to getWarpLocation note `line 294` of `warp.java`, I am unsure what this does and whether it should be `getWarpLocation` or not. I will leave it for the time being. --- src/main/java/world/bentobox/warps/Warp.java | 2 +- .../bentobox/warps/listeners/WarpSignsListener.java | 2 +- .../bentobox/warps/managers/WarpSignsManager.java | 11 ++++++++--- .../java/world/bentobox/warps/objects/WarpsData.java | 1 + .../world/bentobox/warps/WarpSignsManagerTest.java | 8 ++++---- .../warps/listeners/WarpSignsListenerTest.java | 4 ++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/warps/Warp.java b/src/main/java/world/bentobox/warps/Warp.java index 1cbdd71..63a6ed1 100644 --- a/src/main/java/world/bentobox/warps/Warp.java +++ b/src/main/java/world/bentobox/warps/Warp.java @@ -288,7 +288,7 @@ public class Warp extends Addon { } return switch (requestLabel) { case "getSortedWarps" -> getWarpSignsManager().getSortedWarps(world); - case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarp(world, uuid); + case "getWarp" -> uuid == null ? null : getWarpSignsManager().getWarpLocation(world, uuid); case "getWarpMap" -> getWarpSignsManager().getWarpMap(world); case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid); case "listWarps" -> getWarpSignsManager().listWarps(world); diff --git a/src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java b/src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java index b881551..2c4cb5b 100644 --- a/src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java +++ b/src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java @@ -171,7 +171,7 @@ public class WarpSignsListener implements Listener { } // Check if the player already has a sign - final Location oldSignLoc = addon.getWarpSignsManager().getWarp(b.getWorld(), user.getUniqueId()); + final Location oldSignLoc = addon.getWarpSignsManager().getWarpLocation(b.getWorld(), user.getUniqueId()); if (oldSignLoc != null) { // A sign already exists. Check if it still there and if // so, diff --git a/src/main/java/world/bentobox/warps/managers/WarpSignsManager.java b/src/main/java/world/bentobox/warps/managers/WarpSignsManager.java index efc96ed..3ae6565 100644 --- a/src/main/java/world/bentobox/warps/managers/WarpSignsManager.java +++ b/src/main/java/world/bentobox/warps/managers/WarpSignsManager.java @@ -122,11 +122,16 @@ public class WarpSignsManager { * @return Location of warp or null */ @Nullable - public Location getWarp(World world, UUID playerUUID) { + public Location getWarpLocation(World world, UUID playerUUID) { PlayerWarp playerWarp = getWarpMap(world).get(playerUUID); return playerWarp != null ? playerWarp.getLocation() : null; } + @Nullable + public PlayerWarp getPlayerWarp(World world, UUID playerUUID) { + return getWarpMap(world).get(playerUUID); + } + /** * Get the name of the warp owner by location * @param location to search @@ -304,7 +309,7 @@ public class WarpSignsManager { @NonNull public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) { //get the sign info - Location signLocation = getWarp(world, uuid); + Location signLocation = getWarpLocation(world, uuid); if (signLocation == null || !signLocation.getBlock().getType().name().contains("SIGN")) { return new SignCacheItem(); } @@ -398,7 +403,7 @@ public class WarpSignsManager { * @param owner - owner of the warp */ public void warpPlayer(@NonNull World world, @NonNull User user, @NonNull UUID owner) { - final Location warpSpot = getWarp(world, owner); + final Location warpSpot = getWarpLocation(world, owner); // Check if the warp spot is safe if (warpSpot == null) { user.sendMessage("warps.error.does-not-exist"); diff --git a/src/main/java/world/bentobox/warps/objects/WarpsData.java b/src/main/java/world/bentobox/warps/objects/WarpsData.java index 7743df6..dfbdd4d 100644 --- a/src/main/java/world/bentobox/warps/objects/WarpsData.java +++ b/src/main/java/world/bentobox/warps/objects/WarpsData.java @@ -57,6 +57,7 @@ public class WarpsData implements DataObject { PlayerWarp playerWarp = new PlayerWarp(entry.getKey(), true); newWarpSigns.put(playerWarp, entry.getValue()); } + warpSigns.clear(); } public void setWarpSigns(Map warpSigns) { diff --git a/src/test/java/world/bentobox/warps/WarpSignsManagerTest.java b/src/test/java/world/bentobox/warps/WarpSignsManagerTest.java index c82741a..a6e3eb2 100644 --- a/src/test/java/world/bentobox/warps/WarpSignsManagerTest.java +++ b/src/test/java/world/bentobox/warps/WarpSignsManagerTest.java @@ -359,19 +359,19 @@ public class WarpSignsManagerTest { } /** - * Test method for {@link WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}. + * Test method for {@link WarpSignsManager#getWarpLocation(org.bukkit.World, java.util.UUID)}. */ @Test public void testGetWarpWorldWorld() { - assertNull(wsm.getWarp(mock(World.class), uuid)); + assertNull(wsm.getWarpLocation(mock(World.class), uuid)); } /** - * Test method for {@link WarpSignsManager#getWarp(org.bukkit.World, java.util.UUID)}. + * Test method for {@link WarpSignsManager#getWarpLocation(org.bukkit.World, java.util.UUID)}. */ @Test public void testGetWarp() { - assertEquals(location, wsm.getWarp(world, uuid)); + assertEquals(location, wsm.getWarpLocation(world, uuid)); } /** diff --git a/src/test/java/world/bentobox/warps/listeners/WarpSignsListenerTest.java b/src/test/java/world/bentobox/warps/listeners/WarpSignsListenerTest.java index d90c3e0..66c15b2 100644 --- a/src/test/java/world/bentobox/warps/listeners/WarpSignsListenerTest.java +++ b/src/test/java/world/bentobox/warps/listeners/WarpSignsListenerTest.java @@ -133,7 +133,7 @@ public class WarpSignsListenerTest { // Player is in world when(wsm.getWarpMap(world)).thenReturn(list); //Player has a warp sign already here - when(wsm.getWarp(any(), any())).thenReturn(location); + when(wsm.getWarpLocation(any(), any())).thenReturn(location); // Unique spot when(wsm.addWarp(any(), any())).thenReturn(true); // Bentobox @@ -421,7 +421,7 @@ public class WarpSignsListenerTest { @Test public void testCreateNoSignAlreadyUniqueSpot() { - when(wsm.getWarp(any(), any())).thenReturn(null); + when(wsm.getWarpLocation(any(), any())).thenReturn(null); when(player.hasPermission(anyString())).thenReturn(true); WarpSignsListener wsl = new WarpSignsListener(addon); SignChangeEvent e = new SignChangeEvent(block, player, lines);