World Flags are saved in the config.yml file.

Previously, world settings (world setting flags) were not actually being
saved anywhere. They are now saved in the config.yml.

WIP: RemoveMobsListener.java

Improved the FlagTest.
This commit is contained in:
tastybento 2018-06-09 22:09:20 -07:00
parent 1fc1780fd1
commit 90563dac35
12 changed files with 173 additions and 48 deletions

View File

@ -231,6 +231,15 @@ public class Settings implements DataObject, WorldSettings {
@ConfigComment("Default is false, because it is an experimental feature that can break a lot of redstone systems.") @ConfigComment("Default is false, because it is an experimental feature that can break a lot of redstone systems.")
private boolean disableOfflineRedstone = false; private boolean disableOfflineRedstone = false;
@ConfigComment("World flags. These are boolean settings for various flags for this world")
@ConfigEntry(path = "world.flags")
private Map<String, Boolean> worldFlags = new HashMap<>();
{
worldFlags.put("ENTER_EXIT_MESSAGES", true);
worldFlags.put("PISTON_PUSH", true);
worldFlags.put("REMOVE_MOBS", true);
}
// --------------------------------------------- // ---------------------------------------------
/* ISLAND */ /* ISLAND */
@ -1509,4 +1518,18 @@ public class Settings implements DataObject, WorldSettings {
this.ivSettings = ivSettings; this.ivSettings = ivSettings;
} }
/**
* @return the worldFlags
*/
@Override
public Map<String, Boolean> getWorldFlags() {
return worldFlags;
}
/**
* @param worldFlags the worldFlags to set
*/
public void setWorldFlags(Map<String, Boolean> worldFlags) {
this.worldFlags = worldFlags;
}
} }

View File

@ -132,4 +132,10 @@ public interface WorldSettings {
*/ */
List<String> getIvSettings(); List<String> getIvSettings();
/**
* Get world flags
* @return Map of world flags
*/
Map<String, Boolean> getWorldFlags();
} }

View File

@ -1,7 +1,5 @@
package us.tastybento.bskyblock.api.flags; package us.tastybento.bskyblock.api.flags;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import org.bukkit.Material; import org.bukkit.Material;
@ -16,7 +14,6 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.RanksManager; import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Util;
public class Flag implements Comparable<Flag> { public class Flag implements Comparable<Flag> {
@ -31,7 +28,6 @@ public class Flag implements Comparable<Flag> {
private final Material icon; private final Material icon;
private final Listener listener; private final Listener listener;
private final Type type; private final Type type;
private Map<World, Boolean> worldSettings = new HashMap<>();
private boolean setting; private boolean setting;
private final int defaultRank; private final int defaultRank;
private final PanelItem.ClickHandler clickHandler; private final PanelItem.ClickHandler clickHandler;
@ -61,19 +57,21 @@ public class Flag implements Comparable<Flag> {
/** /**
* Check if a setting is set in this world * Check if a setting is set in this world
* @param world - world * @param world - world
* @return world setting, or default system setting if a specific world setting is not set * @return world setting, or default flag setting if a specific world setting is not set
*/ */
public boolean isSetForWorld(World world) { public boolean isSetForWorld(World world) {
return worldSettings.getOrDefault(Util.getWorld(world), setting); return BSkyBlock.getInstance().getIWM().getWorldSettings(world).getWorldFlags().getOrDefault(getID(), setting);
} }
/** /**
* Set the default or global setting for this world * Set a world setting
* @param world - world * @param world - world
* @param setting - true or false * @param setting - true or false
*/ */
public void setSetting(World world, boolean setting) { public void setSetting(World world, boolean setting) {
worldSettings.put(Util.getWorld(world), setting); if (getType().equals(Type.WORLD_SETTING)) {
BSkyBlock.getInstance().getIWM().getWorldSettings(world).getWorldFlags().put(getID(), setting);
}
} }
/** /**
@ -175,7 +173,9 @@ public class Flag implements Comparable<Flag> {
// Dynamic rank list // Dynamic rank list
if (getType().equals(Type.PROTECTION)) { if (getType().equals(Type.PROTECTION)) {
// Protection flag // Protection flag
pib.description(user.getTranslation("protection.panel.flag-item.description-layout", "[description]", user.getTranslation("protection.flags." + id + ".description"))); String d = user.getTranslation("protection.flags." + id + ".description");
d = user.getTranslation("protection.panel.flag-item.description-layout", "[description]", d);
pib.description(d);
plugin.getRanksManager().getRanks().forEach((reference, score) -> { plugin.getRanksManager().getRanks().forEach((reference, score) -> {
if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) { if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) {
pib.description(user.getTranslation("protection.panel.flag-item.blocked_rank") + user.getTranslation(reference)); pib.description(user.getTranslation("protection.panel.flag-item.blocked_rank") + user.getTranslation(reference));

View File

@ -16,6 +16,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.PanelItem.ClickHandler; import us.tastybento.bskyblock.api.panels.PanelItem.ClickHandler;
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
@ -41,9 +42,12 @@ public class InvincibleVisitorsListener extends AbstractFlagListener implements
} else { } else {
getPlugin().getSettings().getIvSettings().add(c.name()); getPlugin().getSettings().getIvSettings().add(c.name());
} }
} // Apply change to panel
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
} else {
// Open the IV Settings panel // Open the IV Settings panel
openPanel(user, ivPanelName); openPanel(user, ivPanelName);
}
return true; return true;
} }
@ -54,21 +58,23 @@ public class InvincibleVisitorsListener extends AbstractFlagListener implements
PanelBuilder pb = new PanelBuilder(); PanelBuilder pb = new PanelBuilder();
pb.user(user).name(ivPanelName); pb.user(user).name(ivPanelName);
// Make panel items // Make panel items
Arrays.stream(EntityDamageEvent.DamageCause.values()).forEach(c -> { Arrays.stream(EntityDamageEvent.DamageCause.values()).forEach(c -> pb.item(getPanelItem(c, user)));
pb.build();
}
private PanelItem getPanelItem(DamageCause c, User user) {
PanelItemBuilder pib = new PanelItemBuilder(); PanelItemBuilder pib = new PanelItemBuilder();
pib.name(Util.prettifyText(c.toString())); pib.name(Util.prettifyText(c.toString()));
pib.clickHandler(this); pib.clickHandler(this);
if (getPlugin().getSettings().getIvSettings().contains(c.name())) { if (getPlugin().getSettings().getIvSettings().contains(c.name())) {
pib.icon(Material.GREEN_GLAZED_TERRACOTTA); pib.icon(Material.GREEN_SHULKER_BOX);
pib.description(user.getTranslation("protection.panel.flag-item.setting-active")); pib.description(user.getTranslation("protection.panel.flag-item.setting-active"));
} else { } else {
pib.icon(Material.RED_GLAZED_TERRACOTTA); pib.icon(Material.RED_SHULKER_BOX);
pib.description(user.getTranslation("protection.panel.flag-item.setting-disabled")); pib.description(user.getTranslation("protection.panel.flag-item.setting-disabled"));
} }
pb.item(pib.build()); return pib.build();
});
pb.build();
} }
/** /**

View File

@ -0,0 +1,12 @@
/**
*
*/
package us.tastybento.bskyblock.listeners.flags;
/**
* @author tastybento
*
*/
public class RemoveMobsListener extends AbstractFlagListener {
}

View File

@ -29,6 +29,7 @@ import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
import us.tastybento.bskyblock.listeners.flags.PistonPushListener; import us.tastybento.bskyblock.listeners.flags.PistonPushListener;
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener; import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
import us.tastybento.bskyblock.listeners.flags.PortalListener; import us.tastybento.bskyblock.listeners.flags.PortalListener;
import us.tastybento.bskyblock.listeners.flags.RemoveMobsListener;
import us.tastybento.bskyblock.listeners.flags.ShearingListener; import us.tastybento.bskyblock.listeners.flags.ShearingListener;
import us.tastybento.bskyblock.listeners.flags.TeleportationListener; import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
import us.tastybento.bskyblock.listeners.flags.clicklisteners.IslandToggleClickListener; import us.tastybento.bskyblock.listeners.flags.clicklisteners.IslandToggleClickListener;
@ -157,7 +158,8 @@ public class Flags {
static InvincibleVisitorsListener ilv = new InvincibleVisitorsListener(); static InvincibleVisitorsListener ilv = new InvincibleVisitorsListener();
public static final Flag INVINCIBLE_VISITORS = new FlagBuilder().id("INVINCIBLE_VISITORS").icon(Material.DIAMOND_CHESTPLATE).type(Type.MENU) public static final Flag INVINCIBLE_VISITORS = new FlagBuilder().id("INVINCIBLE_VISITORS").icon(Material.DIAMOND_CHESTPLATE).type(Type.MENU)
.listener(ilv).onClick(ilv).build(); .listener(ilv).onClick(ilv).build();
public static final Flag REMOVE_MOBS = new FlagBuilder().id("REMOVE_MOBS").icon(Material.GLOWSTONE_DUST).type(Type.WORLD_SETTING)
.listener(new RemoveMobsListener()).allowedByDefault(true).onClick(new WorldToggleClickListener("REMOVE_MOBS")).build();
/** /**
* @return List of all the flags in this class * @return List of all the flags in this class
*/ */

View File

@ -8,34 +8,43 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito; import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.RanksManager; import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ Flag.class, Util.class }) @PrepareForTest({ BSkyBlock.class, Util.class, Bukkit.class })
public class FlagTest { public class FlagTest {
@BeforeClass @BeforeClass
@ -44,8 +53,27 @@ public class FlagTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Set up plugin
BSkyBlock plugin = mock(BSkyBlock.class);
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class)); when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
// World Settings
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
PowerMockito.mockStatic(Bukkit.class);
ItemFactory itemF = mock(ItemFactory.class);
ItemMeta im = mock(ItemMeta.class);
when(itemF.getItemMeta(Mockito.any())).thenReturn(im);
when(Bukkit.getItemFactory()).thenReturn(itemF);
} }
@Test @Test
@ -115,6 +143,7 @@ public class FlagTest {
assertEquals(100, id.getDefaultRank()); assertEquals(100, id.getDefaultRank());
} }
@SuppressWarnings("unlikely-arg-type")
@Test @Test
public void testEqualsObject() { public void testEqualsObject() {
Flag flag1 = null; Flag flag1 = null;
@ -144,10 +173,22 @@ public class FlagTest {
Island island = mock(Island.class); Island island = mock(Island.class);
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK); when(island.getFlag(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK);
User user = mock(User.class); User user = mock(User.class, Mockito.withSettings().verboseLogging());
when(user.getUniqueId()).thenReturn(UUID.randomUUID()); when(user.getUniqueId()).thenReturn(UUID.randomUUID());
when(user.getTranslation(Mockito.anyString())).thenReturn("translation"); Answer<String> answer = new Answer<String>() {
when(user.getTranslation(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn("long translation");
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
StringBuilder sb = new StringBuilder();
Arrays.stream(invocation.getArguments()).forEach(sb::append);
sb.append("mock");
return sb.toString();
}
};
when(user.getTranslation(Mockito.anyVararg())).thenAnswer(answer);
when(user.getTranslation(Mockito.any(),Mockito.any(),Mockito.any())).thenAnswer(answer);
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island); when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
@ -160,24 +201,15 @@ public class FlagTest {
when(rm.getRank(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn("Visitor"); when(rm.getRank(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn("Visitor");
when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner"); when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner");
PowerMockito.whenNew(ItemStack.class).withAnyArguments().thenReturn(mock(ItemStack.class));
PanelItemBuilder pib = mock(PanelItemBuilder.class);
when(pib.description(Mockito.anyString())).thenReturn(pib);
when(pib.name(Mockito.anyString())).thenReturn(pib);
when(pib.icon(Mockito.any(ItemStack.class))).thenReturn(pib);
when(pib.clickHandler(Mockito.any())).thenReturn(pib);
when(pib.build()).thenReturn(mock(PanelItem.class));
// Remember to prepare the calling class, not the subject class!
PowerMockito.whenNew(PanelItemBuilder.class).withAnyArguments().thenReturn(pib);
Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null); Flag id = new Flag("id", Material.ACACIA_DOOR, null, false, Flag.Type.PROTECTION, 0, null);
id.toPanelItem(plugin, user); PanelItem pi = id.toPanelItem(plugin, user);
verify(user).getTranslation(Mockito.eq("protection.flags.id.name")); verify(user).getTranslation(Mockito.eq("protection.flags.id.name"));
verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), Mockito.anyVararg()); verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), Mockito.anyVararg());
assertEquals(Material.ACACIA_DOOR, pi.getItem().getType());
} }
@Test @Test

View File

@ -7,6 +7,8 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -27,6 +29,7 @@ import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.user.Notifier; import us.tastybento.bskyblock.api.user.Notifier;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -155,6 +158,12 @@ public class EnterExitListenerTest {
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
} }
/** /**

View File

@ -6,7 +6,9 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -42,6 +44,7 @@ import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.user.Notifier; import us.tastybento.bskyblock.api.user.Notifier;
import us.tastybento.bskyblock.api.user.User; import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -98,7 +101,6 @@ public class FireListenerTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getIslandWorld()).thenReturn(world); when(iwm.getIslandWorld()).thenReturn(world);
when(iwm.getNetherWorld()).thenReturn(world); when(iwm.getNetherWorld()).thenReturn(world);
when(iwm.getEndWorld()).thenReturn(world); when(iwm.getEndWorld()).thenReturn(world);
@ -134,6 +136,12 @@ public class FireListenerTest {
PlayersManager pm = mock(PlayersManager.class); PlayersManager pm = mock(PlayersManager.class);
when(pm.getName(Mockito.any())).thenReturn("tastybento"); when(pm.getName(Mockito.any())).thenReturn("tastybento");
when(plugin.getPlayers()).thenReturn(pm); when(plugin.getPlayers()).thenReturn(pm);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
} }
@Before @Before

View File

@ -6,6 +6,8 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -34,6 +36,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags; import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.managers.FlagsManager; import us.tastybento.bskyblock.managers.FlagsManager;
@ -114,6 +117,12 @@ public class MobSpawnListenerTest {
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class)); when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
} }

View File

@ -61,6 +61,7 @@ import com.google.common.collect.ImmutableMap;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Settings; import us.tastybento.bskyblock.Settings;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.flags.Flag; import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.Panel;
import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.PanelItem;
@ -184,6 +185,12 @@ public class PVPListenerTest {
BukkitScheduler sch = mock(BukkitScheduler.class); BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch); when(Bukkit.getScheduler()).thenReturn(sch);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
} }
/** /**

View File

@ -6,7 +6,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
@ -25,8 +27,10 @@ import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags; import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager; import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -89,7 +93,14 @@ public class PistonPushListenerTest {
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);
Flags.PISTON_PUSH.setSetting(world, true); // World Settings
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
} }
@Test @Test