mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Flag visibility (#617)
* Saves world settings to config.yml when they are changed mid-game. * Fixes and adds to tests * WIP: Added visibility settings for flags. Tests still need to be fixed and requires saving to config.yml. * Fixes tests * Completed changes. * Renames method to be hidden flags instead of visible settings GameModeAddons will need to adjust WorldSettings API based classes.
This commit is contained in:
parent
cab584d13d
commit
23491d0c4a
@ -126,9 +126,9 @@ public interface WorldSettings {
|
||||
int getSeaHeight();
|
||||
|
||||
/**
|
||||
* @return visible settings for player
|
||||
* @return hidden flag list
|
||||
*/
|
||||
List<String> getVisibleSettings();
|
||||
List<String> getHiddenFlags();
|
||||
|
||||
/**
|
||||
* @return the visitorBannedCommands
|
||||
|
@ -281,14 +281,20 @@ public class Flag implements Comparable<Flag> {
|
||||
* Converts a flag to a panel item. The content of the flag will change depending on who the user is and where they are.
|
||||
* @param plugin - plugin
|
||||
* @param user - user that will see this flag
|
||||
* @return - PanelItem for this flag
|
||||
* @param invisible - true if this flag is not visible to players
|
||||
* @return - PanelItem for this flag or null if item is inivisible to user
|
||||
*/
|
||||
public PanelItem toPanelItem(BentoBox plugin, User user) {
|
||||
public PanelItem toPanelItem(BentoBox plugin, User user, boolean invisible) {
|
||||
// Invisibility
|
||||
if (!user.isOp() && invisible) {
|
||||
return null;
|
||||
}
|
||||
// Start the flag conversion
|
||||
PanelItemBuilder pib = new PanelItemBuilder()
|
||||
.icon(new ItemStack(icon))
|
||||
.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(getNameReference())))
|
||||
.clickHandler(clickHandler);
|
||||
.clickHandler(clickHandler)
|
||||
.invisible(invisible);
|
||||
if (hasSubPanel()) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
|
||||
return pib.build();
|
||||
@ -483,4 +489,5 @@ public class Flag implements Comparable<Flag> {
|
||||
return new Flag(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
@ -66,12 +67,17 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||
}
|
||||
// Left clicking increases the rank required
|
||||
// Right clicking decreases the rank required
|
||||
// Shift Left Click toggles player visibility
|
||||
// Get the user's island
|
||||
island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
|
||||
if (island != null && (user.isOp() || user.getUniqueId().equals(island.getOwner()))) {
|
||||
changeOccurred = true;
|
||||
RanksManager rm = plugin.getRanksManager();
|
||||
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||
|
||||
// Flag visibility
|
||||
boolean invisible = false;
|
||||
// Rank
|
||||
int currentRank = island.getFlag(flag);
|
||||
if (click.equals(ClickType.LEFT)) {
|
||||
if (currentRank >= maxRank) {
|
||||
@ -79,7 +85,7 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||
} else {
|
||||
island.setFlag(flag, rm.getRankUpValue(currentRank));
|
||||
}
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F);
|
||||
} else if (click.equals(ClickType.RIGHT)) {
|
||||
if (currentRank <= minRank) {
|
||||
island.setFlag(flag, maxRank);
|
||||
@ -87,9 +93,20 @@ public class CycleClick implements PanelItem.ClickHandler {
|
||||
island.setFlag(flag, rm.getRankDownValue(currentRank));
|
||||
}
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
} else if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
||||
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
||||
invisible = true;
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).add(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||
} else {
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||
}
|
||||
// Save changes
|
||||
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
}
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||
});
|
||||
} else {
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
@ -29,7 +30,7 @@ public class IslandToggleClick implements ClickHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
public boolean onClick(Panel panel, User user, ClickType click, int slot) {
|
||||
// Get the world
|
||||
if (!plugin.getIWM().inWorld(user.getLocation())) {
|
||||
user.sendMessage("general.errors.wrong-world");
|
||||
@ -45,11 +46,27 @@ public class IslandToggleClick implements ClickHandler {
|
||||
Island island = plugin.getIslands().getIslandAt(user.getLocation()).orElse(plugin.getIslands().getIsland(user.getWorld(), user.getUniqueId()));
|
||||
if (island != null && (user.isOp() || user.getUniqueId().equals(island.getOwner()))) {
|
||||
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||
// Toggle flag
|
||||
island.toggleFlag(flag);
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
|
||||
// Visibility
|
||||
boolean invisible = false;
|
||||
if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
||||
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
||||
invisible = true;
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).add(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||
} else {
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||
}
|
||||
// Save changes
|
||||
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
} else {
|
||||
// Toggle flag
|
||||
island.toggleFlag(flag);
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
}
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||
});
|
||||
} else {
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
|
@ -29,7 +29,7 @@ public class WorldToggleClick implements ClickHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
public boolean onClick(Panel panel, User user, ClickType click, int slot) {
|
||||
// Get the world
|
||||
if (!plugin.getIWM().inWorld(user.getLocation())) {
|
||||
user.sendMessage("general.errors.wrong-world");
|
||||
@ -43,11 +43,27 @@ public class WorldToggleClick implements ClickHandler {
|
||||
}
|
||||
// Get flag
|
||||
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||
// Toggle flag
|
||||
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
// Visibility
|
||||
boolean invisible = false;
|
||||
if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
|
||||
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
|
||||
invisible = true;
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).add(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
|
||||
} else {
|
||||
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(flag.getID());
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
|
||||
}
|
||||
// Save changes
|
||||
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
} else {
|
||||
// Toggle flag
|
||||
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||
}
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user, invisible).getItem());
|
||||
|
||||
// Save world settings
|
||||
plugin.getIWM().getAddon(Util.getWorld(user.getWorld())).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
});
|
||||
|
@ -25,10 +25,11 @@ public class PanelItem {
|
||||
private boolean glow;
|
||||
private ItemMeta meta;
|
||||
private boolean playerHead;
|
||||
private boolean invisible;
|
||||
|
||||
public PanelItem(ItemStack icon, String name, List<String> description, boolean glow, ClickHandler clickHandler, boolean playerHead) {
|
||||
this.icon = icon;
|
||||
this.playerHead = playerHead;
|
||||
public PanelItem(PanelItemBuilder builtItem) {
|
||||
this.icon = builtItem.getIcon();
|
||||
this.playerHead = builtItem.isPlayerHead();
|
||||
// Get the meta
|
||||
meta = icon.getItemMeta();
|
||||
if (meta != null) {
|
||||
@ -41,13 +42,13 @@ public class PanelItem {
|
||||
icon.setItemMeta(meta);
|
||||
}
|
||||
|
||||
this.clickHandler = clickHandler;
|
||||
this.clickHandler = builtItem.getClickHandler();
|
||||
|
||||
// Create the final item
|
||||
setName(name);
|
||||
setDescription(description);
|
||||
setGlow(glow);
|
||||
|
||||
setName(builtItem.getName());
|
||||
setDescription(builtItem.getDescription());
|
||||
setGlow(builtItem.isGlow());
|
||||
setInvisible(builtItem.isInvisible());
|
||||
|
||||
}
|
||||
|
||||
@ -80,6 +81,25 @@ public class PanelItem {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInvisible() {
|
||||
return invisible;
|
||||
}
|
||||
|
||||
public void setInvisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
if (meta != null) {
|
||||
if (invisible) {
|
||||
meta.addEnchant(Enchantment.VANISHING_CURSE, 1, true);
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
icon.setItemMeta(meta);
|
||||
} else {
|
||||
meta.removeEnchant(Enchantment.VANISHING_CURSE);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
icon.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<ClickHandler> getClickHandler() {
|
||||
return Optional.ofNullable(clickHandler);
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ public class PanelBuilder {
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder item(PanelItem item) {
|
||||
// Do not add null items
|
||||
if (item == null) {
|
||||
return this;
|
||||
}
|
||||
return item(nextSlot(), item);
|
||||
}
|
||||
|
||||
@ -35,6 +39,10 @@ public class PanelBuilder {
|
||||
* @return PanelBuilder
|
||||
*/
|
||||
public PanelBuilder item(int slot, PanelItem item) {
|
||||
// Do not add null items
|
||||
if (item == null) {
|
||||
return this;
|
||||
}
|
||||
items.put(slot, item);
|
||||
return this;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class PanelItemBuilder {
|
||||
private boolean glow = false;
|
||||
private PanelItem.ClickHandler clickHandler;
|
||||
private boolean playerHead;
|
||||
private boolean invisible;
|
||||
|
||||
public PanelItemBuilder icon(Material icon) {
|
||||
this.icon = new ItemStack(icon);
|
||||
@ -86,13 +87,67 @@ public class PanelItemBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelItemBuilder invisible(boolean invisible) {
|
||||
this.invisible = invisible;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelItemBuilder clickHandler(ClickHandler clickHandler) {
|
||||
this.clickHandler = clickHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelItem build() {
|
||||
return new PanelItem(icon, name, description, glow, clickHandler, playerHead);
|
||||
return new PanelItem(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the icon
|
||||
*/
|
||||
public ItemStack getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the glow
|
||||
*/
|
||||
public boolean isGlow() {
|
||||
return glow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clickHandler
|
||||
*/
|
||||
public PanelItem.ClickHandler getClickHandler() {
|
||||
return clickHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the playerHead
|
||||
*/
|
||||
public boolean isPlayerHead() {
|
||||
return playerHead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the invisible
|
||||
*/
|
||||
public boolean isInvisible() {
|
||||
return invisible;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -604,8 +604,13 @@ public class IslandWorldManager {
|
||||
return gameModes.get(world).getWorldSettings().getDefaultIslandFlags();
|
||||
}
|
||||
|
||||
public List<String> getVisibleSettings(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getVisibleSettings();
|
||||
/**
|
||||
* Returns a list of flags that should NOT be visible to the player
|
||||
* @param world - world
|
||||
* @return list of hidden flags
|
||||
*/
|
||||
public List<String> getHiddenFlags(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getHiddenFlags();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +46,10 @@ public class SettingsPanel {
|
||||
.collect(Collectors.toList());
|
||||
// Remove any that are not for this game mode
|
||||
plugin.getIWM().getAddon(world).ifPresent(gm -> flags.removeIf(f -> !f.getGameModes().isEmpty() && !f.getGameModes().contains(gm)));
|
||||
|
||||
// Use paging
|
||||
flags.stream().skip(page * 43L).limit(page * 43L + 43L).forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user))));
|
||||
flags.stream().skip(page * 43L).limit(page * 43L + 43L)
|
||||
.forEach((f -> panelBuilder.item(f.toPanelItem(plugin, user, plugin.getIWM().getHiddenFlags(world).contains(f.getID())))));
|
||||
// Add forward and backward icons
|
||||
if (page > 0) {
|
||||
// Previous page icon
|
||||
|
@ -349,7 +349,7 @@ public class FlagTest {
|
||||
when(rm.getRank(Mockito.eq(RanksManager.OWNER_RANK))).thenReturn("Owner");
|
||||
|
||||
|
||||
PanelItem pi = f.toPanelItem(plugin, user);
|
||||
PanelItem pi = f.toPanelItem(plugin, user, false);
|
||||
|
||||
verify(user).getTranslation(Mockito.eq("protection.flags.flagID.name"));
|
||||
verify(user).getTranslation(Mockito.eq("protection.panel.flag-item.name-layout"), Mockito.anyVararg());
|
||||
|
@ -163,7 +163,7 @@ public class CycleClickTest {
|
||||
|
||||
PanelItem panelItem = mock(PanelItem.class);
|
||||
flag = mock(Flag.class);
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.any())).thenReturn(panelItem);
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false))).thenReturn(panelItem);
|
||||
when(panelItem.getItem()).thenReturn(mock(ItemStack.class));
|
||||
FlagsManager fm = mock(FlagsManager.class);
|
||||
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
||||
@ -233,14 +233,14 @@ public class CycleClickTest {
|
||||
// Click left
|
||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.OWNER_RANK));
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
// Check rollover
|
||||
// Clicking when Owner should go to Visitor
|
||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.VISITOR_RANK));
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
}
|
||||
|
||||
@ -254,14 +254,14 @@ public class CycleClickTest {
|
||||
// Click left
|
||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.TRUSTED_RANK));
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
// Check rollover
|
||||
// Clicking when Member should go to Coop
|
||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
assertTrue(udc.onClick(panel, user, ClickType.LEFT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.COOP_RANK));
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
}
|
||||
|
||||
@ -273,14 +273,14 @@ public class CycleClickTest {
|
||||
// Right click - down rank to Trusted
|
||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.TRUSTED_RANK));
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
// Check rollover
|
||||
// Clicking when Visitor should go to Owner
|
||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.VISITOR_RANK);
|
||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.OWNER_RANK));
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
}
|
||||
|
||||
@ -294,14 +294,14 @@ public class CycleClickTest {
|
||||
// Right click
|
||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.COOP_RANK));
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
// Check rollover
|
||||
// Clicking when Coop should go to Member
|
||||
when(island.getFlag(Mockito.any())).thenReturn(RanksManager.COOP_RANK);
|
||||
assertTrue(udc.onClick(panel, user, ClickType.RIGHT, SLOT));
|
||||
Mockito.verify(island).setFlag(Mockito.eq(flag), Mockito.eq(RanksManager.MEMBER_RANK));
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any());
|
||||
Mockito.verify(flag, Mockito.times(2)).toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false));
|
||||
Mockito.verify(inv, Mockito.times(2)).setItem(Mockito.eq(SLOT), Mockito.any());
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class IslandToggleClickTest {
|
||||
when(flag.isSetForWorld(Mockito.any())).thenReturn(false);
|
||||
PanelItem item = mock(PanelItem.class);
|
||||
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user))).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(plugin.getFlagsManager()).thenReturn(fm);
|
||||
|
||||
|
@ -36,7 +36,7 @@ import world.bentobox.bentobox.util.Util;
|
||||
@PrepareForTest({BentoBox.class, Util.class })
|
||||
public class WorldToggleClickTest {
|
||||
|
||||
@Mock
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
private WorldToggleClick listener;
|
||||
@Mock
|
||||
@ -45,7 +45,7 @@ public class WorldToggleClickTest {
|
||||
private User user;
|
||||
private Flag flag;
|
||||
@Mock
|
||||
private GameModeAddon addon;
|
||||
private GameModeAddon addon;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -61,20 +61,20 @@ public class WorldToggleClickTest {
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
||||
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
listener = new WorldToggleClick("test");
|
||||
|
||||
// Panel
|
||||
when(panel.getInventory()).thenReturn(mock(Inventory.class));
|
||||
|
||||
|
||||
// User
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
when(user.getWorld()).thenReturn(mock(World.class));
|
||||
when(user.getLocation()).thenReturn(mock(Location.class));
|
||||
when(user.getPlayer()).thenReturn(mock(Player.class));
|
||||
|
||||
|
||||
// Util
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||
@ -83,10 +83,10 @@ public class WorldToggleClickTest {
|
||||
FlagsManager fm = mock(FlagsManager.class);
|
||||
flag = mock(Flag.class);
|
||||
when(flag.isSetForWorld(Mockito.any())).thenReturn(false);
|
||||
|
||||
|
||||
PanelItem item = mock(PanelItem.class);
|
||||
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user))).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(plugin.getFlagsManager()).thenReturn(fm);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ public class PVPListenerTest {
|
||||
when(flag.isSetForWorld(Mockito.any())).thenReturn(false);
|
||||
PanelItem item = mock(PanelItem.class);
|
||||
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.any())).thenReturn(item);
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.any(), Mockito.eq(false))).thenReturn(item);
|
||||
when(fm.getFlag(Mockito.anyString())).thenReturn(Optional.of(flag));
|
||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||
|
||||
|
@ -53,7 +53,7 @@ import world.bentobox.bentobox.util.Util;
|
||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||
public class InvincibleVisitorsListenerTest {
|
||||
|
||||
@Mock
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
private InvincibleVisitorsListener listener;
|
||||
@Mock
|
||||
@ -83,7 +83,7 @@ public class InvincibleVisitorsListenerTest {
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(true);
|
||||
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
|
||||
Optional<GameModeAddon> optionalAddon = Optional.of(addon);
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(optionalAddon);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
listener = new InvincibleVisitorsListener();
|
||||
@ -107,7 +107,7 @@ public class InvincibleVisitorsListenerTest {
|
||||
when(flag.isSetForWorld(Mockito.any())).thenReturn(false);
|
||||
PanelItem item = mock(PanelItem.class);
|
||||
when(item.getItem()).thenReturn(mock(ItemStack.class));
|
||||
when(flag.toPanelItem(Mockito.any(), Mockito.eq(user))).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(plugin.getFlagsManager()).thenReturn(fm);
|
||||
|
||||
|
@ -618,13 +618,13 @@ public class IslandWorldManagerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandWorldManager#getVisibleSettings(org.bukkit.World)}.
|
||||
* Test method for {@link world.bentobox.bentobox.managers.IslandWorldManager#getHiddenFlags(org.bukkit.World)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetVisibleSettings() {
|
||||
List<String> list = new ArrayList<>();
|
||||
when(ws.getVisibleSettings()).thenReturn(list);
|
||||
assertEquals(list, iwm.getVisibleSettings(world));
|
||||
when(ws.getHiddenFlags()).thenReturn(list);
|
||||
assertEquals(list, iwm.getHiddenFlags(world));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user