mirror of
https://github.com/BentoBoxWorld/Warps.git
synced 2024-11-22 10:35:52 +01:00
Fixed dependency on addon-level.
https://github.com/BentoBoxWorld/addon-welcomewarpsigns/issues/3
This commit is contained in:
parent
eed22732ab
commit
3e07cb1901
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>bskyblock.addon</groupId>
|
||||
<artifactId>WelcomeWarpSigns</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
|
||||
<name>WelcomeWarpSigns</name>
|
||||
<description>WelcomeWarpSigns is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.</description>
|
||||
|
@ -2,9 +2,11 @@ package bentobox.addon.warps;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import bentobox.addon.level.Level;
|
||||
import bentobox.addon.warps.commands.WarpCommand;
|
||||
import bentobox.addon.warps.commands.WarpsCommand;
|
||||
import bentobox.addon.warps.config.PluginConfig;
|
||||
@ -22,6 +24,7 @@ public class Warp extends Addon {
|
||||
|
||||
private static final String BSKYBLOCK = "BSkyBlock";
|
||||
private static final String ACIDISLAND = "AcidIsland";
|
||||
private static final String LEVEL_PLUGIN_NAME = "BentoBox-Level";
|
||||
|
||||
// The plugin instance.
|
||||
private BentoBox plugin;
|
||||
@ -116,4 +119,14 @@ public class Warp extends Addon {
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the island level
|
||||
* @param world - world
|
||||
* @param uniqueId - player's UUID
|
||||
* @return island level or null if there is no level plugin
|
||||
*/
|
||||
public Long getLevel(World world, UUID uniqueId) {
|
||||
return plugin.getAddonsManager().getAddonByName(LEVEL_PLUGIN_NAME).map(l -> ((Level) l).getIslandLevel(world, uniqueId)).orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import bentobox.addon.level.Level;
|
||||
import bentobox.addon.warps.event.WarpRemoveEvent;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -27,7 +26,6 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*
|
||||
*/
|
||||
public class WarpSignsListener implements Listener {
|
||||
private static final String LEVEL_PLUGIN_NAME = "BentoBox-Level";
|
||||
|
||||
private BentoBox plugin;
|
||||
|
||||
@ -101,9 +99,9 @@ public class WarpSignsListener implements Listener {
|
||||
user.sendMessage("general.errors.you-need", "[permission]", addon.getPermPrefix(b.getWorld()) + ".island.addwarp");
|
||||
return;
|
||||
}
|
||||
long level = plugin.getAddonsManager().getAddonByName(LEVEL_PLUGIN_NAME).map(l -> (Level)l)
|
||||
.map(l -> l.getIslandLevel(b.getWorld(), user.getUniqueId())).orElse(0L);
|
||||
if (level < addon.getSettings().getWarpLevelRestriction()) {
|
||||
// Get level is level addon is available
|
||||
Long level = addon.getLevel(b.getWorld(), user.getUniqueId());
|
||||
if (level != null && level < addon.getSettings().getWarpLevelRestriction()) {
|
||||
user.sendMessage("warps.error.not-enough-level");
|
||||
user.sendMessage("warps.error.your-level-is",
|
||||
"[level]", String.valueOf(level),
|
||||
|
@ -3,5 +3,7 @@
|
||||
# 10 is default
|
||||
warplevelrestriction: 10
|
||||
|
||||
# Text that player must put on sign to make it a warp sign
|
||||
# Not case sensitive!
|
||||
welcomeLine: [WELCOME]
|
||||
|
||||
|
@ -9,7 +9,6 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -34,12 +33,9 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import bentobox.addon.level.Level;
|
||||
import bentobox.addon.warps.config.PluginConfig;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
|
||||
@ -58,7 +54,6 @@ public class WarpSignsListenerTest {
|
||||
private String[] lines;
|
||||
private FileConfiguration config;
|
||||
private PluginConfig settings;
|
||||
private Level level_addon;
|
||||
private IslandsManager im;
|
||||
|
||||
@Before
|
||||
@ -117,17 +112,13 @@ public class WarpSignsListenerTest {
|
||||
when(settings.getWarpLevelRestriction()).thenReturn(10);
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
|
||||
level_addon = mock(Level.class);
|
||||
Optional<Addon> level = Optional.of(level_addon);
|
||||
AddonsManager am = mock(AddonsManager.class);
|
||||
when(plugin.getAddonsManager()).thenReturn(am);
|
||||
when(am.getAddonByName(Mockito.anyString())).thenReturn(level);
|
||||
when(level_addon.getIslandLevel(Mockito.any(), Mockito.any())).thenReturn(11L); // Higher than 10
|
||||
|
||||
im = mock(IslandsManager.class);
|
||||
// On island
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
when(im.userIsOnIsland(Mockito.any(World.class), Mockito.any(User.class))).thenReturn(true);
|
||||
|
||||
// Sufficient level
|
||||
when(addon.getLevel(Mockito.any(), Mockito.any())).thenReturn(100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -271,7 +262,7 @@ public class WarpSignsListenerTest {
|
||||
@Test
|
||||
public void testOnLevelPresentNotHighEnough() {
|
||||
when(player.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||
when(level_addon.getIslandLevel(Mockito.any(), Mockito.any())).thenReturn(1L);
|
||||
when(addon.getLevel(Mockito.any(), Mockito.any())).thenReturn(1L);
|
||||
WarpSignsListener wsl = new WarpSignsListener(addon);
|
||||
SignChangeEvent e = new SignChangeEvent(block, player, lines);
|
||||
wsl.onSignWarpCreate(e);
|
||||
|
Loading…
Reference in New Issue
Block a user