1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-22 02:25:31 +01:00

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.
This commit is contained in:
TreemanK 2024-06-21 02:23:38 +10:00
parent 64f8a4899a
commit ef81a1c2f0
6 changed files with 17 additions and 11 deletions

View File

@ -288,7 +288,7 @@ public class Warp extends Addon {
} }
return switch (requestLabel) { return switch (requestLabel) {
case "getSortedWarps" -> getWarpSignsManager().getSortedWarps(world); 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 "getWarpMap" -> getWarpSignsManager().getWarpMap(world);
case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid); case "hasWarp" -> uuid == null ? null : getWarpSignsManager().hasWarp(world, uuid);
case "listWarps" -> getWarpSignsManager().listWarps(world); case "listWarps" -> getWarpSignsManager().listWarps(world);

View File

@ -171,7 +171,7 @@ public class WarpSignsListener implements Listener {
} }
// Check if the player already has a sign // 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) { if (oldSignLoc != null) {
// A sign already exists. Check if it still there and if // A sign already exists. Check if it still there and if
// so, // so,

View File

@ -122,11 +122,16 @@ public class WarpSignsManager {
* @return Location of warp or null * @return Location of warp or null
*/ */
@Nullable @Nullable
public Location getWarp(World world, UUID playerUUID) { public Location getWarpLocation(World world, UUID playerUUID) {
PlayerWarp playerWarp = getWarpMap(world).get(playerUUID); PlayerWarp playerWarp = getWarpMap(world).get(playerUUID);
return playerWarp != null ? playerWarp.getLocation() : null; 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 * Get the name of the warp owner by location
* @param location to search * @param location to search
@ -304,7 +309,7 @@ public class WarpSignsManager {
@NonNull @NonNull
public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) { public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) {
//get the sign info //get the sign info
Location signLocation = getWarp(world, uuid); Location signLocation = getWarpLocation(world, uuid);
if (signLocation == null || !signLocation.getBlock().getType().name().contains("SIGN")) { if (signLocation == null || !signLocation.getBlock().getType().name().contains("SIGN")) {
return new SignCacheItem(); return new SignCacheItem();
} }
@ -398,7 +403,7 @@ public class WarpSignsManager {
* @param owner - owner of the warp * @param owner - owner of the warp
*/ */
public void warpPlayer(@NonNull World world, @NonNull User user, @NonNull UUID owner) { 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 // Check if the warp spot is safe
if (warpSpot == null) { if (warpSpot == null) {
user.sendMessage("warps.error.does-not-exist"); user.sendMessage("warps.error.does-not-exist");

View File

@ -57,6 +57,7 @@ public class WarpsData implements DataObject {
PlayerWarp playerWarp = new PlayerWarp(entry.getKey(), true); PlayerWarp playerWarp = new PlayerWarp(entry.getKey(), true);
newWarpSigns.put(playerWarp, entry.getValue()); newWarpSigns.put(playerWarp, entry.getValue());
} }
warpSigns.clear();
} }
public void setWarpSigns(Map<PlayerWarp, UUID> warpSigns) { public void setWarpSigns(Map<PlayerWarp, UUID> warpSigns) {

View File

@ -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 @Test
public void testGetWarpWorldWorld() { 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 @Test
public void testGetWarp() { public void testGetWarp() {
assertEquals(location, wsm.getWarp(world, uuid)); assertEquals(location, wsm.getWarpLocation(world, uuid));
} }
/** /**

View File

@ -133,7 +133,7 @@ public class WarpSignsListenerTest {
// Player is in world // Player is in world
when(wsm.getWarpMap(world)).thenReturn(list); when(wsm.getWarpMap(world)).thenReturn(list);
//Player has a warp sign already here //Player has a warp sign already here
when(wsm.getWarp(any(), any())).thenReturn(location); when(wsm.getWarpLocation(any(), any())).thenReturn(location);
// Unique spot // Unique spot
when(wsm.addWarp(any(), any())).thenReturn(true); when(wsm.addWarp(any(), any())).thenReturn(true);
// Bentobox // Bentobox
@ -421,7 +421,7 @@ public class WarpSignsListenerTest {
@Test @Test
public void testCreateNoSignAlreadyUniqueSpot() { public void testCreateNoSignAlreadyUniqueSpot() {
when(wsm.getWarp(any(), any())).thenReturn(null); when(wsm.getWarpLocation(any(), any())).thenReturn(null);
when(player.hasPermission(anyString())).thenReturn(true); when(player.hasPermission(anyString())).thenReturn(true);
WarpSignsListener wsl = new WarpSignsListener(addon); WarpSignsListener wsl = new WarpSignsListener(addon);
SignChangeEvent e = new SignChangeEvent(block, player, lines); SignChangeEvent e = new SignChangeEvent(block, player, lines);