mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Adds new flag change events and fires them.
Updated click tests. https://github.com/BentoBoxWorld/BentoBox/issues/753
This commit is contained in:
parent
a8578b5658
commit
0f5629b729
@ -1,54 +0,0 @@
|
|||||||
package world.bentobox.bentobox.api.events.island;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This event is fired when a player changes a flag on his island
|
|
||||||
* <p>
|
|
||||||
* Canceling this event will result in canceling the change.
|
|
||||||
*
|
|
||||||
* @author Poslovitch
|
|
||||||
*/
|
|
||||||
public class FlagChangeEvent extends IslandBaseEvent {
|
|
||||||
private final UUID player;
|
|
||||||
private final Flag editedFlag;
|
|
||||||
private final boolean setTo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param island - island
|
|
||||||
* @param player - the player
|
|
||||||
* @param editedFlag - flag edited
|
|
||||||
* @param setTo - new value
|
|
||||||
*/
|
|
||||||
public FlagChangeEvent(Island island, UUID player, Flag editedFlag, boolean setTo) {
|
|
||||||
super(island);
|
|
||||||
this.player = player;
|
|
||||||
this.editedFlag = editedFlag;
|
|
||||||
this.setTo = setTo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the player
|
|
||||||
*/
|
|
||||||
public UUID getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the edited flag
|
|
||||||
*/
|
|
||||||
public Flag getFlag() {
|
|
||||||
return editedFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return enabled/disabled
|
|
||||||
*/
|
|
||||||
public boolean getSetTo() {
|
|
||||||
return setTo;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
package world.bentobox.bentobox.api.events.island;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.events.BentoBoxEvent;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
* @since 1.6.0
|
||||||
|
*/
|
||||||
|
public class FlagProtectionChangeEvent extends BentoBoxEvent {
|
||||||
|
|
||||||
|
private final Island island;
|
||||||
|
private final UUID player;
|
||||||
|
private final Flag editedFlag;
|
||||||
|
private final int setTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that fires when an island protection flag is changed
|
||||||
|
* @param island - island
|
||||||
|
* @param player - player changing the flag
|
||||||
|
* @param editedFlag - flag that has changed
|
||||||
|
* @param setTo - value it was set to
|
||||||
|
*/
|
||||||
|
public FlagProtectionChangeEvent(Island island, UUID player, Flag editedFlag, int setTo) {
|
||||||
|
this.island = island;
|
||||||
|
this.player = player;
|
||||||
|
this.editedFlag = editedFlag;
|
||||||
|
this.setTo = setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the island
|
||||||
|
*/
|
||||||
|
public Island getIsland() {
|
||||||
|
return island;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the player
|
||||||
|
*/
|
||||||
|
public UUID getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the editedFlag
|
||||||
|
*/
|
||||||
|
public Flag getEditedFlag() {
|
||||||
|
return editedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the setTo
|
||||||
|
*/
|
||||||
|
public int getSetTo() {
|
||||||
|
return setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package world.bentobox.bentobox.api.events.island;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.events.BentoBoxEvent;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
* @since 1.6.0
|
||||||
|
*/
|
||||||
|
public class FlagSettingChangeEvent extends BentoBoxEvent {
|
||||||
|
|
||||||
|
private final Island island;
|
||||||
|
private final UUID player;
|
||||||
|
private final Flag editedFlag;
|
||||||
|
private final boolean setTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that fires when an island setting flag is changed
|
||||||
|
* @param island - island
|
||||||
|
* @param player - player changing the flag
|
||||||
|
* @param editedFlag - flag that has changed
|
||||||
|
* @param setTo - value it was set to
|
||||||
|
*/
|
||||||
|
public FlagSettingChangeEvent(Island island, UUID player, Flag editedFlag, boolean setTo) {
|
||||||
|
this.island = island;
|
||||||
|
this.player = player;
|
||||||
|
this.editedFlag = editedFlag;
|
||||||
|
this.setTo = setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the island
|
||||||
|
*/
|
||||||
|
public Island getIsland() {
|
||||||
|
return island;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the player
|
||||||
|
*/
|
||||||
|
public UUID getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the editedFlag
|
||||||
|
*/
|
||||||
|
public Flag getEditedFlag() {
|
||||||
|
return editedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the setTo
|
||||||
|
*/
|
||||||
|
public boolean isSetTo() {
|
||||||
|
return setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package world.bentobox.bentobox.api.events.island;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.api.events.BentoBoxEvent;
|
||||||
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
* @since 1.6.0
|
||||||
|
*/
|
||||||
|
public class FlagWorldSettingChangeEvent extends BentoBoxEvent {
|
||||||
|
|
||||||
|
private final World world;
|
||||||
|
private final UUID player;
|
||||||
|
private final Flag editedFlag;
|
||||||
|
private final boolean setTo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that fires when a world setting is changed
|
||||||
|
* @param world - world
|
||||||
|
* @param player - player changing the flag
|
||||||
|
* @param editedFlag - flag that has changed
|
||||||
|
* @param setTo - value it was set to
|
||||||
|
*/
|
||||||
|
public FlagWorldSettingChangeEvent(World world, UUID player, Flag editedFlag, boolean setTo) {
|
||||||
|
this.world = world;
|
||||||
|
this.player = player;
|
||||||
|
this.editedFlag = editedFlag;
|
||||||
|
this.setTo = setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the world
|
||||||
|
*/
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the player
|
||||||
|
*/
|
||||||
|
public UUID getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the editedFlag
|
||||||
|
*/
|
||||||
|
public Flag getEditedFlag() {
|
||||||
|
return editedFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the setTo
|
||||||
|
*/
|
||||||
|
public boolean isSetTo() {
|
||||||
|
return setTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagProtectionChangeEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
@ -86,6 +88,8 @@ public class CycleClick implements PanelItem.ClickHandler {
|
|||||||
island.setFlag(flag, rm.getRankUpValue(currentRank));
|
island.setFlag(flag, rm.getRankUpValue(currentRank));
|
||||||
}
|
}
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F);
|
||||||
|
// Fire event
|
||||||
|
Bukkit.getPluginManager().callEvent(new FlagProtectionChangeEvent(island, user.getUniqueId(), flag, island.getFlag(flag)));
|
||||||
} else if (click.equals(ClickType.RIGHT)) {
|
} else if (click.equals(ClickType.RIGHT)) {
|
||||||
if (currentRank <= minRank) {
|
if (currentRank <= minRank) {
|
||||||
island.setFlag(flag, maxRank);
|
island.setFlag(flag, maxRank);
|
||||||
@ -93,6 +97,8 @@ public class CycleClick implements PanelItem.ClickHandler {
|
|||||||
island.setFlag(flag, rm.getRankDownValue(currentRank));
|
island.setFlag(flag, rm.getRankDownValue(currentRank));
|
||||||
}
|
}
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
// Fire event
|
||||||
|
Bukkit.getPluginManager().callEvent(new FlagProtectionChangeEvent(island, user.getUniqueId(), flag, island.getFlag(flag)));
|
||||||
} else if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
} else if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
||||||
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
||||||
invisible = true;
|
invisible = true;
|
||||||
@ -103,8 +109,7 @@ public class CycleClick implements PanelItem.ClickHandler {
|
|||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||||
}
|
}
|
||||||
// Save changes
|
// Save changes
|
||||||
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings); }
|
||||||
}
|
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagSettingChangeEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
@ -72,6 +74,8 @@ public class IslandToggleClick implements ClickHandler {
|
|||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
// Set cooldown
|
// Set cooldown
|
||||||
island.setCooldown(flag);
|
island.setCooldown(flag);
|
||||||
|
// Fire event
|
||||||
|
Bukkit.getPluginManager().callEvent(new FlagSettingChangeEvent(island, user.getUniqueId(), flag, island.isAllowed(flag)));
|
||||||
}
|
}
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package world.bentobox.bentobox.api.flags.clicklisteners;
|
package world.bentobox.bentobox.api.flags.clicklisteners;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagWorldSettingChangeEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
@ -60,6 +62,8 @@ public class WorldToggleClick implements ClickHandler {
|
|||||||
// Toggle flag
|
// Toggle flag
|
||||||
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
// Fire event
|
||||||
|
Bukkit.getPluginManager().callEvent(new FlagWorldSettingChangeEvent(user.getWorld(), user.getUniqueId(), flag, flag.isSetForWorld(user.getWorld())));
|
||||||
}
|
}
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||||
|
@ -2,9 +2,13 @@ package world.bentobox.bentobox.api.flags.clicklisteners;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
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 static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.anyString;
|
||||||
|
import static org.mockito.Mockito.eq;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -18,10 +22,12 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
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;
|
||||||
@ -30,6 +36,7 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.Settings;
|
import world.bentobox.bentobox.Settings;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagProtectionChangeEvent;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
@ -52,16 +59,27 @@ public class CycleClickTest {
|
|||||||
private static final Integer X = 600;
|
private static final Integer X = 600;
|
||||||
private static final Integer Y = 120;
|
private static final Integer Y = 120;
|
||||||
private static final Integer Z = 10000;
|
private static final Integer Z = 10000;
|
||||||
|
@Mock
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
|
@Mock
|
||||||
private Flag flag;
|
private Flag flag;
|
||||||
|
@Mock
|
||||||
private Panel panel;
|
private Panel panel;
|
||||||
|
@Mock
|
||||||
private Inventory inv;
|
private Inventory inv;
|
||||||
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
|
@Mock
|
||||||
private RanksManager rm;
|
private RanksManager rm;
|
||||||
|
@Mock
|
||||||
|
private PluginManager pim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception - exception
|
* @throws java.lang.Exception - exception
|
||||||
@ -70,7 +88,6 @@ public class CycleClickTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
plugin = mock(BentoBox.class);
|
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// World
|
// World
|
||||||
@ -83,7 +100,6 @@ public class CycleClickTest {
|
|||||||
// Player
|
// Player
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
|
||||||
User.setPlugin(plugin);
|
User.setPlugin(plugin);
|
||||||
when(user.isOp()).thenReturn(false);
|
when(user.isOp()).thenReturn(false);
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
@ -91,17 +107,16 @@ public class CycleClickTest {
|
|||||||
when(user.getPlayer()).thenReturn(p);
|
when(user.getPlayer()).thenReturn(p);
|
||||||
when(user.getName()).thenReturn("tastybento");
|
when(user.getName()).thenReturn("tastybento");
|
||||||
when(user.getWorld()).thenReturn(world);
|
when(user.getWorld()).thenReturn(world);
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(true);
|
when(user.hasPermission(anyString())).thenReturn(true);
|
||||||
|
|
||||||
// No island for player to begin with (set it later in the tests)
|
// No island for player to begin with (set it later in the tests)
|
||||||
im = mock(IslandsManager.class);
|
when(im.hasIsland(any(), eq(uuid))).thenReturn(false);
|
||||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
|
||||||
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Has team
|
// Has team
|
||||||
PlayersManager pm = mock(PlayersManager.class);
|
PlayersManager pm = mock(PlayersManager.class);
|
||||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
@ -119,9 +134,8 @@ public class CycleClickTest {
|
|||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
|
|
||||||
// Island Banned list initialization
|
// Island Banned list initialization
|
||||||
island = mock(Island.class);
|
|
||||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||||
when(island.isBanned(Mockito.any())).thenReturn(false);
|
when(island.isBanned(any())).thenReturn(false);
|
||||||
Location loc = mock(Location.class);
|
Location loc = mock(Location.class);
|
||||||
when(loc.getWorld()).thenReturn(world);
|
when(loc.getWorld()).thenReturn(world);
|
||||||
when(loc.getBlockX()).thenReturn(X);
|
when(loc.getBlockX()).thenReturn(X);
|
||||||
@ -130,11 +144,11 @@ public class CycleClickTest {
|
|||||||
when(island.getCenter()).thenReturn(loc);
|
when(island.getCenter()).thenReturn(loc);
|
||||||
when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE);
|
when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE);
|
||||||
// Island is not locked by default
|
// Island is not locked by default
|
||||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||||
// Island owner is user by default
|
// Island owner is user by default
|
||||||
when(island.getOwner()).thenReturn(uuid);
|
when(island.getOwner()).thenReturn(uuid);
|
||||||
|
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||||
|
|
||||||
// Common from to's
|
// Common from to's
|
||||||
Location outside = mock(Location.class);
|
Location outside = mock(Location.class);
|
||||||
@ -156,49 +170,48 @@ public class CycleClickTest {
|
|||||||
when(inside.getBlockZ()).thenReturn(Z);
|
when(inside.getBlockZ()).thenReturn(Z);
|
||||||
|
|
||||||
Optional<Island> opIsland = Optional.ofNullable(island);
|
Optional<Island> opIsland = Optional.ofNullable(island);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(inside))).thenReturn(opIsland);
|
when(im.getProtectedIslandAt(eq(inside))).thenReturn(opIsland);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(inside2))).thenReturn(opIsland);
|
when(im.getProtectedIslandAt(eq(inside2))).thenReturn(opIsland);
|
||||||
when(im.getProtectedIslandAt(Mockito.eq(outside))).thenReturn(Optional.empty());
|
when(im.getProtectedIslandAt(eq(outside))).thenReturn(Optional.empty());
|
||||||
when(im.getIslandAt(Mockito.any())).thenReturn(opIsland);
|
when(im.getIslandAt(any())).thenReturn(opIsland);
|
||||||
|
|
||||||
PanelItem panelItem = mock(PanelItem.class);
|
PanelItem panelItem = mock(PanelItem.class);
|
||||||
flag = mock(Flag.class);
|
when(flag.toPanelItem(any(), any(), eq(false))).thenReturn(panelItem);
|
||||||
when(flag.toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false))).thenReturn(panelItem);
|
|
||||||
when(panelItem.getItem()).thenReturn(mock(ItemStack.class));
|
when(panelItem.getItem()).thenReturn(mock(ItemStack.class));
|
||||||
FlagsManager fm = mock(FlagsManager.class);
|
FlagsManager fm = mock(FlagsManager.class);
|
||||||
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
when(fm.getFlag(anyString())).thenReturn(Optional.of(flag));
|
||||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||||
|
|
||||||
rm = mock(RanksManager.class);
|
// Ranks Manager
|
||||||
|
|
||||||
when(plugin.getRanksManager()).thenReturn(rm);
|
when(plugin.getRanksManager()).thenReturn(rm);
|
||||||
|
|
||||||
// Provide a current rank value - member
|
// Provide a current rank value - member
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
// Set up up and down ranks
|
// Set up up and down ranks
|
||||||
when(rm.getRankUpValue(Mockito.eq(RanksManager.VISITOR_RANK))).thenReturn(RanksManager.COOP_RANK);
|
when(rm.getRankUpValue(eq(RanksManager.VISITOR_RANK))).thenReturn(RanksManager.COOP_RANK);
|
||||||
when(rm.getRankUpValue(Mockito.eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.TRUSTED_RANK);
|
when(rm.getRankUpValue(eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.TRUSTED_RANK);
|
||||||
when(rm.getRankUpValue(Mockito.eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.MEMBER_RANK);
|
when(rm.getRankUpValue(eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
when(rm.getRankUpValue(Mockito.eq(RanksManager.MEMBER_RANK))).thenReturn(RanksManager.OWNER_RANK);
|
when(rm.getRankUpValue(eq(RanksManager.MEMBER_RANK))).thenReturn(RanksManager.OWNER_RANK);
|
||||||
when(rm.getRankDownValue(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn(RanksManager.MEMBER_RANK);
|
when(rm.getRankDownValue(eq(RanksManager.OWNER_RANK))).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
when(rm.getRankDownValue(Mockito.eq(RanksManager.MEMBER_RANK))).thenReturn(RanksManager.TRUSTED_RANK);
|
when(rm.getRankDownValue(eq(RanksManager.MEMBER_RANK))).thenReturn(RanksManager.TRUSTED_RANK);
|
||||||
when(rm.getRankDownValue(Mockito.eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.COOP_RANK);
|
when(rm.getRankDownValue(eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.COOP_RANK);
|
||||||
when(rm.getRankDownValue(Mockito.eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.VISITOR_RANK);
|
when(rm.getRankDownValue(eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
|
|
||||||
panel = mock(Panel.class);
|
// Panel
|
||||||
inv = mock(Inventory.class);
|
|
||||||
when(panel.getInventory()).thenReturn(inv);
|
when(panel.getInventory()).thenReturn(inv);
|
||||||
|
|
||||||
// IslandWorldManager
|
// IslandWorldManager
|
||||||
iwm = mock(IslandWorldManager.class);
|
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock");
|
||||||
|
|
||||||
// Util
|
// Util
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
when(Util.getWorld(any())).thenReturn(world);
|
||||||
|
|
||||||
|
// Event
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,15 +221,15 @@ public class CycleClickTest {
|
|||||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick("LOCK");
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.wrong-world"));
|
verify(user).sendMessage(eq("general.errors.wrong-world"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoPremission() {
|
public void testNoPremission() {
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
when(user.hasPermission(anyString())).thenReturn(false);
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick("LOCK");
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
|
||||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"), Mockito.eq("[permission]"), Mockito.eq("bskyblock.settings.LOCK"));
|
verify(user).sendMessage(eq("general.errors.no-permission"), eq("[permission]"), eq("bskyblock.settings.LOCK"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -232,37 +245,39 @@ public class CycleClickTest {
|
|||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Click left
|
// Click left
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.OWNER_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.OWNER_RANK));
|
||||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv).setItem(eq(SLOT), any());
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Owner should go to Visitor
|
// Clicking when Owner should go to Visitor
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.OWNER_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.VISITOR_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.VISITOR_RANK));
|
||||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag, times(2)).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv, times(2)).setItem(eq(SLOT), any());
|
||||||
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnLeftClickSetMinMax() {
|
public void testOnLeftClickSetMinMax() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.COOP_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Click left
|
// Click left
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.TRUSTED_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.TRUSTED_RANK));
|
||||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv).setItem(eq(SLOT), any());
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Member should go to Coop
|
// Clicking when Member should go to Coop
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.COOP_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.COOP_RANK));
|
||||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag, times(2)).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv, times(2)).setItem(eq(SLOT), any());
|
||||||
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -272,37 +287,39 @@ public class CycleClickTest {
|
|||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Right click - down rank to Trusted
|
// Right click - down rank to Trusted
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.TRUSTED_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.TRUSTED_RANK));
|
||||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv).setItem(eq(SLOT), any());
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Visitor should go to Owner
|
// Clicking when Visitor should go to Owner
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.OWNER_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.OWNER_RANK));
|
||||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag, times(2)).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv, times(2)).setItem(eq(SLOT), any());
|
||||||
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnRightClickMinMaxSet() {
|
public void testOnRightClickMinMaxSet() {
|
||||||
// Provide a current rank value - coop
|
// Provide a current rank value - coop
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.TRUSTED_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.TRUSTED_RANK);
|
||||||
final int SLOT = 5;
|
final int SLOT = 5;
|
||||||
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
CycleClick udc = new CycleClick("LOCK", RanksManager.COOP_RANK, RanksManager.MEMBER_RANK);
|
||||||
// Rank starts at member
|
// Rank starts at member
|
||||||
// Right click
|
// Right click
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.COOP_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.COOP_RANK));
|
||||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv).setItem(eq(SLOT), any());
|
||||||
// Check rollover
|
// Check rollover
|
||||||
// Clicking when Coop should go to Member
|
// Clicking when Coop should go to Member
|
||||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.COOP_RANK);
|
when(island.getFlag(any())).thenReturn(RanksManager.COOP_RANK);
|
||||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.MEMBER_RANK));
|
verify(island).setFlag(eq(flag), eq(RanksManager.MEMBER_RANK));
|
||||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
verify(flag, times(2)).toPanelItem(any(), any(), eq(false));
|
||||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
verify(inv, times(2)).setItem(eq(SLOT), any());
|
||||||
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -310,6 +327,7 @@ public class CycleClickTest {
|
|||||||
// Test all possible click types
|
// Test all possible click types
|
||||||
CycleClick udc = new CycleClick("LOCK");
|
CycleClick udc = new CycleClick("LOCK");
|
||||||
Arrays.asList(ClickType.values()).forEach(c -> assertTrue(udc.onClick(panel, user, c, 0)));
|
Arrays.asList(ClickType.values()).forEach(c -> assertTrue(udc.onClick(panel, user, c, 0)));
|
||||||
|
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -317,14 +335,14 @@ public class CycleClickTest {
|
|||||||
UUID u = UUID.randomUUID();
|
UUID u = UUID.randomUUID();
|
||||||
|
|
||||||
when(island.getOwner()).thenReturn(u);
|
when(island.getOwner()).thenReturn(u);
|
||||||
Mockito.verify(plugin, Mockito.never()).getRanksManager();
|
verify(plugin, Mockito.never()).getRanksManager();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullIsland() {
|
public void testNullIsland() {
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(null);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||||
Mockito.verify(plugin, Mockito.never()).getRanksManager();
|
verify(plugin, Mockito.never()).getRanksManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,25 @@ package world.bentobox.bentobox.api.flags.clicklisteners;
|
|||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
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.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
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;
|
||||||
@ -23,6 +28,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
|||||||
import org.powermock.reflect.Whitebox;
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagSettingChangeEvent;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
@ -34,17 +40,25 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
|||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({BentoBox.class, Util.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class })
|
||||||
public class IslandToggleClickTest {
|
public class IslandToggleClickTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
private IslandToggleClick listener;
|
private IslandToggleClick listener;
|
||||||
|
@Mock
|
||||||
private Panel panel;
|
private Panel panel;
|
||||||
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
|
@Mock
|
||||||
private Flag flag;
|
private Flag flag;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private Island island;
|
private Island island;
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Mock
|
||||||
|
private PluginManager pim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -59,12 +73,12 @@ public class IslandToggleClickTest {
|
|||||||
iwm = mock(IslandWorldManager.class);
|
iwm = mock(IslandWorldManager.class);
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock");
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
listener = new IslandToggleClick("test");
|
listener = new IslandToggleClick("test");
|
||||||
|
|
||||||
panel = mock(Panel.class);
|
// Panel
|
||||||
when(panel.getInventory()).thenReturn(mock(Inventory.class));
|
when(panel.getInventory()).thenReturn(mock(Inventory.class));
|
||||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||||
user = mock(User.class);
|
user = mock(User.class);
|
||||||
@ -75,28 +89,28 @@ public class IslandToggleClickTest {
|
|||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
when(user.getUniqueId()).thenReturn(uuid);
|
when(user.getUniqueId()).thenReturn(uuid);
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
when(Util.getWorld(any())).thenReturn(mock(World.class));
|
||||||
|
|
||||||
FlagsManager fm = mock(FlagsManager.class);
|
FlagsManager fm = mock(FlagsManager.class);
|
||||||
flag = mock(Flag.class);
|
when(flag.isSetForWorld(any())).thenReturn(false);
|
||||||
when(flag.isSetForWorld(Mockito.any())).thenReturn(false);
|
|
||||||
PanelItem item = mock(PanelItem.class);
|
PanelItem item = mock(PanelItem.class);
|
||||||
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
||||||
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user), Mockito.eq(false))).thenReturn(item);
|
when(flag.toPanelItem(any(), Mockito.eq(user), Mockito.eq(false))).thenReturn(item);
|
||||||
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
||||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||||
|
|
||||||
// Island Manager
|
// Island Manager
|
||||||
im = mock(IslandsManager.class);
|
|
||||||
island = mock(Island.class);
|
|
||||||
when(island.getOwner()).thenReturn(uuid);
|
when(island.getOwner()).thenReturn(uuid);
|
||||||
when(im.getIsland(Mockito.any(World.class), Mockito.any(User.class))).thenReturn(island);
|
when(im.getIsland(any(World.class), any(User.class))).thenReturn(island);
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Optional island
|
// Optional island
|
||||||
Optional<Island> opIsland = Optional.ofNullable(island);
|
Optional<Island> opIsland = Optional.ofNullable(island);
|
||||||
when(im.getIslandAt(Mockito.any())).thenReturn(opIsland);
|
when(im.getIslandAt(any())).thenReturn(opIsland);
|
||||||
|
|
||||||
|
// Event
|
||||||
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -104,28 +118,29 @@ public class IslandToggleClickTest {
|
|||||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(user).sendMessage("general.errors.wrong-world");
|
verify(user).sendMessage("general.errors.wrong-world");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.settings.test");
|
verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.settings.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClick() {
|
public void testOnClick() {
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(island).toggleFlag(flag);
|
verify(island).toggleFlag(flag);
|
||||||
|
verify(pim).callEvent(any(FlagSettingChangeEvent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClickNoIsland() {
|
public void testOnClickNoIsland() {
|
||||||
when(im.getIslandAt(Mockito.any())).thenReturn(Optional.empty());
|
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(null);
|
when(im.getIsland(any(), any(User.class))).thenReturn(null);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(island, Mockito.never()).toggleFlag(flag);
|
verify(island, never()).toggleFlag(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -137,7 +152,7 @@ public class IslandToggleClickTest {
|
|||||||
}
|
}
|
||||||
when(island.getOwner()).thenReturn(u);
|
when(island.getOwner()).thenReturn(u);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(island, Mockito.never()).toggleFlag(flag);
|
verify(island, never()).toggleFlag(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,18 @@ package world.bentobox.bentobox.api.flags.clicklisteners;
|
|||||||
import static org.mockito.Matchers.any;
|
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 static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -24,6 +27,7 @@ import org.powermock.reflect.Whitebox;
|
|||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.events.island.FlagWorldSettingChangeEvent;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
import world.bentobox.bentobox.api.flags.Flag;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
@ -33,7 +37,7 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
|
|||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({BentoBox.class, Util.class })
|
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class })
|
||||||
public class WorldToggleClickTest {
|
public class WorldToggleClickTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@ -46,6 +50,8 @@ public class WorldToggleClickTest {
|
|||||||
private Flag flag;
|
private Flag flag;
|
||||||
@Mock
|
@Mock
|
||||||
private GameModeAddon addon;
|
private GameModeAddon addon;
|
||||||
|
@Mock
|
||||||
|
private PluginManager pim;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -89,6 +95,10 @@ public class WorldToggleClickTest {
|
|||||||
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user), Mockito.eq(false))).thenReturn(item);
|
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user), Mockito.eq(false))).thenReturn(item);
|
||||||
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
||||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||||
|
|
||||||
|
// Event
|
||||||
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -96,24 +106,25 @@ public class WorldToggleClickTest {
|
|||||||
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
when(iwm.inWorld(any(World.class))).thenReturn(false);
|
||||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(user).sendMessage("general.errors.wrong-world");
|
verify(user).sendMessage("general.errors.wrong-world");
|
||||||
Mockito.verify(addon, Mockito.never()).saveWorldSettings();
|
verify(addon, Mockito.never()).saveWorldSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClickNoPermission() {
|
public void testOnClickNoPermission() {
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
when(user.hasPermission(Mockito.anyString())).thenReturn(false);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.admin.world.settings.test");
|
verify(user).sendMessage("general.errors.no-permission", "[permission]", "bskyblock.admin.world.settings.test");
|
||||||
Mockito.verify(addon, Mockito.never()).saveWorldSettings();
|
verify(addon, Mockito.never()).saveWorldSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClick() {
|
public void testOnClick() {
|
||||||
when(user.hasPermission(Mockito.anyString())).thenReturn(true);
|
when(user.hasPermission(Mockito.anyString())).thenReturn(true);
|
||||||
listener.onClick(panel, user, ClickType.LEFT, 0);
|
listener.onClick(panel, user, ClickType.LEFT, 0);
|
||||||
Mockito.verify(flag).setSetting(Mockito.any(), Mockito.eq(true));
|
verify(flag).setSetting(Mockito.any(), Mockito.eq(true));
|
||||||
Mockito.verify(panel).getInventory();
|
verify(panel).getInventory();
|
||||||
Mockito.verify(addon).saveWorldSettings();
|
verify(addon).saveWorldSettings();
|
||||||
|
verify(pim).callEvent(any(FlagWorldSettingChangeEvent.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user