1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-22 10:35:52 +01:00

Hybrid version. Works on 1.13.2 and 1.14.1

This commit is contained in:
tastybento 2019-05-15 15:16:15 -07:00
parent ddffcf3f38
commit 45ee5b1186
6 changed files with 51 additions and 39 deletions

View File

@ -66,7 +66,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<version>1.14.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -44,7 +44,7 @@ public class WarpPanelManager {
private Material getSignIcon(World world, UUID warpOwner) {
Material type = addon.getWarpSignsManager().getWarp(world, warpOwner).getBlock().getType();
return Material.valueOf(type.toString().replace("_WALL", ""));
return Material.valueOf(type.toString().replace("WALL_", ""));
}
/**

View File

@ -6,7 +6,6 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler;
@ -48,10 +47,8 @@ public class WarpSignsListener implements Listener {
public void onSignBreak(BlockBreakEvent e) {
Block b = e.getBlock();
// Signs only
if (!Tag
.SIGNS
.isTagged(b.getType())) {
// FIXME: When we drop support for 1.13, switch to Tag.SIGNS
if (!e.getBlock().getType().name().contains("SIGN")) {
return;
}
if (!addon.inRegisteredWorld(b.getWorld())) {
@ -130,7 +127,8 @@ public class WarpSignsListener implements Listener {
// so,
// deactivate it
Block oldSignBlock = oldSignLoc.getBlock();
if (Tag.SIGNS.isTagged(oldSignBlock.getType())) {
// FIXME: When we drop support for 1.13, switch to Tag.SIGNS
if (oldSignBlock.getType().name().contains("SIGN")) {
// The block is still a sign
Sign oldSign = (Sign) oldSignBlock.getState();
if (oldSign != null) {

View File

@ -18,7 +18,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -169,7 +168,7 @@ public class WarpSignsManager {
// Load into map
if (warps != null) {
warps.getWarpSigns().forEach((k,v) -> {
if (k != null && k.getWorld() != null && Tag.SIGNS.isTagged(k.getBlock().getType())) {
if (k != null && k.getWorld() != null && k.getBlock().getType().name().contains("SIGN")) {
// Add to map
getWarpMap(k.getWorld()).put(v, k);
}
@ -184,7 +183,7 @@ public class WarpSignsManager {
*/
private void popSign(Location loc) {
Block b = loc.getBlock();
if (Tag.SIGNS.isTagged(b.getType())) {
if (b.getType().name().contains("SIGN")) {
Sign s = (Sign) b.getState();
if (s != null) {
if (s.getLine(0).equalsIgnoreCase(ChatColor.GREEN + addon.getConfig().getString("welcomeLine"))) {
@ -253,7 +252,7 @@ public class WarpSignsManager {
List<String> result = new ArrayList<>();
//get the sign info
Location signLocation = getWarp(world, uuid);
if (signLocation != null && Tag.SIGNS.isTagged(signLocation.getBlock().getType())) {
if (signLocation != null && signLocation.getBlock().getType().name().contains("SIGN")) {
Sign sign = (Sign)signLocation.getBlock().getState();
result.addAll(Arrays.asList(sign.getLines()));
// Clean up - remove the [WELCOME] line
@ -383,15 +382,7 @@ public class WarpSignsManager {
}
// Find out which direction the warp is facing
Block b = warpSpot.getBlock();
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())) {
if (b.getType().name().contains("WALL_SIGN")) {
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();
@ -404,6 +395,14 @@ public class WarpSignsManager {
addon.getWarpSignsManager().warpPlayer(user, oneDown, owner, directionFacing, pvp);
return;
}
} else if (b.getType().name().contains("SIGN")) {
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 {
// Warp has been removed
user.sendMessage("warps.error.does-not-exist");
@ -412,12 +411,6 @@ 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 (Tag.STANDING_SIGNS.isTagged(b.getType())) {
addon.getLogger().warning(
"Unsafe warp found at " + warpSpot.toString() + " owned by " + addon.getPlugin().getPlayers().getName(owner));
}
return;
} else {
final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(),

View File

@ -11,7 +11,10 @@ import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFactory;
@ -30,9 +33,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.warps.Warp;
import world.bentobox.warps.WarpPanelManager;
import world.bentobox.warps.WarpSignsManager;
import world.bentobox.warps.config.Settings;
/**
@ -105,6 +105,19 @@ public class WarpPanelManagerTest {
Settings settings = mock(Settings.class);
when(settings.getIcon()).thenReturn("SIGN");
when(addon.getSettings()).thenReturn(settings);
Location location = mock(Location.class);
Block block = mock(Block.class);
Material sign_type;
try {
sign_type = Material.valueOf("SIGN");
} catch (Exception e) {
sign_type = Material.valueOf("OAK_SIGN");
}
when(block.getType()).thenReturn(sign_type);
when(location.getBlock()).thenReturn(block);
// Sign block
when(wsm.getWarp(Mockito.any(), Mockito.any())).thenReturn(location);
}
/**

View File

@ -44,6 +44,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.warps.config.Settings;
@ -68,19 +69,13 @@ public class WarpSignsListenerTest {
private FileConfiguration config;
private Settings settings;
private IslandsManager im;
@Mock
private Tag<Material> value;
@Before
public void setUp() throws Exception {
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");
@ -90,13 +85,18 @@ public class WarpSignsListenerTest {
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);
when(config.getString(Mockito.anyString())).thenReturn("[WELCOME]");
when(addon.getConfig()).thenReturn(config);
// Block
when(block.getType()).thenReturn(Material.OAK_WALL_SIGN);
Material sign;
try {
sign = Material.valueOf("OAK_WALL_SIGN");
} catch (Exception e) {
sign = Material.valueOf("WALL_SIGN");
}
when(block.getType()).thenReturn(sign);
when(block.getWorld()).thenReturn(world);
// Player
when(player.hasPermission(Mockito.anyString())).thenReturn(false);
@ -154,6 +154,15 @@ public class WarpSignsListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// Locales
Answer<String> answer = invocation -> invocation.getArgumentAt(1, String.class);
when(lm.get(Mockito.any(User.class), Mockito.anyString())).thenAnswer(answer);
when(plugin.getLocalesManager()).thenReturn(lm);
// Placeholders
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
when(placeholdersManager.replacePlaceholders(Mockito.any(), Mockito.any())).thenAnswer(answer);
}
@ -169,7 +178,6 @@ public class WarpSignsListenerTest {
when(block.getType()).thenReturn(Material.STONE);
wsl.onSignBreak(e);
assertFalse(e.isCancelled());
Mockito.verify(block, Mockito.times(2)).getType();
}
@Test