Works, but tests do not pass due to Tag issue
This commit is contained in:
parent
aeb5a60e94
commit
5b07d33491
2
pom.xml
2
pom.xml
|
@ -66,7 +66,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.14-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package world.bentobox.warps;
|
||||
|
||||
|
||||
import org.bukkit.World;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
@ -20,9 +21,9 @@ import world.bentobox.warps.config.Settings;
|
|||
*
|
||||
*/
|
||||
public class Warp extends Addon {
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Variables
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This variable stores string for Level addon.
|
||||
|
@ -54,9 +55,9 @@ public class Warp extends Addon {
|
|||
*/
|
||||
private boolean hooked;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Methods
|
||||
// ---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Methods
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ public class WarpPanelManager {
|
|||
private PanelItem getPanelItem(World world, UUID warpOwner) {
|
||||
// Return a sign panel item
|
||||
return new PanelItemBuilder()
|
||||
.icon(Material.SIGN)
|
||||
.icon(getSignIcon(world, warpOwner))
|
||||
.name(addon.getPlugin().getPlayers().getName(warpOwner))
|
||||
.description(getSign(world, warpOwner))
|
||||
.clickHandler((panel, clicker, click, slot) -> { {
|
||||
|
@ -41,6 +41,11 @@ public class WarpPanelManager {
|
|||
}).build();
|
||||
}
|
||||
|
||||
private Material getSignIcon(World world, UUID warpOwner) {
|
||||
Material type = addon.getWarpSignsManager().getWarp(world, warpOwner).getBlock().getType();
|
||||
return Material.valueOf(type.toString().replace("_WALL", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets sign text and cache it
|
||||
* @param playerUUID
|
||||
|
@ -84,7 +89,7 @@ public class WarpPanelManager {
|
|||
// Next
|
||||
panelBuilder.item(new PanelItemBuilder()
|
||||
.name("Next")
|
||||
.icon(new ItemStack(Material.SIGN))
|
||||
.icon(new ItemStack(Material.STONE))
|
||||
.clickHandler((panel, clicker, click, slot) -> {
|
||||
user.closeInventory();
|
||||
showWarpPanel(world, user, panelNum+1);
|
||||
|
@ -95,7 +100,7 @@ public class WarpPanelManager {
|
|||
// Previous
|
||||
panelBuilder.item(new PanelItemBuilder()
|
||||
.name("Previous")
|
||||
.icon(new ItemStack(Material.SIGN))
|
||||
.icon(new ItemStack(Material.COBBLESTONE))
|
||||
.clickHandler((panel, clicker, click, slot) -> {
|
||||
user.closeInventory();
|
||||
showWarpPanel(world, user, panelNum-1);
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.UUID;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -48,7 +48,10 @@ public class WarpSignsListener implements Listener {
|
|||
public void onSignBreak(BlockBreakEvent e) {
|
||||
Block b = e.getBlock();
|
||||
// Signs only
|
||||
if (!b.getType().equals(Material.SIGN) && !b.getType().equals(Material.WALL_SIGN)) {
|
||||
|
||||
if (!Tag
|
||||
.SIGNS
|
||||
.isTagged(b.getType())) {
|
||||
return;
|
||||
}
|
||||
if (!addon.inRegisteredWorld(b.getWorld())) {
|
||||
|
@ -127,7 +130,7 @@ public class WarpSignsListener implements Listener {
|
|||
// so,
|
||||
// deactivate it
|
||||
Block oldSignBlock = oldSignLoc.getBlock();
|
||||
if (oldSignBlock.getType().equals(Material.SIGN) || oldSignBlock.getType().equals(Material.WALL_SIGN)) {
|
||||
if (Tag.SIGNS.isTagged(oldSignBlock.getType())) {
|
||||
// The block is still a sign
|
||||
Sign oldSign = (Sign) oldSignBlock.getState();
|
||||
if (oldSign != null) {
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.stream.Collectors;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
@ -169,7 +169,7 @@ public class WarpSignsManager {
|
|||
// Load into map
|
||||
if (warps != null) {
|
||||
warps.getWarpSigns().forEach((k,v) -> {
|
||||
if (k != null && k.getWorld() != null && (k.getBlock().getType().equals(Material.SIGN) || k.getBlock().getType().equals(Material.WALL_SIGN))) {
|
||||
if (k != null && k.getWorld() != null && Tag.SIGNS.isTagged(k.getBlock().getType())) {
|
||||
// Add to map
|
||||
getWarpMap(k.getWorld()).put(v, k);
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ public class WarpSignsManager {
|
|||
*/
|
||||
private void popSign(Location loc) {
|
||||
Block b = loc.getBlock();
|
||||
if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
if (Tag.SIGNS.isTagged(b.getType())) {
|
||||
Sign s = (Sign) b.getState();
|
||||
if (s != null) {
|
||||
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + addon.getConfig().getString("welcomeLine"))) {
|
||||
|
@ -253,7 +253,7 @@ public class WarpSignsManager {
|
|||
List<String> result = new ArrayList<>();
|
||||
//get the sign info
|
||||
Location signLocation = getWarp(world, uuid);
|
||||
if (signLocation != null && (signLocation.getBlock().getType().equals(Material.SIGN) || signLocation.getBlock().getType().equals(Material.WALL_SIGN))) {
|
||||
if (signLocation != null && Tag.SIGNS.isTagged(signLocation.getBlock().getType())) {
|
||||
Sign sign = (Sign)signLocation.getBlock().getState();
|
||||
result.addAll(Arrays.asList(sign.getLines()));
|
||||
// Clean up - remove the [WELCOME] line
|
||||
|
@ -383,16 +383,23 @@ public class WarpSignsManager {
|
|||
}
|
||||
// Find out which direction the warp is facing
|
||||
Block b = warpSpot.getBlock();
|
||||
if (b.getType().equals(Material.SIGN) || b.getType().equals(Material.WALL_SIGN)) {
|
||||
Sign sign = (Sign) b.getState();
|
||||
org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
|
||||
if (Tag.STANDING_SIGNS.isTagged(b.getType())) {
|
||||
org.bukkit.block.data.type.Sign s = (org.bukkit.block.data.type.Sign) b.getBlockData();
|
||||
BlockFace directionFacing = s.getRotation();
|
||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||
if ((plugin.getIslands().isSafeLocation(inFront))) {
|
||||
addon.getWarpSignsManager().warpPlayer(user, inFront, owner, directionFacing, pvp);
|
||||
return;
|
||||
}
|
||||
} else if (Tag.WALL_SIGNS.isTagged(b.getType())) {
|
||||
org.bukkit.block.data.type.WallSign s = (org.bukkit.block.data.type.WallSign) b.getBlockData();
|
||||
BlockFace directionFacing = s.getFacing();
|
||||
Location inFront = b.getRelative(directionFacing).getLocation();
|
||||
Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
|
||||
if ((plugin.getIslands().isSafeLocation(inFront))) {
|
||||
addon.getWarpSignsManager().warpPlayer(user, inFront, owner, directionFacing, pvp);
|
||||
return;
|
||||
} else if (b.getType().equals(Material.WALL_SIGN) && plugin.getIslands().isSafeLocation(oneDown)) {
|
||||
} else if (plugin.getIslands().isSafeLocation(oneDown)) {
|
||||
// Try one block down if this is a wall sign
|
||||
addon.getWarpSignsManager().warpPlayer(user, oneDown, owner, directionFacing, pvp);
|
||||
return;
|
||||
|
@ -406,7 +413,7 @@ public class WarpSignsManager {
|
|||
if (!(plugin.getIslands().isSafeLocation(warpSpot))) {
|
||||
user.sendMessage("warps.error.not-safe");
|
||||
// WALL_SIGN's will always be unsafe if the place in front is obscured.
|
||||
if (b.getType().equals(Material.SIGN)) {
|
||||
if (Tag.STANDING_SIGNS.isTagged(b.getType())) {
|
||||
addon.getLogger().warning(
|
||||
"Unsafe warp found at " + warpSpot.toString() + " owned by " + addon.getPlugin().getPlayers().getName(owner));
|
||||
|
||||
|
|
|
@ -17,6 +17,9 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
|
@ -28,6 +31,7 @@ import org.bukkit.plugin.PluginManager;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
@ -44,34 +48,57 @@ import world.bentobox.bentobox.util.Util;
|
|||
import world.bentobox.warps.config.Settings;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, Util.class})
|
||||
@PrepareForTest({Bukkit.class, Util.class, NamespacedKey.class, Tag.class})
|
||||
public class WarpSignsListenerTest {
|
||||
|
||||
@Mock
|
||||
private Warp addon;
|
||||
@Mock
|
||||
private Block block;
|
||||
@Mock
|
||||
private Player player;
|
||||
@Mock
|
||||
private World world;
|
||||
private Sign s;
|
||||
private WarpSignsManager wsm;
|
||||
private PluginManager pm;
|
||||
private UUID uuid;
|
||||
private String[] lines;
|
||||
@Mock
|
||||
private FileConfiguration config;
|
||||
private Settings settings;
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Tag<Material> value;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
addon = mock(Warp.class);
|
||||
PowerMockito.mockStatic(Tag.class);
|
||||
when(Tag.WOOL).thenReturn(value);
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
pm = mock(PluginManager.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pm);
|
||||
when(value.isTagged(Mockito.any())).thenReturn(true);
|
||||
when(Bukkit.getTag(Mockito.anyString(), Mockito.any(), Mockito.eq(Material.class))).thenReturn(value);
|
||||
|
||||
Server server = mock(Server.class);
|
||||
when(server.getVersion()).thenReturn("1.14");
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
Bukkit.setServer(server);
|
||||
|
||||
PowerMockito.mockStatic(NamespacedKey.class);
|
||||
NamespacedKey keyValue = mock(NamespacedKey.class);
|
||||
when(NamespacedKey.minecraft(Mockito.anyString())).thenReturn(keyValue);
|
||||
when(server.getTag(Mockito.anyString(), Mockito.any(), Mockito.eq(Material.class))).thenReturn(value);
|
||||
|
||||
when(addon.inRegisteredWorld(Mockito.any())).thenReturn(true);
|
||||
config = mock(FileConfiguration.class);
|
||||
when(config.getString(Mockito.anyString())).thenReturn("[WELCOME]");
|
||||
when(addon.getConfig()).thenReturn(config);
|
||||
block = mock(Block.class);
|
||||
when(block.getType()).thenReturn(Material.WALL_SIGN);
|
||||
world = mock(World.class);
|
||||
// Block
|
||||
when(block.getType()).thenReturn(Material.OAK_WALL_SIGN);
|
||||
when(block.getWorld()).thenReturn(world);
|
||||
player = mock(Player.class);
|
||||
// Player
|
||||
when(player.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
|
@ -104,11 +131,6 @@ public class WarpSignsListenerTest {
|
|||
}});
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
pm = mock(PluginManager.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pm);
|
||||
|
||||
// Lines
|
||||
lines = new String[] {"[WELCOME]", "line2", "line3", "line4"};
|
||||
|
||||
|
@ -131,6 +153,8 @@ public class WarpSignsListenerTest {
|
|||
// Util
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue