* WIP - add GUI for teams.

* WIP teams GUI

* Moe WIP on team GUI

* Modified file to avoid an NPE.

* Minor refactor to prevent int to Integer warning.

* Use latest dependencies for tests to pass.

* Move to singleton pattern for RanksManager,

* Team GUI WIP

* Added support for kick, setowner, and leave.

* Added support for accepting and rejecting an invite.

* Fixed bugs with text and operations.

* WIP for team invites.

* Adds inviting to the GUI.

* Fix tests

* Fixed minor bugs reported by SonarCloud

* Up Minecraft version and paper to 1.20.4 in POM

* Added features based on Discord feedback.

1. added some lore to the invite button to explain the players shown are
from the game world
2. removed the team state in chat
3. added a search to the invite panel

* Added back button.

Refactored some code and templates.

* Fixed bugs with teams and uncoop untrust etc of Ops.

* Return to name search GUI if name not found.

* Added return to GUI for player search

* Use Path.of
This commit is contained in:
tastybento 2024-01-08 20:50:26 +09:00 committed by GitHub
parent 68da898e79
commit 0e0c502e1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
77 changed files with 1590 additions and 455 deletions

View File

@ -217,7 +217,7 @@
<version>3.11.1</version> <version>3.11.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- Spigot API --> <!-- Spigot API -->
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>

View File

@ -73,7 +73,6 @@ public class BentoBox extends JavaPlugin implements Listener {
private AddonsManager addonsManager; private AddonsManager addonsManager;
private FlagsManager flagsManager; private FlagsManager flagsManager;
private IslandWorldManager islandWorldManager; private IslandWorldManager islandWorldManager;
private RanksManager ranksManager;
private BlueprintsManager blueprintsManager; private BlueprintsManager blueprintsManager;
private HooksManager hooksManager; private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager; private PlaceholdersManager placeholdersManager;
@ -141,7 +140,6 @@ public class BentoBox extends JavaPlugin implements Listener {
return; return;
} }
islandsManager = new IslandsManager(this); islandsManager = new IslandsManager(this);
ranksManager = new RanksManager();
// Start head getter // Start head getter
headGetter = new HeadGetter(this); headGetter = new HeadGetter(this);
@ -429,9 +427,11 @@ public class BentoBox extends JavaPlugin implements Listener {
/** /**
* @return the ranksManager * @return the ranksManager
* @deprecated Just use {@code RanksManager.getInstance()}
*/ */
@Deprecated(since = "2.0.0")
public RanksManager getRanksManager() { public RanksManager getRanksManager() {
return ranksManager; return RanksManager.getInstance();
} }
/** /**
@ -466,6 +466,7 @@ public class BentoBox extends JavaPlugin implements Listener {
return false; return false;
} }
log("Saving default panels...");
if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "island_creation_panel.yml"))) { if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "island_creation_panel.yml"))) {
log("Saving default island_creation_panel..."); log("Saving default island_creation_panel...");
this.saveResource("panels/island_creation_panel.yml", false); this.saveResource("panels/island_creation_panel.yml", false);
@ -475,7 +476,6 @@ public class BentoBox extends JavaPlugin implements Listener {
log("Saving default language_panel..."); log("Saving default language_panel...");
this.saveResource("panels/language_panel.yml", false); this.saveResource("panels/language_panel.yml", false);
} }
return true; return true;
} }

View File

@ -83,10 +83,10 @@ public class AdminGetrankCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
// Get rank // Get rank
RanksManager rm = getPlugin().getRanksManager();
User target = User.getInstance(targetUUID); User target = User.getInstance(targetUUID);
int currentRank = island.getRank(target); int currentRank = island.getRank(target);
user.sendMessage("commands.admin.getrank.rank-is", TextVariables.RANK, user.getTranslation(rm.getRank(currentRank)), user.sendMessage("commands.admin.getrank.rank-is", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(currentRank)),
TextVariables.NAME, getPlayers().getName(island.getOwner())); TextVariables.NAME, getPlayers().getName(island.getOwner()));
return true; return true;
} }

View File

@ -24,7 +24,6 @@ public class AdminSetrankCommand extends CompositeCommand {
private int rankValue; private int rankValue;
private @Nullable UUID targetUUID; private @Nullable UUID targetUUID;
private @Nullable UUID ownerUUID; private @Nullable UUID ownerUUID;
private RanksManager rm;
public AdminSetrankCommand(CompositeCommand adminCommand) { public AdminSetrankCommand(CompositeCommand adminCommand) {
super(adminCommand, "setrank"); super(adminCommand, "setrank");
@ -36,7 +35,6 @@ public class AdminSetrankCommand extends CompositeCommand {
setOnlyPlayer(false); setOnlyPlayer(false);
setParametersHelp("commands.admin.setrank.parameters"); setParametersHelp("commands.admin.setrank.parameters");
setDescription("commands.admin.setrank.description"); setDescription("commands.admin.setrank.description");
rm = getPlugin().getRanksManager();
} }
@Override @Override
@ -53,7 +51,7 @@ public class AdminSetrankCommand extends CompositeCommand {
return false; return false;
} }
// Get rank // Get rank
rankValue = rm.getRanks().entrySet().stream() rankValue = RanksManager.getInstance().getRanks().entrySet().stream()
.filter(r -> user.getTranslation(r.getKey()).equalsIgnoreCase(args.get(1))).findFirst() .filter(r -> user.getTranslation(r.getKey()).equalsIgnoreCase(args.get(1))).findFirst()
.map(Map.Entry::getValue).orElse(-999); .map(Map.Entry::getValue).orElse(-999);
if (rankValue < RanksManager.BANNED_RANK) { if (rankValue < RanksManager.BANNED_RANK) {
@ -121,8 +119,8 @@ public class AdminSetrankCommand extends CompositeCommand {
ownerName = target.getName(); ownerName = target.getName();
} }
user.sendMessage("commands.admin.setrank.rank-set", user.sendMessage("commands.admin.setrank.rank-set",
"[from]", user.getTranslation(rm.getRank(currentRank)), "[from]", user.getTranslation(RanksManager.getInstance().getRank(currentRank)), "[to]",
"[to]", user.getTranslation(rm.getRank(rankValue)), user.getTranslation(RanksManager.getInstance().getRank(rankValue)),
TextVariables.NAME, ownerName); TextVariables.NAME, ownerName);
return true; return true;
} }
@ -136,7 +134,7 @@ public class AdminSetrankCommand extends CompositeCommand {
// Return the ranks // Return the ranks
if (args.size() == 3) { if (args.size() == 3) {
return Optional.of(getPlugin().getRanksManager().getRanks() return Optional.of(RanksManager.getInstance().getRanks()
.entrySet().stream() .entrySet().stream()
.filter(entry -> entry.getValue() > RanksManager.VISITOR_RANK) .filter(entry -> entry.getValue() > RanksManager.VISITOR_RANK)
.map(entry -> user.getTranslation(entry.getKey())).toList()); .map(entry -> user.getTranslation(entry.getKey())).toList());

View File

@ -175,7 +175,7 @@ public class AdminSettingsCommand extends CompositeCommand {
* @return true if rank is valid * @return true if rank is valid
*/ */
private boolean checkRank(User user, String string) { private boolean checkRank(User user, String string) {
for (Entry<String, Integer> en : getPlugin().getRanksManager().getRanks().entrySet()) { for (Entry<String, Integer> en : RanksManager.getInstance().getRanks().entrySet()) {
if (en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK if (en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK
&& string.equalsIgnoreCase(ChatColor.stripColor(user.getTranslation(en.getKey())))) { && string.equalsIgnoreCase(ChatColor.stripColor(user.getTranslation(en.getKey())))) {
// We have a winner // We have a winner
@ -277,8 +277,7 @@ public class AdminSettingsCommand extends CompositeCommand {
} else if (args.size() == 4) { } else if (args.size() == 4) {
// Get flag in previous argument // Get flag in previous argument
options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> switch (f.getType()) { options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> switch (f.getType()) {
case PROTECTION -> getPlugin().getRanksManager() case PROTECTION -> RanksManager.getInstance().getRanks().entrySet().stream()
.getRanks().entrySet().stream()
.filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK) .filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK)
.map(Entry::getKey) .map(Entry::getKey)
.map(user::getTranslation).toList(); .map(user::getTranslation).toList();

View File

@ -118,12 +118,10 @@ public class AdminTeleportCommand extends CompositeCommand {
private Location getSpot(World world) { private Location getSpot(World world) {
Island island = getIslands().getIsland(world, targetUUID); Island island = getIslands().getIsland(world, targetUUID);
if (island != null && island.getSpawnPoint(world.getEnvironment()) != null) { if (island == null) {
// Return the defined spawn point return null;
return island.getSpawnPoint(world.getEnvironment());
} }
// Return the default island protection center return island.getSpawnPoint(world.getEnvironment()) != null ? island.getSpawnPoint(world.getEnvironment()) : island.getProtectionCenter().toVector().toLocation(world);
return island.getProtectionCenter().toVector().toLocation(world);
} }
@Override @Override

View File

@ -17,6 +17,7 @@ import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
public class IslandBanCommand extends CompositeCommand { public class IslandBanCommand extends CompositeCommand {
@ -55,7 +56,7 @@ public class IslandBanCommand extends CompositeCommand {
int rank = island.getRank(user); int rank = island.getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player

View File

@ -8,6 +8,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
public class IslandBanlistCommand extends CompositeCommand { public class IslandBanlistCommand extends CompositeCommand {
@ -40,7 +41,8 @@ public class IslandBanlistCommand extends CompositeCommand {
island = getIslands().getIsland(getWorld(), user.getUniqueId()); island = getIslands().getIsland(getWorld(), user.getUniqueId());
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
return true; return true;

View File

@ -57,7 +57,7 @@ public class IslandDeletehomeCommand extends ConfirmableCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); TextVariables.RANK, user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }

View File

@ -16,6 +16,7 @@ import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
/** /**
@ -60,7 +61,7 @@ public class IslandExpelCommand extends CompositeCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player

View File

@ -65,7 +65,8 @@ public class IslandRenamehomeCommand extends ConfirmableCommand {
// check command permission // check command permission
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }

View File

@ -7,6 +7,7 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
/** /**
@ -41,7 +42,7 @@ public class IslandResetnameCommand extends CompositeCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); TextVariables.RANK, user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }

View File

@ -46,7 +46,8 @@ public class IslandSethomeCommand extends ConfirmableCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }

View File

@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
/** /**
@ -51,7 +52,8 @@ public class IslandSetnameCommand extends CompositeCommand {
// Check command rank. // Check command rank.
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }

View File

@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
/** /**
@ -54,7 +55,8 @@ public class IslandUnbanCommand extends CompositeCommand {
Island island = getIslands().getIsland(getWorld(), user); Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player

View File

@ -0,0 +1,53 @@
package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
/**
* Invites a player by search
* @author tastybento
*
*/
public class InviteNamePrompt extends StringPrompt {
@NonNull
private final User user;
@NonNull
private final IslandTeamInviteCommand itic;
public InviteNamePrompt(@NonNull User user, IslandTeamInviteCommand islandTeamInviteCommand) {
this.user = user;
this.itic = islandTeamInviteCommand;
}
@Override
@NonNull
public String getPromptText(@NonNull ConversationContext context) {
return user.getTranslation("commands.island.team.invite.gui.enter-name");
}
@Override
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
// TODO remove this and pass the options back to the GUI
if (itic.canExecute(user, itic.getLabel(), List.of(input))) {
if (itic.execute(user, itic.getLabel(), List.of(input))) {
return Prompt.END_OF_CONVERSATION;
}
}
// Set the search item to what was entered
itic.setSearchName(input);
// Return to the GUI but give a second for the error to show
// TODO: return the failed input and display the options in the GUI.
Bukkit.getScheduler().runTaskLater(BentoBox.getInstance(), () -> itic.build(user), 20L);
return Prompt.END_OF_CONVERSATION;
}
}

View File

@ -1,15 +1,24 @@
package world.bentobox.bentobox.api.commands.island.team; package world.bentobox.bentobox.api.commands.island.team;
import java.io.File;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
@ -17,6 +26,15 @@ import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; import world.bentobox.bentobox.api.events.team.TeamEvent;
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.PanelItem;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
import world.bentobox.bentobox.api.panels.TemplatedPanel.ItemSlot;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecords;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
@ -24,12 +42,48 @@ import world.bentobox.bentobox.util.Util;
public class IslandTeamCommand extends CompositeCommand { public class IslandTeamCommand extends CompositeCommand {
/**
* List of ranks that we will loop through in order
*/
private static final List<Integer> RANKS = List.of(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK,
RanksManager.MEMBER_RANK, RanksManager.TRUSTED_RANK, RanksManager.COOP_RANK);
/** /**
* Invited list. Key is the invited party, value is the invite. * Invited list. Key is the invited party, value is the invite.
* @since 1.8.0 * @since 1.8.0
*/ */
private final Map<UUID, Invite> inviteMap; private final Map<UUID, Invite> inviteMap;
private User user;
private Island island;
private int rank = RanksManager.OWNER_RANK;
private IslandTeamKickCommand kickCommand;
private IslandTeamLeaveCommand leaveCommand;
private IslandTeamSetownerCommand setOwnerCommand;
private IslandTeamUncoopCommand uncoopCommand;
private IslandTeamUntrustCommand unTrustCommand;
private @Nullable TemplateItem border;
private @Nullable TemplateItem background;
private IslandTeamInviteAcceptCommand acceptCommand;
private IslandTeamInviteRejectCommand rejectCommand;
private IslandTeamInviteCommand inviteCommand;
private IslandTeamCoopCommand coopCommand;
private IslandTeamTrustCommand trustCommand;
public IslandTeamCommand(CompositeCommand parent) { public IslandTeamCommand(CompositeCommand parent) {
super(parent, "team"); super(parent, "team");
inviteMap = new HashMap<>(); inviteMap = new HashMap<>();
@ -41,29 +95,40 @@ public class IslandTeamCommand extends CompositeCommand {
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.description"); setDescription("commands.island.team.description");
// Register commands // Register commands
new IslandTeamInviteCommand(this); inviteCommand = new IslandTeamInviteCommand(this);
new IslandTeamLeaveCommand(this); leaveCommand = new IslandTeamLeaveCommand(this);
new IslandTeamSetownerCommand(this); setOwnerCommand = new IslandTeamSetownerCommand(this);
new IslandTeamKickCommand(this); kickCommand = new IslandTeamKickCommand(this);
new IslandTeamInviteAcceptCommand(this); acceptCommand = new IslandTeamInviteAcceptCommand(this);
new IslandTeamInviteRejectCommand(this); rejectCommand = new IslandTeamInviteRejectCommand(this);
if (getPlugin().getRanksManager().rankExists(RanksManager.COOP_RANK_REF)) { if (RanksManager.getInstance().rankExists(RanksManager.COOP_RANK_REF)) {
new IslandTeamCoopCommand(this); coopCommand = new IslandTeamCoopCommand(this);
new IslandTeamUncoopCommand(this); uncoopCommand = new IslandTeamUncoopCommand(this);
} }
if (getPlugin().getRanksManager().rankExists(RanksManager.TRUSTED_RANK_REF)) { if (RanksManager.getInstance().rankExists(RanksManager.TRUSTED_RANK_REF)) {
new IslandTeamTrustCommand(this); trustCommand = new IslandTeamTrustCommand(this);
new IslandTeamUntrustCommand(this); unTrustCommand = new IslandTeamUntrustCommand(this);
} }
new IslandTeamPromoteCommand(this, "promote"); new IslandTeamPromoteCommand(this, "promote");
new IslandTeamPromoteCommand(this, "demote"); new IslandTeamPromoteCommand(this, "demote");
// Panels
if (!new File(getPlugin().getDataFolder() + File.separator + "panels", "team_panel.yml").exists()) {
getPlugin().saveResource("panels/team_panel.yml", false);
}
} }
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean canExecute(User user, String label, List<String> args) {
this.user = user;
// Player issuing the command must have an island // Player issuing the command must have an island
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()); island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island == null) { if (island == null) {
if (isInvited(user.getUniqueId())) {
// Player has an invite, so show the invite
build();
return true;
}
user.sendMessage("general.errors.no-island"); user.sendMessage("general.errors.no-island");
return false; return false;
} }
@ -84,86 +149,499 @@ public class IslandTeamCommand extends CompositeCommand {
user.sendMessage("commands.island.team.invite.errors.island-is-full"); user.sendMessage("commands.island.team.invite.errors.island-is-full");
} }
} }
// Show members of island
showMembers(island, user);
return true; return true;
} }
private void showMembers(Island island, User user) { @Override
public boolean execute(User user, String label, List<String> args) {
// Show the panel
build();
return true;
}
/**
* This method builds this GUI.
*/
void build() {
// Start building panel.
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
panelBuilder.user(user);
panelBuilder.world(user.getWorld());
panelBuilder.template("team_panel", new File(getPlugin().getDataFolder(), "panels"));
panelBuilder.parameters("[name]", user.getName(), "[display_name]", user.getDisplayName());
panelBuilder.registerTypeBuilder("STATUS", this::createStatusButton);
panelBuilder.registerTypeBuilder("MEMBER", this::createMemberButton);
panelBuilder.registerTypeBuilder("INVITED", this::createInvitedButton);
panelBuilder.registerTypeBuilder("RANK", this::createRankButton);
panelBuilder.registerTypeBuilder("INVITE", this::createInviteButton);
border = panelBuilder.getPanelTemplate().border();
background = panelBuilder.getPanelTemplate().background();
// Register unknown type builder.
panelBuilder.build();
}
private PanelItem createInviteButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
if (island == null || !user.hasPermission(this.inviteCommand.getPermission())
|| island.getRank(user) < island.getRankCommand(this.getLabel() + " invite")) {
return this.getBlankBorder();
}
PanelItemBuilder builder = new PanelItemBuilder();
builder.icon(Material.PLAYER_HEAD);
builder.name(user.getTranslation("commands.island.team.gui.buttons.invite.name"));
builder.description(user.getTranslation("commands.island.team.gui.buttons.invite.description"));
builder.clickHandler((panel, user, clickType, clickSlot) -> {
if (clickType.equals(ClickType.LEFT)) {
user.closeInventory();
this.inviteCommand.build(user);
}
return true;
});
return builder.build();
}
private PanelItem createRankButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
// If there is no island, the do not show this icon
if (island == null) {
return this.getBlankBorder();
}
PanelItemBuilder builder = new PanelItemBuilder();
builder.name(user.getTranslation("commands.island.team.gui.buttons.rank-filter.name"));
builder.icon(Material.AMETHYST_SHARD);
// Create description
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
if (rank == RanksManager.OWNER_RANK && score > RanksManager.VISITOR_RANK
&& score <= RanksManager.OWNER_RANK) {
builder.description(user.getTranslation("protection.panel.flag-item.allowed-rank")
+ user.getTranslation(reference));
} else if (score > RanksManager.VISITOR_RANK && score < rank) {
builder.description(user.getTranslation("protection.panel.flag-item.blocked-rank")
+ user.getTranslation(reference));
} else if (score <= RanksManager.OWNER_RANK && score > rank) {
builder.description(user.getTranslation("protection.panel.flag-item.blocked-rank")
+ user.getTranslation(reference));
} else if (score == rank) {
builder.description(user.getTranslation("protection.panel.flag-item.allowed-rank")
+ user.getTranslation(reference));
}
});
builder.description(user.getTranslation("commands.island.team.gui.buttons.rank-filter.description"));
builder.clickHandler((panel, user, clickType, clickSlot) -> {
if (clickType.equals(ClickType.LEFT)) {
rank = RanksManager.getInstance().getRankDownValue(rank);
if (rank <= RanksManager.VISITOR_RANK) {
rank = RanksManager.OWNER_RANK;
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
} else {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
}
}
if (clickType.equals(ClickType.RIGHT)) {
rank = RanksManager.getInstance().getRankUpValue(rank);
if (rank >= RanksManager.OWNER_RANK) {
rank = RanksManager.getInstance().getRankUpValue(RanksManager.VISITOR_RANK);
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
} else {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
}
}
// Update panel after click
build();
return true;
});
return builder.build();
}
/**
* Create invited button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createInvitedButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
PanelItemBuilder builder = new PanelItemBuilder();
if (isInvited(user.getUniqueId()) && user.hasPermission(this.acceptCommand.getPermission())) {
Invite invite = getInvite(user.getUniqueId());
User inviter = User.getInstance(invite.getInviter());
String name = inviter.getName();
builder.icon(inviter.getName());
builder.name(user.getTranslation("commands.island.team.gui.buttons.invitation"));
builder.description(switch (invite.getType()) {
case COOP ->
List.of(user.getTranslation("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME,
name));
case TRUST ->
List.of(user.getTranslation("commands.island.team.invite.name-has-invited-you.trust",
TextVariables.NAME, name));
default ->
List.of(user.getTranslation("commands.island.team.invite.name-has-invited-you", TextVariables.NAME,
name), user.getTranslation("commands.island.team.invite.accept.confirmation"));
});
// Add all the tool tips
builder.description(template.actions().stream()
.map(ar -> user.getTranslation("commands.island.team.gui.tips." + ar.clickType().name() + ".name")
+ " "
+ user.getTranslation(ar.tooltip()))
.toList());
builder.clickHandler((panel, user, clickType, clickSlot) -> {
if (clickType.equals(ClickType.SHIFT_LEFT) && user.hasPermission(this.acceptCommand.getPermission())) {
getPlugin().log("Invite accepted: " + user.getName() + " accepted " + invite.getType()
+ " invite to island at " + island.getCenter());
// Accept
switch (invite.getType()) {
case COOP -> this.acceptCommand.acceptCoopInvite(user, invite);
case TRUST -> this.acceptCommand.acceptTrustInvite(user, invite);
default -> this.acceptCommand.acceptTeamInvite(user, invite);
}
user.closeInventory();
}
if (clickType.equals(ClickType.SHIFT_RIGHT) && user.hasPermission(this.rejectCommand.getPermission())) {
// Reject
getPlugin().log("Invite rejected: " + user.getName() + " rejected " + invite.getType()
+ " invite.");
this.rejectCommand.execute(user, "", List.of());
user.closeInventory();
}
return true;
});
} else {
return this.getBlankBorder();
}
return builder.build();
}
/**
* Create status button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createStatusButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
PanelItemBuilder builder = new PanelItemBuilder();
// Player issuing the command must have an island
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island == null) {
return getBlankBorder();
}
return builder.icon(user.getName()).name(user.getTranslation("commands.island.team.gui.buttons.status.name"))
.description(showMembers()).build();
}
private PanelItem getBlankBorder() {
return new PanelItemBuilder().icon(Objects.requireNonNullElse(border.icon(), new ItemStack(Material.BARRIER)))
.name((Objects.requireNonNullElse(border.title(), ""))).build();
}
private PanelItem getBlankBackground() {
return new PanelItemBuilder()
.icon(Objects.requireNonNullElse(background.icon(), new ItemStack(Material.BARRIER)))
.name((Objects.requireNonNullElse(background.title(), ""))).build();
}
/**
* Create member button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createMemberButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
// Player issuing the command must have an island
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island == null) {
return this.getBlankBackground();
}
return switch (rank) {
case RanksManager.OWNER_RANK -> ownerView(template, slot);
default -> getMemberButton(rank, slot.slot(), template.actions());
};
}
/**
* The owner view shows all the ranks, in order
* @param template template reference
* @param slot slot to show
* @return panel item
*/
private PanelItem ownerView(ItemTemplateRecord template, ItemSlot slot) {
if (slot.slot() == 0 && island.getOwner() != null) {
// Owner
PanelItem item = getMemberButton(RanksManager.OWNER_RANK, 1, template.actions());
if (item != null) {
return item;
}
}
long subOwnerCount = island.getMemberSet(RanksManager.SUB_OWNER_RANK, false).stream().count();
long memberCount = island.getMemberSet(RanksManager.MEMBER_RANK, false).stream().count();
long coopCount = island.getMemberSet(RanksManager.COOP_RANK, false).stream().count();
long trustedCount = island.getMemberSet(RanksManager.TRUSTED_RANK, false).stream().count();
if (slot.slot() > 0 && slot.slot() < subOwnerCount + 1) {
// Show sub owners
PanelItem item = getMemberButton(RanksManager.SUB_OWNER_RANK, slot.slot(), template.actions());
if (item != null) {
return item;
}
}
if (slot.slot() > subOwnerCount && slot.slot() < subOwnerCount + memberCount + 1) {
// Show members
PanelItem item = getMemberButton(RanksManager.MEMBER_RANK, slot.slot(), template.actions());
if (item != null) {
return item;
}
}
if (slot.slot() > subOwnerCount + memberCount && slot.slot() < subOwnerCount + memberCount + trustedCount + 1) {
// Show trusted
PanelItem item = getMemberButton(RanksManager.TRUSTED_RANK, slot.slot(), template.actions());
if (item != null) {
return item;
}
}
if (slot.slot() > subOwnerCount + memberCount + trustedCount
&& slot.slot() < subOwnerCount + memberCount + trustedCount + coopCount + 1) {
// Show coops
return getMemberButton(RanksManager.COOP_RANK, slot.slot(), template.actions());
}
return this.getBlankBackground();
}
/**
* Shows a member's head. The clicks available will depend on who is viewing.
* @param targetRank - the rank to show
* @param slot - the slot number
* @param actions - actions that need to apply to this member button as provided by the template
* @return panel item
*/
private PanelItem getMemberButton(int targetRank, int slot, List<ActionRecords> actions) {
if (slot == 0 && island.getOwner() != null) {
// Owner
return getMemberButton(RanksManager.OWNER_RANK, 1, actions);
}
String ref = RanksManager.getInstance().getRank(targetRank);
Optional<User> opMember = island.getMemberSet(targetRank, false).stream().sorted().skip(slot - 1L).limit(1L)
.map(User::getInstance).findFirst();
if (opMember.isEmpty()) {
return this.getBlankBackground();
}
User member = opMember.get();
// Make button description depending on viewer
List<String> desc = new ArrayList<>();
int userRank = Objects.requireNonNull(island).getRank(user);
// Add the tooltip for kicking
if (user.hasPermission(this.kickCommand.getPermission())
&& userRank >= island.getRankCommand(this.getLabel() + " kick") && !user.equals(member)) {
actions.stream().filter(ar -> ar.actionType().equalsIgnoreCase("kick"))
.map(ar -> user.getTranslation("commands.island.team.gui.tips." + ar.clickType().name() + ".name")
+ " " + user.getTranslation(ar.tooltip()))
.findFirst().ifPresent(desc::add);
}
// Set Owner
if (user.hasPermission(this.setOwnerCommand.getPermission()) && !user.equals(member)
&& userRank >= RanksManager.OWNER_RANK && targetRank >= RanksManager.MEMBER_RANK) {
// Add the tooltip for setowner
actions.stream().filter(ar -> ar.actionType().equalsIgnoreCase("setowner"))
.map(ar -> user.getTranslation("commands.island.team.gui.tips." + ar.clickType().name() + ".name")
+ " " + user.getTranslation(ar.tooltip()))
.findFirst().ifPresent(desc::add);
}
// Leave
if (user.hasPermission(this.leaveCommand.getPermission()) && user.equals(member)
&& userRank < RanksManager.OWNER_RANK) {
// Add the tooltip for leave
actions.stream().filter(ar -> ar.actionType().equalsIgnoreCase("leave"))
.map(ar -> user.getTranslation("commands.island.team.gui.tips." + ar.clickType().name() + ".name")
+ " " + user.getTranslation(ar.tooltip()))
.findFirst().ifPresent(desc::add);
}
if (member.isOnline()) {
desc.add(0, user.getTranslation(ref));
return new PanelItemBuilder().icon(member.getName()).name(member.getDisplayName()).description(desc)
.clickHandler(
(panel, user, clickType, i) -> clickListener(panel, user, clickType, i, member, actions))
.build();
} else {
// Offline player
desc.add(0, user.getTranslation(ref));
return new PanelItemBuilder().icon(member.getName())
.name(offlinePlayerStatus(user, Bukkit.getOfflinePlayer(member.getUniqueId()))).description(desc)
.clickHandler(
(panel, user, clickType, i) -> clickListener(panel, user, clickType, i, member, actions))
.build();
}
}
private boolean clickListener(Panel panel, User clickingUser, ClickType clickType, int i, User target,
List<ActionRecords> actions) {
int rank = Objects.requireNonNull(island).getRank(clickingUser);
for (ItemTemplateRecord.ActionRecords action : actions) {
if (clickType.equals(action.clickType())) {
switch (action.actionType().toUpperCase(Locale.ENGLISH)) {
case "KICK" -> {
// Kick the player, or uncoop, or untrust
if (clickingUser.hasPermission(this.kickCommand.getPermission()) && !target.equals(clickingUser)
&& rank >= island.getRankCommand(this.getLabel() + " kick")) {
getPlugin().log("Kick: " + clickingUser.getName() + " kicked " + target.getName()
+ " from island at " + island.getCenter());
clickingUser.closeInventory();
if (removePlayer(clickingUser, target)) {
clickingUser.getPlayer().playSound(clickingUser.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F,
1F);
getPlugin().log("Kick: success");
} else {
getPlugin().log("Kick: failed");
}
}
}
case "SETOWNER" -> {
// Make the player the leader of the island
if (clickingUser.hasPermission(this.setOwnerCommand.getPermission()) && !target.equals(clickingUser)
&& clickingUser.getUniqueId().equals(island.getOwner())) {
getPlugin().log("Set Owner: " + clickingUser.getName() + " trying to make " + target.getName()
+ " owner of island at " + island.getCenter());
clickingUser.closeInventory();
if (this.setOwnerCommand.setOwner(clickingUser, target.getUniqueId())) {
getPlugin().log("Set Owner: success");
} else {
getPlugin().log("Set Owner: failed");
}
}
}
case "LEAVE" -> {
if (clickingUser.hasPermission(this.leaveCommand.getPermission()) && target.equals(clickingUser)
&& !clickingUser.getUniqueId().equals(island.getOwner())) {
getPlugin().log("Leave: " + clickingUser.getName() + " trying to leave island at "
+ island.getCenter());
clickingUser.closeInventory();
if (leaveCommand.leave(clickingUser)) {
getPlugin().log("Leave: success");
} else {
getPlugin().log("Leave: failed");
}
}
}
}
}
}
return true;
}
private boolean removePlayer(User clicker, User member) {
// If member then kick, if coop, uncoop, if trusted, then untrust
return switch (island.getRank(member)) {
case RanksManager.COOP_RANK -> this.uncoopCommand.unCoopCmd(user, member.getUniqueId());
case RanksManager.TRUSTED_RANK -> this.unTrustCommand.unTrustCmd(user, member.getUniqueId());
default -> {
if (kickCommand.canExecute(user, kickCommand.getLabel(), List.of(member.getName()))) {
yield kickCommand.execute(user, kickCommand.getLabel(), List.of(member.getName()));
} else {
yield false;
}
}
};
}
private List<String> showMembers() {
List<String> message = new ArrayList<>();
// Gather online members // Gather online members
long count = island.getMemberSet(RanksManager.MEMBER_RANK).stream() long onlineMemberCount = island.getMemberSet(RanksManager.MEMBER_RANK).stream()
.filter(uuid -> Util.getOnlinePlayerList(user).contains(Bukkit.getOfflinePlayer(uuid).getName())) .filter(uuid -> Util.getOnlinePlayerList(user).contains(Bukkit.getOfflinePlayer(uuid).getName()))
.count(); .count();
// List of ranks that we will loop through
Integer[] ranks = new Integer[] { RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK,
RanksManager.MEMBER_RANK, RanksManager.TRUSTED_RANK, RanksManager.COOP_RANK };
// Show header: // Show header:
user.sendMessage("commands.island.team.info.header", "[max]", message.add(user.getTranslation("commands.island.team.info.header", "[max]",
String.valueOf(getIslands().getMaxMembers(island, RanksManager.MEMBER_RANK)), "[total]", String.valueOf(getIslands().getMaxMembers(island, RanksManager.MEMBER_RANK)), "[total]",
String.valueOf(island.getMemberSet().size()), "[online]", String.valueOf(count)); String.valueOf(island.getMemberSet().size()), "[online]", String.valueOf(onlineMemberCount)));
// We now need to get all online "members" of the island - incl. Trusted and coop // We now need to get all online "members" of the island - incl. Trusted and coop
List<UUID> onlineMembers = island.getMemberSet(RanksManager.COOP_RANK).stream() List<UUID> onlineMembers = island.getMemberSet(RanksManager.COOP_RANK).stream()
.filter(uuid -> Util.getOnlinePlayerList(user).contains(Bukkit.getOfflinePlayer(uuid).getName())) .filter(uuid -> Util.getOnlinePlayerList(user).contains(Bukkit.getOfflinePlayer(uuid).getName()))
.toList(); .toList();
for (int rank : ranks) { for (int rank : RANKS) {
Set<UUID> players = island.getMemberSet(rank, false); Set<UUID> players = island.getMemberSet(rank, false);
if (!players.isEmpty()) { if (!players.isEmpty()) {
if (rank == RanksManager.OWNER_RANK) { if (rank == RanksManager.OWNER_RANK) {
// Slightly special handling for the owner rank // Slightly special handling for the owner rank
user.sendMessage("commands.island.team.info.rank-layout.owner", TextVariables.RANK, message.add(user.getTranslation("commands.island.team.info.rank-layout.owner", TextVariables.RANK,
user.getTranslation(RanksManager.OWNER_RANK_REF)); user.getTranslation(RanksManager.OWNER_RANK_REF)));
} else { } else {
user.sendMessage("commands.island.team.info.rank-layout.generic", TextVariables.RANK, message.add(user.getTranslation("commands.island.team.info.rank-layout.generic", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank)), TextVariables.NUMBER, user.getTranslation(RanksManager.getInstance().getRank(rank)), TextVariables.NUMBER,
String.valueOf(island.getMemberSet(rank, false).size())); String.valueOf(island.getMemberSet(rank, false).size())));
} }
displayOnOffline(user, rank, island, onlineMembers); message.addAll(displayOnOffline(user, rank, island, onlineMembers));
} }
} }
return message;
}
private List<String> displayOnOffline(User user, int rank, Island island, List<UUID> onlineMembers) {
List<String> message = new ArrayList<>();
for (UUID member : island.getMemberSet(rank, false)) {
message.add(getMemberStatus(user, member, onlineMembers.contains(member)));
}
return message;
}
private String getMemberStatus(User user2, UUID member, boolean online) {
OfflinePlayer offlineMember = Bukkit.getOfflinePlayer(member);
if (online) {
return user.getTranslation("commands.island.team.info.member-layout.online", TextVariables.NAME,
offlineMember.getName());
} else {
return offlinePlayerStatus(user, offlineMember);
}
} }
private void displayOnOffline(User user, int rank, Island island, List<UUID> onlineMembers) { /**
for (UUID member : island.getMemberSet(rank, false)) { * Creates text to describe the status of the player
OfflinePlayer offlineMember = Bukkit.getOfflinePlayer(member); * @param user2 user asking to see the status
if (onlineMembers.contains(member)) { * @param offlineMember member of the team
// the player is online * @return string
user.sendMessage("commands.island.team.info.member-layout.online", TextVariables.NAME, */
offlineMember.getName()); private String offlinePlayerStatus(User user2, OfflinePlayer offlineMember) {
} else { String lastSeen = lastSeen(offlineMember);
// A bit of handling for the last joined date if (island.getMemberSet(RanksManager.MEMBER_RANK, true).contains(offlineMember.getUniqueId())) {
Instant lastJoined = Instant.ofEpochMilli(offlineMember.getLastPlayed()); return user.getTranslation("commands.island.team.info.member-layout.offline", TextVariables.NAME,
Instant now = Instant.now(); offlineMember.getName(), "[last_seen]", lastSeen);
} else {
Duration duration = Duration.between(lastJoined, now); // This will prevent anyone that is trusted or below to not have a last-seen status
String lastSeen; return user.getTranslation("commands.island.team.info.member-layout.offline-not-last-seen",
final String reference = "commands.island.team.info.last-seen.layout"; TextVariables.NAME, offlineMember.getName());
if (duration.toMinutes() < 60L) {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER,
String.valueOf(duration.toMinutes()), TextVariables.UNIT,
user.getTranslation("commands.island.team.info.last-seen.minutes"));
} else if (duration.toHours() < 24L) {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER, String.valueOf(duration.toHours()),
TextVariables.UNIT, user.getTranslation("commands.island.team.info.last-seen.hours"));
} else {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER, String.valueOf(duration.toDays()),
TextVariables.UNIT, user.getTranslation("commands.island.team.info.last-seen.days"));
}
if (island.getMemberSet(RanksManager.MEMBER_RANK, true).contains(member)) {
user.sendMessage("commands.island.team.info.member-layout.offline", TextVariables.NAME,
offlineMember.getName(), "[last_seen]", lastSeen);
} else {
// This will prevent anyone that is trusted or below to not have a last-seen status
user.sendMessage("commands.island.team.info.member-layout.offline-not-last-seen",
TextVariables.NAME, offlineMember.getName());
}
}
} }
}
private String lastSeen(OfflinePlayer offlineMember) {
// A bit of handling for the last joined date
Instant lastJoined = Instant.ofEpochMilli(offlineMember.getLastPlayed());
Instant now = Instant.now();
Duration duration = Duration.between(lastJoined, now);
String lastSeen;
final String reference = "commands.island.team.info.last-seen.layout";
if (duration.toMinutes() < 60L) {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER, String.valueOf(duration.toMinutes()),
TextVariables.UNIT, user.getTranslation("commands.island.team.info.last-seen.minutes"));
} else if (duration.toHours() < 24L) {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER, String.valueOf(duration.toHours()),
TextVariables.UNIT, user.getTranslation("commands.island.team.info.last-seen.hours"));
} else {
lastSeen = user.getTranslation(reference, TextVariables.NUMBER, String.valueOf(duration.toDays()),
TextVariables.UNIT, user.getTranslation("commands.island.team.info.last-seen.days"));
}
return lastSeen;
} }
private boolean fireEvent(User user, Island island) { private boolean fireEvent(User user, Island island) {
@ -223,4 +701,18 @@ public class IslandTeamCommand extends CompositeCommand {
public void removeInvite(@NonNull UUID invitee) { public void removeInvite(@NonNull UUID invitee) {
inviteMap.remove(invitee); inviteMap.remove(invitee);
} }
/**
* @return the coopCommand
*/
protected IslandTeamCoopCommand getCoopCommand() {
return coopCommand;
}
/**
* @return the trustCommand
*/
protected IslandTeamTrustCommand getTrustCommand() {
return trustCommand;
}
} }

View File

@ -58,7 +58,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player

View File

@ -23,7 +23,6 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
private static final String INVALID_INVITE = "commands.island.team.invite.errors.invalid-invite"; private static final String INVALID_INVITE = "commands.island.team.invite.errors.invalid-invite";
private final IslandTeamCommand itc; private final IslandTeamCommand itc;
private UUID playerUUID;
public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) { public IslandTeamInviteAcceptCommand(IslandTeamCommand islandTeamCommand) {
super(islandTeamCommand, "accept"); super(islandTeamCommand, "accept");
@ -39,7 +38,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
@Override @Override
public boolean canExecute(User user, String label, List<String> args) { public boolean canExecute(User user, String label, List<String> args) {
playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
// Check if player has been invited // Check if player has been invited
if (!itc.isInvited(playerUUID)) { if (!itc.isInvited(playerUUID)) {
user.sendMessage("commands.island.team.invite.errors.none-invited-you"); user.sendMessage("commands.island.team.invite.errors.none-invited-you");
@ -79,7 +78,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
// Get the invite // Get the invite
Invite invite = itc.getInvite(playerUUID); Invite invite = itc.getInvite(user.getUniqueId());
switch (invite.getType()) { switch (invite.getType()) {
case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite)); case COOP -> askConfirmation(user, () -> acceptCoopInvite(user, invite));
case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite)); case TRUST -> askConfirmation(user, () -> acceptTrustInvite(user, invite));
@ -89,9 +88,9 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
return true; return true;
} }
private void acceptTrustInvite(User user, Invite invite) { void acceptTrustInvite(User user, Invite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(playerUUID); itc.removeInvite(user.getUniqueId());
User inviter = User.getInstance(invite.getInviter()); User inviter = User.getInstance(invite.getInviter());
Island island = invite.getIsland(); Island island = invite.getIsland();
if (island != null) { if (island != null) {
@ -115,9 +114,9 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
} }
} }
private void acceptCoopInvite(User user, Invite invite) { void acceptCoopInvite(User user, Invite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(playerUUID); itc.removeInvite(user.getUniqueId());
User inviter = User.getInstance(invite.getInviter()); User inviter = User.getInstance(invite.getInviter());
Island island = invite.getIsland(); Island island = invite.getIsland();
if (island != null) { if (island != null) {
@ -141,11 +140,11 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
} }
} }
private void acceptTeamInvite(User user, Invite invite) { void acceptTeamInvite(User user, Invite invite) {
// Remove the invite // Remove the invite
itc.removeInvite(playerUUID); itc.removeInvite(user.getUniqueId());
// Get the player's island - may be null if the player has no island // Get the player's island - may be null if the player has no island
Set<Island> islands = getIslands().getIslands(getWorld(), playerUUID); Set<Island> islands = getIslands().getIslands(getWorld(), user.getUniqueId());
// Get the team's island // Get the team's island
Island teamIsland = invite.getIsland(); Island teamIsland = invite.getIsland();
if (teamIsland == null) { if (teamIsland == null) {
@ -158,11 +157,11 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
return; return;
} }
// Remove player as owner of the old island // Remove player as owner of the old island
getIslands().removePlayer(getWorld(), playerUUID); getIslands().removePlayer(getWorld(), user.getUniqueId());
// Remove money inventory etc. for leaving // Remove money inventory etc. for leaving
cleanPlayer(user); cleanPlayer(user);
// Add the player as a team member of the new island // Add the player as a team member of the new island
getIslands().setJoinTeam(teamIsland, playerUUID); getIslands().setJoinTeam(teamIsland, user.getUniqueId());
// Move player to team's island // Move player to team's island
getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> { getIslands().homeTeleportAsync(getWorld(), user.getPlayer()).thenRun(() -> {
// Delete the old islands // Delete the old islands
@ -178,7 +177,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
}); });
// Reset deaths // Reset deaths
if (getIWM().isTeamJoinDeathReset(getWorld())) { if (getIWM().isTeamJoinDeathReset(getWorld())) {
getPlayers().setDeaths(getWorld(), playerUUID, 0); getPlayers().setDeaths(getWorld(), user.getUniqueId(), 0);
} }
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel()); user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
User inviter = User.getInstance(invite.getInviter()); User inviter = User.getInstance(invite.getInviter());
@ -188,7 +187,8 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
} }
getIslands().save(teamIsland); getIslands().save(teamIsland);
// Fire event // Fire event
TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(playerUUID).build(); TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(user.getUniqueId())
.build();
IslandEvent.builder().island(teamIsland).involvedPlayer(user.getUniqueId()).admin(false) IslandEvent.builder().island(teamIsland).involvedPlayer(user.getUniqueId()).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(teamIsland.getRank(user), RanksManager.MEMBER_RANK) .reason(IslandEvent.Reason.RANK_CHANGE).rankChange(teamIsland.getRank(user), RanksManager.MEMBER_RANK)
.build(); .build();

View File

@ -1,18 +1,33 @@
package world.bentobox.bentobox.api.commands.island.team; package world.bentobox.bentobox.api.commands.island.team;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type; import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent; import world.bentobox.bentobox.api.events.team.TeamEvent;
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.PanelItem;
import world.bentobox.bentobox.api.panels.TemplatedPanel;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
@ -24,6 +39,13 @@ public class IslandTeamInviteCommand extends CompositeCommand {
private final IslandTeamCommand itc; private final IslandTeamCommand itc;
private @Nullable User invitedPlayer; private @Nullable User invitedPlayer;
private @Nullable TemplateItem border;
private @Nullable TemplateItem background;
private User user;
private long page = 0; // This number by 35
private boolean inviteCmd;
private static final long PER_PAGE = 35;
private String searchName = "";
public IslandTeamInviteCommand(IslandTeamCommand parent) { public IslandTeamInviteCommand(IslandTeamCommand parent) {
super(parent, "invite"); super(parent, "invite");
@ -36,6 +58,10 @@ public class IslandTeamInviteCommand extends CompositeCommand {
setOnlyPlayer(true); setOnlyPlayer(true);
setDescription("commands.island.team.invite.description"); setDescription("commands.island.team.invite.description");
setConfigurableRankCommand(); setConfigurableRankCommand();
// Panels
if (!new File(getPlugin().getDataFolder() + File.separator + "panels", "team_invite_panel.yml").exists()) {
getPlugin().saveResource("panels/team_invite_panel.yml", false);
}
} }
@ -51,7 +77,9 @@ public class IslandTeamInviteCommand extends CompositeCommand {
} }
if (args.size() != 1) { if (args.size() != 1) {
return handleCommandWithNoArgs(user); this.inviteCmd = true;
build(user);
return true;
} }
Island island = islandsManager.getIsland(getWorld(), user); Island island = islandsManager.getIsland(getWorld(), user);
@ -60,33 +88,15 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return checkRankAndInvitePlayer(user, island, rank, args.get(0)); return checkRankAndInvitePlayer(user, island, rank, args.get(0));
} }
private boolean handleCommandWithNoArgs(User user) {
UUID playerUUID = user.getUniqueId();
Type inviteType = getInviteType(playerUUID);
if (inviteType != null) {
String name = getPlayers().getName(playerUUID);
switch (inviteType) {
case COOP -> user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
case TRUST -> user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
default -> user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
}
return true;
}
showHelp(this, user);
return false;
}
private boolean checkRankAndInvitePlayer(User user, Island island, int rank, String playerName) { private boolean checkRankAndInvitePlayer(User user, Island island, int rank, String playerName) {
RanksManager ranksManager = getPlugin().getRanksManager();
PlayersManager playersManager = getPlayers(); PlayersManager playersManager = getPlayers();
UUID playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
// Check rank to use command // Check rank to use command
int requiredRank = island.getRankCommand(getUsage()); int requiredRank = island.getRankCommand(getUsage());
if (rank < requiredRank) { if (rank < requiredRank) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(ranksManager.getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
@ -127,14 +137,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return true; return true;
} }
private Type getInviteType(UUID playerUUID) {
if (itc.isInvited(playerUUID)) {
Invite invite = itc.getInvite(playerUUID);
return invite.getType();
}
return null;
}
private boolean canInvitePlayer(User user, User invitedPlayer) { private boolean canInvitePlayer(User user, User invitedPlayer) {
UUID playerUUID = user.getUniqueId(); UUID playerUUID = user.getUniqueId();
if (!invitedPlayer.isOnline() || !user.getPlayer().canSee(invitedPlayer.getPlayer())) { if (!invitedPlayer.isOnline() || !user.getPlayer().canSee(invitedPlayer.getPlayer())) {
@ -204,4 +206,198 @@ public class IslandTeamInviteCommand extends CompositeCommand {
return Optional.of(Util.tabLimit(options, lastArg)); return Optional.of(Util.tabLimit(options, lastArg));
} }
/**
* Build the invite panel
* @param user use of the panel
*/
void build(User user) {
this.user = user;
// Start building panel.
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
panelBuilder.user(user);
panelBuilder.world(user.getWorld());
panelBuilder.template("team_invite_panel", new File(getPlugin().getDataFolder(), "panels"));
panelBuilder.parameters("[name]", user.getName(), "[display_name]", user.getDisplayName());
panelBuilder.registerTypeBuilder("PROSPECT", this::createProspectButton);
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
panelBuilder.registerTypeBuilder("BACK", this::createBackButton);
// Stash the backgrounds for later use
border = panelBuilder.getPanelTemplate().border();
background = panelBuilder.getPanelTemplate().background();
// Register unknown type builder.
panelBuilder.build();
}
private PanelItem createBackButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.closeInventory();
if (!inviteCmd) {
this.itc.build();
}
return true;
}).build();
}
private PanelItem createSearchButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
PanelItemBuilder pib = new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.closeInventory();
new ConversationFactory(BentoBox.getInstance()).withLocalEcho(false).withTimeout(90)
.withModality(false).withFirstPrompt(new InviteNamePrompt(user, this))
.buildConversation(user.getPlayer()).begin();
return true;
});
if (!this.searchName.isBlank()) {
pib.description(user.getTranslation(Objects
.requireNonNullElse(template.description(),
"commands.island.team.invite.gui.button.searching"),
TextVariables.NAME, searchName));
}
return pib.build();
}
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
long count = getWorld().getPlayers().stream().filter(player -> user.getPlayer().canSee(player))
.filter(player -> !player.equals(user.getPlayer())).count();
if (count > page * PER_PAGE) {
// We need to show a next button
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
page++;
build(user);
return true;
}).build();
}
return getBlankBorder();
}
private void checkTemplate(ItemTemplateRecord template) {
if (template.icon() == null) {
getPlugin().logError("Icon in template is missing or unknown! " + template.toString());
}
if (template.title() == null) {
getPlugin().logError("Title in template is missing! " + template.toString());
}
}
private PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
checkTemplate(template);
if (page > 0) {
// We need to show a next button
return new PanelItemBuilder().name(user.getTranslation(template.title())).icon(template.icon())
.clickHandler((panel, user, clickType, clickSlot) -> {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
page--;
build(user);
return true;
}).build();
}
return getBlankBorder();
}
private PanelItem getBlankBorder() {
return new PanelItemBuilder().icon(Objects.requireNonNullElse(border.icon(), new ItemStack(Material.BARRIER)))
.name((Objects.requireNonNullElse(border.title(), ""))).build();
}
/**
* Create member button panel item.
*
* @param template the template
* @param slot the slot
* @return the panel item
*/
private PanelItem createProspectButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
// Player issuing the command must have an island
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
if (island == null) {
return this.getBlankBackground();
}
if (page < 0) {
page = 0;
}
return getWorld().getPlayers().stream().filter(player -> user.getPlayer().canSee(player))
.filter(player -> this.searchName.isBlank() ? true
: player.getName().toLowerCase().contains(searchName.toLowerCase()))
.filter(player -> !player.equals(user.getPlayer())).skip(slot.slot() + page * PER_PAGE).findFirst()
.map(player -> getProspect(player, template)).orElse(this.getBlankBackground());
}
private PanelItem getProspect(Player player, ItemTemplateRecord template) {
// Check if the prospect has already been invited
if (this.itc.isInvited(player.getUniqueId())
&& user.getUniqueId().equals(this.itc.getInvite(player.getUniqueId()).getInviter())) {
return new PanelItemBuilder().icon(player.getName()).name(player.getDisplayName())
.description(user.getTranslation("commands.island.team.invite.gui.button.already-invited")).build();
}
List<String> desc = template.actions().stream().map(ar -> user
.getTranslation("commands.island.team.invite.gui.tips." + ar.clickType().name() + ".name")
+ " " + user.getTranslation(ar.tooltip())).toList();
return new PanelItemBuilder().icon(player.getName()).name(player.getDisplayName()).description(desc)
.clickHandler(
(panel, user, clickType, clickSlot) -> clickHandler(panel, user, clickType, clickSlot, player))
.build();
}
private boolean clickHandler(Panel panel, User user, ClickType clickType, int clickSlot, Player player) {
if (clickType.equals(ClickType.LEFT)) {
user.closeInventory();
if (this.canExecute(user, this.getLabel(), List.of(player.getName()))) {
getPlugin().log("Invite sent to: " + player.getName() + " by " + user.getName() + " to join island in "
+ getWorld().getName());
this.execute(user, getLabel(), List.of(player.getName()));
} else {
getPlugin().log("Invite failed: " + player.getName() + " by " + user.getName() + " to join island in "
+ getWorld().getName());
}
} else if (clickType.equals(ClickType.RIGHT)) {
user.closeInventory();
if (this.itc.getCoopCommand().canExecute(user, this.getLabel(), List.of(player.getName()))) {
getPlugin().log("Coop: " + player.getName() + " cooped " + user.getName() + " to island in "
+ getWorld().getName());
this.itc.getCoopCommand().execute(user, getLabel(), List.of(player.getName()));
} else {
getPlugin().log(
"Coop failed: " + player.getName() + "'s coop to " + user.getName() + " failed for island in "
+ getWorld().getName());
}
} else if (clickType.equals(ClickType.SHIFT_LEFT)) {
user.closeInventory();
if (this.itc.getTrustCommand().canExecute(user, this.getLabel(), List.of(player.getName()))) {
getPlugin().log("Trust: " + player.getName() + " trusted " + user.getName() + " to island in "
+ getWorld().getName());
this.itc.getTrustCommand().execute(user, getLabel(), List.of(player.getName()));
} else {
getPlugin().log("Trust failed: " + player.getName() + "'s trust failed for " + user.getName()
+ " for island in "
+ getWorld().getName());
}
}
return true;
}
private PanelItem getBlankBackground() {
return new PanelItemBuilder()
.icon(Objects.requireNonNullElse(background.icon(), new ItemStack(Material.BARRIER)))
.name((Objects.requireNonNullElse(background.title(), ""))).build();
}
/**
* @param searchName the searchName to set
*/
void setSearchName(String searchName) {
this.searchName = searchName;
}
} }

View File

@ -35,7 +35,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
} }
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean canExecute(User user, String label, List<String> args) {
if (!getIslands().inTeam(getWorld(), user.getUniqueId())) { if (!getIslands().inTeam(getWorld(), user.getUniqueId())) {
user.sendMessage("general.errors.no-team"); user.sendMessage("general.errors.no-team");
return false; return false;
@ -45,7 +45,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// If args are not right, show help // If args are not right, show help
@ -74,7 +74,13 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
getPlayers().getName(targetUUID)); getPlayers().getName(targetUUID));
return false; return false;
} }
return true;
}
@Override
public boolean execute(User user, String label, List<String> args) {
// Get target
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (!getSettings().isKickConfirmation()) { if (!getSettings().isKickConfirmation()) {
kick(user, targetUUID); kick(user, targetUUID);
return true; return true;
@ -84,7 +90,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
} }
} }
private void kick(User user, UUID targetUUID) { protected void kick(User user, UUID targetUUID) {
User target = User.getInstance(targetUUID); User target = User.getInstance(targetUUID);
Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID)); // Should never be Island oldIsland = Objects.requireNonNull(getIslands().getIsland(getWorld(), targetUUID)); // Should never be
// null because of // null because of

View File

@ -65,17 +65,17 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
} }
private void leave(User user) { protected boolean leave(User user) {
Island island = getIslands().getIsland(getWorld(), user); Island island = getIslands().getIsland(getWorld(), user);
if (island == null) { if (island == null) {
user.sendMessage("general.errors.no-island"); user.sendMessage("general.errors.no-island");
return; return false;
} }
// Fire event // Fire event
IslandBaseEvent event = TeamEvent.builder().island(island).reason(TeamEvent.Reason.LEAVE) IslandBaseEvent event = TeamEvent.builder().island(island).reason(TeamEvent.Reason.LEAVE)
.involvedPlayer(user.getUniqueId()).build(); .involvedPlayer(user.getUniqueId()).build();
if (event.isCancelled()) { if (event.isCancelled()) {
return; return false;
} }
UUID ownerUUID = island.getOwner(); UUID ownerUUID = island.getOwner();
if (ownerUUID != null) { if (ownerUUID != null) {
@ -103,5 +103,6 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false) IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(island.getRank(user), RanksManager.VISITOR_RANK) .reason(IslandEvent.Reason.RANK_CHANGE).rankChange(island.getRank(user), RanksManager.VISITOR_RANK)
.build(); .build();
return true;
} }
} }

View File

@ -54,7 +54,8 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
Island island = getIslands().getIsland(getWorld(), user); Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
@ -97,11 +98,11 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
Island island = getIslands().getIsland(getWorld(), user); Island island = getIslands().getIsland(getWorld(), user);
int currentRank = island.getRank(target); int currentRank = island.getRank(target);
if (this.getLabel().equals("promote")) { if (this.getLabel().equals("promote")) {
int nextRank = getPlugin().getRanksManager().getRankUpValue(currentRank); int nextRank = RanksManager.getInstance().getRankUpValue(currentRank);
// Stop short of owner // Stop short of owner
if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) { if (nextRank != RanksManager.OWNER_RANK && nextRank > currentRank) {
island.setRank(target, nextRank); island.setRank(target, nextRank);
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(nextRank)); String rankName = user.getTranslation(RanksManager.getInstance().getRank(nextRank));
user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName()); user.sendMessage("commands.island.team.promote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName());
IslandEvent.builder() IslandEvent.builder()
.island(island) .island(island)
@ -117,11 +118,11 @@ public class IslandTeamPromoteCommand extends CompositeCommand {
} }
} else { } else {
// Demote // Demote
int prevRank = getPlugin().getRanksManager().getRankDownValue(currentRank); int prevRank = RanksManager.getInstance().getRankDownValue(currentRank);
// Lowest is Member // Lowest is Member
if (prevRank >= RanksManager.MEMBER_RANK && prevRank < currentRank) { if (prevRank >= RanksManager.MEMBER_RANK && prevRank < currentRank) {
island.setRank(target, prevRank); island.setRank(target, prevRank);
String rankName = user.getTranslation(getPlugin().getRanksManager().getRank(prevRank)); String rankName = user.getTranslation(RanksManager.getInstance().getRank(prevRank));
user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName()); user.sendMessage("commands.island.team.demote.success", TextVariables.NAME, target.getName(), TextVariables.RANK, rankName, TextVariables.DISPLAY_NAME, target.getDisplayName());
IslandEvent.builder() IslandEvent.builder()
.island(island) .island(island)

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
@ -69,19 +70,24 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
return setOwner(user, targetUUID);
}
protected boolean setOwner(User user, @NonNull UUID targetUUID2) {
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()); Island island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
IslandBaseEvent e = TeamEvent.builder().island(island).reason(TeamEvent.Reason.SETOWNER) IslandBaseEvent e = TeamEvent.builder().island(island).reason(TeamEvent.Reason.SETOWNER)
.involvedPlayer(targetUUID).build(); .involvedPlayer(targetUUID2).build();
if (e.isCancelled()) { if (e.isCancelled()) {
return false; return false;
} }
getIslands().setOwner(getWorld(), user, targetUUID); getIslands().setOwner(getWorld(), user, targetUUID2);
// Call the event for the new owner // Call the event for the new owner
IslandEvent.builder().island(island).involvedPlayer(targetUUID).admin(false) IslandEvent.builder().island(island).involvedPlayer(targetUUID2).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE) .reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(User.getInstance(targetUUID)), RanksManager.OWNER_RANK).build(); .rankChange(island.getRank(User.getInstance(targetUUID2)), RanksManager.OWNER_RANK).build();
// Call the event for the previous owner // Call the event for the previous owner
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false) IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK) .reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK)

View File

@ -55,7 +55,8 @@ public class IslandTeamTrustCommand extends CompositeCommand {
Island island = getIslands().getIsland(getWorld(), user); Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player

View File

@ -55,7 +55,7 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player
@ -68,7 +68,7 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
return unCoopCmd(user, targetUUID); return unCoopCmd(user, targetUUID);
} }
private boolean unCoopCmd(User user, UUID targetUUID) { protected boolean unCoopCmd(User user, UUID targetUUID) {
// Player cannot uncoop themselves // Player cannot uncoop themselves
if (user.getUniqueId().equals(targetUUID)) { if (user.getUniqueId().equals(targetUUID)) {
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself"); user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself");

View File

@ -55,7 +55,7 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
int rank = Objects.requireNonNull(island).getRank(user); int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) { if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank))); user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false; return false;
} }
// Get target player // Get target player
@ -68,7 +68,7 @@ public class IslandTeamUntrustCommand extends CompositeCommand {
return unTrustCmd(user, targetUUID); return unTrustCmd(user, targetUUID);
} }
private boolean unTrustCmd(User user, UUID targetUUID) { protected boolean unTrustCmd(User user, UUID targetUUID) {
// Player cannot untrust themselves // Player cannot untrust themselves
if (user.getUniqueId().equals(targetUUID)) { if (user.getUniqueId().equals(targetUUID)) {
user.sendMessage("commands.island.team.untrust.cannot-untrust-yourself"); user.sendMessage("commands.island.team.untrust.cannot-untrust-yourself");

View File

@ -430,7 +430,7 @@ public class Flag implements Comparable<Flag> {
// Protection flag // Protection flag
pib.description(user.getTranslation("protection.panel.flag-item.description-layout", pib.description(user.getTranslation("protection.panel.flag-item.description-layout",
TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()))); TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
plugin.getRanksManager().getRanks().forEach((reference, score) -> { RanksManager.getInstance().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));
} else if (score <= RanksManager.OWNER_RANK && score > island.getFlag(this)) { } else if (score <= RanksManager.OWNER_RANK && score > island.getFlag(this)) {

View File

@ -81,15 +81,14 @@ public class CycleClick implements PanelItem.ClickHandler {
// Shift Left Click toggles player visibility // Shift Left Click toggles player visibility
if (island != null && (user.isOp() || island.isAllowed(user, Flags.CHANGE_SETTINGS) || user.hasPermission(prefix + "admin.settings"))) { if (island != null && (user.isOp() || island.isAllowed(user, Flags.CHANGE_SETTINGS) || user.hasPermission(prefix + "admin.settings"))) {
changeOccurred = true; changeOccurred = true;
RanksManager rm = plugin.getRanksManager();
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> { plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
// Rank // Rank
int currentRank = island.getFlag(flag); int currentRank = island.getFlag(flag);
if (click.equals(ClickType.LEFT)) { if (click.equals(ClickType.LEFT)) {
leftClick(flag, rm, currentRank); leftClick(flag, currentRank);
} else if (click.equals(ClickType.RIGHT)) { } else if (click.equals(ClickType.RIGHT)) {
rightClick(flag, rm, currentRank); rightClick(flag, currentRank);
} else if (click.equals(ClickType.SHIFT_LEFT) && user2.isOp()) { } else if (click.equals(ClickType.SHIFT_LEFT) && user2.isOp()) {
leftShiftClick(flag); leftShiftClick(flag);
@ -109,16 +108,16 @@ public class CycleClick implements PanelItem.ClickHandler {
// Player is not the allowed to change settings. // Player is not the allowed to change settings.
user.sendMessage("general.errors.insufficient-rank", user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, TextVariables.RANK,
user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user)))); user.getTranslation(RanksManager.getInstance().getRank(Objects.requireNonNull(island).getRank(user))));
} }
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
} }
private void leftClick(Flag flag, RanksManager rm, int currentRank) { private void leftClick(Flag flag, int currentRank) {
if (currentRank >= maxRank) { if (currentRank >= maxRank) {
island.setFlag(flag, minRank); island.setFlag(flag, minRank);
} else { } else {
island.setFlag(flag, rm.getRankUpValue(currentRank)); island.setFlag(flag, RanksManager.getInstance().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 // Fire event
@ -132,11 +131,11 @@ public class CycleClick implements PanelItem.ClickHandler {
} }
private void rightClick(Flag flag, RanksManager rm, int currentRank) { private void rightClick(Flag flag, int currentRank) {
if (currentRank <= minRank) { if (currentRank <= minRank) {
island.setFlag(flag, maxRank); island.setFlag(flag, maxRank);
} else { } else {
island.setFlag(flag, rm.getRankDownValue(currentRank)); island.setFlag(flag, RanksManager.getInstance().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 // Fire event

View File

@ -17,6 +17,7 @@ import world.bentobox.bentobox.api.panels.TabbedPanel;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.panels.settings.SettingsTab; import world.bentobox.bentobox.panels.settings.SettingsTab;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -112,7 +113,7 @@ public class IslandToggleClick implements ClickHandler {
// Player is not the allowed to change settings. // Player is not the allowed to change settings.
user.sendMessage("general.errors.insufficient-rank", user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, TextVariables.RANK,
user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user)))); user.getTranslation(RanksManager.getInstance().getRank(Objects.requireNonNull(island).getRank(user))));
} }
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);

View File

@ -38,8 +38,8 @@ public class Panel implements HeadRequester, InventoryHolder {
* <br> * <br>
* The current list of inventories that cannot be created are:<br> * The current list of inventories that cannot be created are:<br>
* <blockquote> * <blockquote>
* {@link Type#INVENTORY}, {@link Type#HOPPER} and * {@link Type#INVENTORY}, {@link Type#HOPPER},
* {@link Type#DROPPER} * {@link Type#DROPPER}, {@link Type#ANVIL}
* </blockquote> * </blockquote>
* *
* These relate to the Bukkit inventories with INVENTORY being the standard CHEST inventory. * These relate to the Bukkit inventories with INVENTORY being the standard CHEST inventory.
@ -47,7 +47,7 @@ public class Panel implements HeadRequester, InventoryHolder {
* @since 1.7.0 * @since 1.7.0
*/ */
public enum Type { public enum Type {
INVENTORY, HOPPER, DROPPER INVENTORY, HOPPER, DROPPER, ANVIL
} }
public Panel() { public Panel() {
@ -92,6 +92,7 @@ public class Panel implements HeadRequester, InventoryHolder {
case INVENTORY -> inventory = Bukkit.createInventory(null, fixSize(size), name); case INVENTORY -> inventory = Bukkit.createInventory(null, fixSize(size), name);
case HOPPER -> inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name); case HOPPER -> inventory = Bukkit.createInventory(null, InventoryType.HOPPER, name);
case DROPPER -> inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name); case DROPPER -> inventory = Bukkit.createInventory(null, InventoryType.DROPPER, name);
case ANVIL -> inventory = Bukkit.createInventory(null, InventoryType.ANVIL, name);
} }
// Fill the inventory and return // Fill the inventory and return

View File

@ -61,6 +61,7 @@ public class TemplatedPanel extends Panel {
case INVENTORY -> this.populateInventoryPanel(new PanelItem[6][9]); case INVENTORY -> this.populateInventoryPanel(new PanelItem[6][9]);
case HOPPER -> this.populateInventoryPanel(new PanelItem[1][5]); case HOPPER -> this.populateInventoryPanel(new PanelItem[1][5]);
case DROPPER -> this.populateInventoryPanel(new PanelItem[3][3]); case DROPPER -> this.populateInventoryPanel(new PanelItem[3][3]);
case ANVIL -> this.populateInventoryPanel(new PanelItem[4][9]);
}; };
super.makePanel(this.user.getTranslation(this.panelTemplate.title(), this.parameters), items, super.makePanel(this.user.getTranslation(this.panelTemplate.title(), this.parameters), items,

View File

@ -3,10 +3,8 @@
// Copyright - 2021 // Copyright - 2021
// //
package world.bentobox.bentobox.api.panels.reader; package world.bentobox.bentobox.api.panels.reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -17,8 +15,6 @@ import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecords;
/** /**
* This Record contains all necessary information about Item Template that can be used to craft panel item. * This Record contains all necessary information about Item Template that can be used to craft panel item.
* *
@ -31,13 +27,32 @@ import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord.ActionRecord
* *
* @since 1.17.3 * @since 1.17.3
*/ */
public record ItemTemplateRecord(@Nullable ItemStack icon, public record ItemTemplateRecord(
/**
* ItemStack of the Item
*/
@Nullable ItemStack icon,
/**
* Title of the item
*/
@Nullable String title, @Nullable String title,
/**
* Lore message of the item
*/
@Nullable String description, @Nullable String description,
/**
* List of Actions for a button
*/
@NonNull List<ActionRecords> actions, @NonNull List<ActionRecords> actions,
/**
* DataMap that links additional objects for a button.
*/
@NonNull Map<String, Object> dataMap, @NonNull Map<String, Object> dataMap,
@Nullable ItemTemplateRecord fallback) /**
{ * FallBack item if current one is not possible to generate.
*/
@Nullable ItemTemplateRecord fallback) {
/** /**
* Instantiates a new Item template record without actions and data map. * Instantiates a new Item template record without actions and data map.
* *
@ -46,39 +61,32 @@ public record ItemTemplateRecord(@Nullable ItemStack icon,
* @param description the description * @param description the description
* @param fallback the fallback * @param fallback the fallback
*/ */
public ItemTemplateRecord(ItemStack icon, String title, String description, ItemTemplateRecord fallback) public ItemTemplateRecord(ItemStack icon, String title, String description, ItemTemplateRecord fallback) {
{
this(icon, title, description, new ArrayList<>(6), new HashMap<>(0), fallback); this(icon, title, description, new ArrayList<>(6), new HashMap<>(0), fallback);
} }
/** /**
* This method adds given object associated with key into data map. * This method adds given object associated with key into data map.
* @param key Key value of object. * @param key Key value of object.
* @param data Data that is associated with a key. * @param data Data that is associated with a key.
*/ */
public void addData(String key, Object data) public void addData(String key, Object data) {
{
this.dataMap.put(key, data); this.dataMap.put(key, data);
} }
/** /**
* Add action to the actions list. * Add action to the actions list.
* *
* @param actionData the action data * @param actionData the action data
*/ */
public void addAction(ActionRecords actionData) public void addAction(ActionRecords actionData) {
{
this.actions.add(actionData); this.actions.add(actionData);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Section: Classes // Section: Classes
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
/** /**
* The Action Records holds data about each action. * The Action Records holds data about each action.
* *
@ -87,5 +95,22 @@ public record ItemTemplateRecord(@Nullable ItemStack icon,
* @param content the content of the action * @param content the content of the action
* @param tooltip the tooltip of action * @param tooltip the tooltip of action
*/ */
public record ActionRecords(ClickType clickType, String actionType, String content, String tooltip) {} public record ActionRecords(
/**
* the click type
*/
ClickType clickType,
/**
* the string that represents action type
*/
String actionType,
/**
* the content of the action
*/
String content,
/**
* the tooltip of action
*/
String tooltip) {
}
} }

View File

@ -15,7 +15,6 @@ import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.Panel;
import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem;
/** /**
* This is template object for the panel reader. It contains data that can exist in the panel. * This is template object for the panel reader. It contains data that can exist in the panel.

View File

@ -22,6 +22,7 @@ import org.eclipse.jdt.annotation.Nullable;
import com.google.common.base.Enums; import com.google.common.base.Enums;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.Panel;
import world.bentobox.bentobox.util.ItemParser; import world.bentobox.bentobox.util.ItemParser;
@ -83,6 +84,7 @@ public class TemplateReader
{ {
if (!panelLocation.exists()) if (!panelLocation.exists())
{ {
BentoBox.getInstance().logError("Panel Template reader: Folder does not exist");
// Return null because folder does not exist. // Return null because folder does not exist.
return null; return null;
} }
@ -91,6 +93,7 @@ public class TemplateReader
if (!file.exists()) if (!file.exists())
{ {
BentoBox.getInstance().logError(file.getAbsolutePath() + " does not exist for panel template");
// Return as file does not exist. // Return as file does not exist.
return null; return null;
} }
@ -117,6 +120,8 @@ public class TemplateReader
} }
catch (IOException | InvalidConfigurationException e) catch (IOException | InvalidConfigurationException e)
{ {
BentoBox.getInstance().logError("Error loading template");
BentoBox.getInstance().logStacktrace(e);
rec = null; rec = null;
} }
@ -133,6 +138,7 @@ public class TemplateReader
{ {
if (configurationSection == null) if (configurationSection == null)
{ {
BentoBox.getInstance().logError("No configuration section!");
// No data to return. // No data to return.
return null; return null;
} }

View File

@ -78,7 +78,8 @@ public class BlueprintEntity {
if (e instanceof AbstractHorse horse) { if (e instanceof AbstractHorse horse) {
if (domestication != null) horse.setDomestication(domestication); if (domestication != null) horse.setDomestication(domestication);
if (inventory != null) { if (inventory != null) {
inventory.forEach(horse.getInventory()::setItem); inventory.forEach((index, item) -> horse.getInventory().setItem(index.intValue(), item));
} }
} }
if (style != null && e instanceof Horse horse) { if (style != null && e instanceof Horse horse) {

View File

@ -20,7 +20,6 @@ public class BentoBoxRankCommand extends CompositeCommand {
private static final String REMOVE = "remove"; private static final String REMOVE = "remove";
private int rankValue; private int rankValue;
private String firstElement; private String firstElement;
private final RanksManager rm;
/** /**
* Rank management. Add and remove * Rank management. Add and remove
@ -29,7 +28,6 @@ public class BentoBoxRankCommand extends CompositeCommand {
*/ */
public BentoBoxRankCommand(CompositeCommand parent) { public BentoBoxRankCommand(CompositeCommand parent) {
super(parent, "rank"); super(parent, "rank");
rm = getPlugin().getRanksManager();
} }
@Override @Override
@ -93,7 +91,7 @@ public class BentoBoxRankCommand extends CompositeCommand {
return true; return true;
} }
if ("add".equals(firstElement)) { if ("add".equals(firstElement)) {
if (rm.addRank(args.get(1), rankValue)) { if (RanksManager.getInstance().addRank(args.get(1), rankValue)) {
user.sendMessage("commands.bentobox.rank.add.success", TextVariables.RANK, args.get(1), user.sendMessage("commands.bentobox.rank.add.success", TextVariables.RANK, args.get(1),
TextVariables.NUMBER, String.valueOf(rankValue)); TextVariables.NUMBER, String.valueOf(rankValue));
showRanks(user); showRanks(user);
@ -103,7 +101,7 @@ public class BentoBoxRankCommand extends CompositeCommand {
return false; return false;
} }
} else { } else {
if (rm.removeRank(args.get(1))) { if (RanksManager.getInstance().removeRank(args.get(1))) {
user.sendMessage("commands.bentobox.rank.remove.success", TextVariables.RANK, args.get(1)); user.sendMessage("commands.bentobox.rank.remove.success", TextVariables.RANK, args.get(1));
showRanks(user); showRanks(user);
} else { } else {
@ -116,7 +114,7 @@ public class BentoBoxRankCommand extends CompositeCommand {
private void showRanks(User user) { private void showRanks(User user) {
user.sendMessage("commands.bentobox.rank.list"); user.sendMessage("commands.bentobox.rank.list");
rm.getRanks().forEach((ref, rank) -> { RanksManager.getInstance().getRanks().forEach((ref, rank) -> {
user.sendRawMessage(user.getTranslation(ref) + ": " + ref + " " + String.valueOf(rank)); user.sendRawMessage(user.getTranslation(ref) + ": " + ref + " " + String.valueOf(rank));
}); });
@ -133,11 +131,11 @@ public class BentoBoxRankCommand extends CompositeCommand {
} }
if (args.size() > 1 && "add".equals(firstElement)) { if (args.size() > 1 && "add".equals(firstElement)) {
List<String> options = new ArrayList<>(RanksManager.DEFAULT_RANKS.keySet()); List<String> options = new ArrayList<>(RanksManager.DEFAULT_RANKS.keySet());
options.removeIf(rm.getRanks().keySet()::contains); options.removeIf(RanksManager.getInstance().getRanks().keySet()::contains);
return Optional.of(options); return Optional.of(options);
} }
if (args.size() > 1 && REMOVE.equals(firstElement)) { if (args.size() > 1 && REMOVE.equals(firstElement)) {
return Optional.of(new ArrayList<>(rm.getRanks().keySet())); return Optional.of(new ArrayList<>(RanksManager.getInstance().getRanks().keySet()));
} }
return Optional.empty(); return Optional.empty();

View File

@ -658,9 +658,6 @@ public class Island implements DataObject, MetaDataAble {
* @return rank integer * @return rank integer
*/ */
public int getRank(User user) { public int getRank(User user) {
if (user.isOp()) {
return RanksManager.ADMIN_RANK;
}
return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK); return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK);
} }

View File

@ -298,7 +298,7 @@ public class Players implements DataObject, MetaDataAble {
* @param world - world * @param world - world
*/ */
public void addReset(World world) { public void addReset(World world) {
resets.merge(world.getName(), 1, Integer::sum); resets.merge(world.getName(), 1, (oldValue, newValue) -> Integer.valueOf(oldValue + newValue));
} }
/** /**

View File

@ -38,20 +38,19 @@ public class CommandCycleClick implements ClickHandler {
World world = panel.getWorld().orElse(user.getWorld()); World world = panel.getWorld().orElse(user.getWorld());
Island island = plugin.getIslands().getIsland(world, user.getUniqueId()); Island island = plugin.getIslands().getIsland(world, user.getUniqueId());
if (island != null && island.getOwner() != null && island.isAllowed(user, Flags.CHANGE_SETTINGS)) { if (island != null && island.getOwner() != null && island.isAllowed(user, Flags.CHANGE_SETTINGS)) {
RanksManager rm = plugin.getRanksManager();
int currentRank = island.getRankCommand(command); int currentRank = island.getRankCommand(command);
if (click.equals(ClickType.LEFT)) { if (click.equals(ClickType.LEFT)) {
if (currentRank == RanksManager.OWNER_RANK) { if (currentRank == RanksManager.OWNER_RANK) {
island.setRankCommand(command, RanksManager.MEMBER_RANK); island.setRankCommand(command, RanksManager.MEMBER_RANK);
} else { } else {
island.setRankCommand(command, rm.getRankUpValue(currentRank)); island.setRankCommand(command, RanksManager.getInstance().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_ON, 1F, 1F);
} else if (click.equals(ClickType.RIGHT)) { } else if (click.equals(ClickType.RIGHT)) {
if (currentRank == RanksManager.MEMBER_RANK) { if (currentRank == RanksManager.MEMBER_RANK) {
island.setRankCommand(command, RanksManager.OWNER_RANK); island.setRankCommand(command, RanksManager.OWNER_RANK);
} else { } else {
island.setRankCommand(command, rm.getRankDownValue(currentRank)); island.setRankCommand(command, RanksManager.getInstance().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);
} }

View File

@ -66,7 +66,7 @@ public class CommandRankClickListener implements ClickHandler {
// Check if user has rank enough on the island // Check if user has rank enough on the island
//Island island = plugin.getIslands().getIsland(panel.getWorld().orElse(user.getWorld()), user.getUniqueId()); //Island island = plugin.getIslands().getIsland(panel.getWorld().orElse(user.getWorld()), user.getUniqueId());
if (!island.isAllowed(user, Flags.CHANGE_SETTINGS)) { if (!island.isAllowed(user, Flags.CHANGE_SETTINGS)) {
String rank = user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user))); String rank = user.getTranslation(RanksManager.getInstance().getRank(Objects.requireNonNull(island).getRank(user)));
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, rank); user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK, rank);
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
return true; return true;
@ -114,7 +114,7 @@ public class CommandRankClickListener implements ClickHandler {
// TODO: use specific layout // TODO: use specific layout
String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, ""); String d = user.getTranslation("protection.panel.flag-item.description-layout", TextVariables.DESCRIPTION, "");
pib.description(d); pib.description(d);
plugin.getRanksManager().getRanks().forEach((reference, score) -> { RanksManager.getInstance().getRanks().forEach((reference, score) -> {
if (score >= RanksManager.MEMBER_RANK && score < island.getRankCommand(c)) { if (score >= RanksManager.MEMBER_RANK && score < island.getRankCommand(c)) {
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));
} else if (score <= RanksManager.OWNER_RANK && score > island.getRankCommand(c)) { } else if (score <= RanksManager.OWNER_RANK && score > island.getRankCommand(c)) {

View File

@ -162,7 +162,10 @@ public class LockAndBanListener extends FlagListener {
} else { } else {
// There's nothing much we can do. // There's nothing much we can do.
// We'll try to teleport him to the spawn... // We'll try to teleport him to the spawn...
PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); Location l = player.getWorld().getSpawnLocation();
if (l != null) {
PaperLib.teleportAsync(player, l);
}
// Switch him back to the default gamemode. He may die, sorry :( // Switch him back to the default gamemode. He may die, sorry :(
player.setGameMode(getIWM().getDefaultGameMode(player.getWorld())); player.setGameMode(getIWM().getDefaultGameMode(player.getWorld()));

View File

@ -289,7 +289,9 @@ public enum GameModePlaceholder {
* Returns the rank this player has on his island. * Returns the rank this player has on his island.
* @since 1.5.0 * @since 1.5.0
*/ */
RANK("rank", (addon, user, island) -> (island == null || user == null) ? "" : user.getTranslation(addon.getPlugin().getRanksManager().getRank(island.getRank(user)))), RANK("rank",
(addon, user, island) -> (island == null || user == null) ? ""
: user.getTranslation(RanksManager.getInstance().getRank(island.getRank(user)))),
/** /**
* Returns how many times this player reset his island. * Returns how many times this player reset his island.
* @since 1.5.0 * @since 1.5.0

View File

@ -1116,7 +1116,7 @@ public class IslandsManager {
.ifFail(() -> goingHome.remove(user.getUniqueId())).buildFuture().thenAccept(result::complete); .ifFail(() -> goingHome.remove(user.getUniqueId())).buildFuture().thenAccept(result::complete);
return; return;
} }
PaperLib.teleportAsync(player, home).thenAccept(b -> { PaperLib.teleportAsync(Objects.requireNonNull(player), home).thenAccept(b -> {
// Only run the commands if the player is successfully teleported // Only run the commands if the player is successfully teleported
if (Boolean.TRUE.equals(b)) { if (Boolean.TRUE.equals(b)) {
teleported(world, user, name, newIsland, island); teleported(world, user, name, newIsland, island);
@ -1512,7 +1512,12 @@ public class IslandsManager {
// Move player to spawn // Move player to spawn
if (spawn.containsKey(w)) { if (spawn.containsKey(w)) {
// go to island spawn // go to island spawn
PaperLib.teleportAsync(p, spawn.get(w).getSpawnPoint(w.getEnvironment())); Location sp = spawn.get(w).getSpawnPoint(w.getEnvironment());
if (sp != null) {
PaperLib.teleportAsync(p, sp);
} else {
plugin.logWarning("Spawn exists but its location is null!");
}
} }
} }
}); });
@ -1925,7 +1930,7 @@ public class IslandsManager {
Island highestIsland = null; Island highestIsland = null;
for (Island i : en.getValue()) { for (Island i : en.getValue()) {
int rankValue = i.getRank(en.getKey()); int rankValue = i.getRank(en.getKey());
String rank = plugin.getRanksManager().getRank(rankValue); String rank = RanksManager.getInstance().getRank(rankValue);
if (rankValue > highestRank || highestIsland == null) { if (rankValue > highestRank || highestIsland == null) {
highestRank = rankValue; highestRank = rankValue;
highestIsland = i; highestIsland = i;
@ -1937,7 +1942,7 @@ public class IslandsManager {
} }
// Fix island ownership in cache // Fix island ownership in cache
// Correct island cache // Correct island cache
if (highestRank == RanksManager.OWNER_RANK if (highestRank == RanksManager.OWNER_RANK && highestIsland != null
&& islandCache.getIslandById(highestIsland.getUniqueId()) != null) { && islandCache.getIslandById(highestIsland.getUniqueId()) != null) {
islandCache.setOwner(islandCache.getIslandById(highestIsland.getUniqueId()), en.getKey()); islandCache.setOwner(islandCache.getIslandById(highestIsland.getUniqueId()), en.getKey());
} }

View File

@ -95,7 +95,7 @@ public class PlaceholdersManager {
int j = 1; int j = 1;
for (UUID uuid : island.getMemberSet(RanksManager.MEMBER_RANK)) { for (UUID uuid : island.getMemberSet(RanksManager.MEMBER_RANK)) {
if (j++ == count) { if (j++ == count) {
return user.getTranslationOrNothing(plugin.getRanksManager().getRank(island.getRank(uuid))); return user.getTranslationOrNothing(RanksManager.getInstance().getRank(island.getRank(uuid)));
} }
} }
} }
@ -140,7 +140,7 @@ public class PlaceholdersManager {
int j = 1; int j = 1;
for (UUID uuid : island.getMemberSet(RanksManager.MEMBER_RANK)) { for (UUID uuid : island.getMemberSet(RanksManager.MEMBER_RANK)) {
if (j++ == count) { if (j++ == count) {
return user.getTranslationOrNothing(plugin.getRanksManager().getRank(island.getRank(uuid))); return user.getTranslationOrNothing(RanksManager.getInstance().getRank(island.getRank(uuid)));
} }
} }
return ""; return "";

View File

@ -41,16 +41,32 @@ public class RanksManager {
public static final int BANNED_RANK = -1; public static final int BANNED_RANK = -1;
// The store of ranks // The store of ranks
private LinkedHashMap<String, Integer> ranks = new LinkedHashMap<>(); private static LinkedHashMap<String, Integer> ranks = new LinkedHashMap<>();
public static final Map<String, Integer> DEFAULT_RANKS = Map.of(ADMIN_RANK_REF, ADMIN_RANK, MOD_RANK_REF, MOD_RANK, public static final Map<String, Integer> DEFAULT_RANKS = Map.of(ADMIN_RANK_REF, ADMIN_RANK, MOD_RANK_REF, MOD_RANK,
OWNER_RANK_REF, OWNER_RANK, SUB_OWNER_RANK_REF, SUB_OWNER_RANK, MEMBER_RANK_REF, MEMBER_RANK, OWNER_RANK_REF, OWNER_RANK, SUB_OWNER_RANK_REF, SUB_OWNER_RANK, MEMBER_RANK_REF, MEMBER_RANK,
TRUSTED_RANK_REF, TRUSTED_RANK, COOP_RANK_REF, COOP_RANK, VISITOR_RANK_REF, VISITOR_RANK, BANNED_RANK_REF, TRUSTED_RANK_REF, TRUSTED_RANK, COOP_RANK_REF, COOP_RANK, VISITOR_RANK_REF, VISITOR_RANK, BANNED_RANK_REF,
BANNED_RANK); BANNED_RANK);
@NonNull @NonNull
private Database<Ranks> handler; private static Database<Ranks> handler;
private static RanksManager instance;
public RanksManager() { // Private constructor for singleton
private RanksManager() {
handler = new Database<>(BentoBox.getInstance(), Ranks.class);
ranks = new LinkedHashMap<>();
loadRanksFromDatabase();
}
// Public method to get the singleton instance
public static synchronized RanksManager getInstance() {
if (instance == null) {
instance = new RanksManager();
}
return instance;
}
public void loadRanksFromDatabase() {
// Set up the database handler to store and retrieve Island classes // Set up the database handler to store and retrieve Island classes
handler = new Database<>(BentoBox.getInstance(), Ranks.class); handler = new Database<>(BentoBox.getInstance(), Ranks.class);
if (!handler.objectExists(Ranks.ID)) { if (!handler.objectExists(Ranks.ID)) {
@ -59,7 +75,8 @@ public class RanksManager {
handler.saveObject(new Ranks(ranks)); handler.saveObject(new Ranks(ranks));
} else { } else {
// Load the ranks from the database // Load the ranks from the database
Objects.requireNonNull(handler.loadObject(Ranks.ID)).getRankReference().forEach(this::ranksPut); Objects.requireNonNull(handler.loadObject(Ranks.ID)).getRankReference()
.forEach((rankRef, rankValue) -> ranksPut(rankRef, rankValue));
} }
} }

View File

@ -131,7 +131,7 @@ public class DefaultPasteUtil {
Inventory ih = holder.getInventory(); Inventory ih = holder.getInventory();
// Double chests are pasted as two blocks so inventory is filled twice. // Double chests are pasted as two blocks so inventory is filled twice.
// This code stops over-filling for the first block. // This code stops over-filling for the first block.
bpBlock.getInventory().forEach(ih::setItem); bpBlock.getInventory().forEach((slot, item) -> ih.setItem(slot, item));
} }
// Mob spawners // Mob spawners
else if (bs instanceof CreatureSpawner spawner) { else if (bs instanceof CreatureSpawner spawner) {

View File

@ -169,11 +169,11 @@ public class IslandInfo {
if (owner.equals(u)) { if (owner.equals(u)) {
user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME, user.sendMessage("commands.admin.info.team-owner-format", TextVariables.NAME,
plugin.getPlayers().getName(u), "[rank]", plugin.getPlayers().getName(u), "[rank]",
user.getTranslation(plugin.getRanksManager().getRank(i))); user.getTranslation(RanksManager.getInstance().getRank(i)));
} else if (i > RanksManager.VISITOR_RANK) { } else if (i > RanksManager.VISITOR_RANK) {
user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME, user.sendMessage("commands.admin.info.team-member-format", TextVariables.NAME,
plugin.getPlayers().getName(u), "[rank]", plugin.getPlayers().getName(u), "[rank]",
user.getTranslation(plugin.getRanksManager().getRank(i))); user.getTranslation(RanksManager.getInstance().getRank(i)));
} }
}); });
} }

View File

@ -109,7 +109,6 @@ commands:
description: displays the status of the purge description: displays the status of the purge
status: '&b [purged] &a islands purged out of &b [purgeable] &7(&b[percentage] status: '&b [purged] &a islands purged out of &b [purgeable] &7(&b[percentage]
%&7)&a.' %&7)&a.'
team: team:
description: manage teams description: manage teams
add: add:
@ -612,7 +611,41 @@ commands:
description: reset your island name description: reset your island name
success: '&a Successfully reset your island name.' success: '&a Successfully reset your island name.'
team: team:
description: manage your team description: "manage your team"
gui:
titles:
team-panel: "Team Management"
buttons:
status:
name: "Status"
description: "The status of the team"
rank-filter:
name: "Rank Filter"
description: "&a Click to cycle ranks"
invitation: "Invitation"
invite:
name: "Invite player"
description: |
&a Players must be in the
&a same world as you to be
&a shown in the list.
tips:
LEFT:
name: "&b Left Click"
invite: "&a to invite a player"
RIGHT:
name: "&b Right Click"
SHIFT_RIGHT:
name: "&b Shift Right Click"
reject: "&a to reject"
kick: "&a to kick player"
leave: "&a to leave team"
SHIFT_LEFT:
name: "&b Shift Left Click"
accept: "&a to accept "
setowner: |
&a to set owner
&a to this player
info: info:
description: display detailed info about your team description: display detailed info about your team
member-layout: member-layout:
@ -678,6 +711,30 @@ commands:
to-accept-or-reject: '&a Do /[label] team accept to accept, or /[label] team to-accept-or-reject: '&a Do /[label] team accept to accept, or /[label] team
reject to reject' reject to reject'
you-will-lose-your-island: '&c WARNING! You will lose your island if you accept!' you-will-lose-your-island: '&c WARNING! You will lose your island if you accept!'
gui:
titles:
team-invite-panel: "Invite Players"
button:
already-invited: "&c Invited already"
search: "&a Search for a player"
searching: |
&b Searching for
&c [name]
enter-name: "&a Enter name:"
tips:
LEFT:
name: "&b Left Click"
search: "&a Enter the player's name"
back: "&a Back"
invite: |
&a to invite a player
&a to join your team
RIGHT:
name: "&b Right Click"
coop: "&a to coop player"
SHIFT_LEFT:
name: "&b Shift Left Click"
trust: "&a to trust a player"
errors: errors:
cannot-invite-self: '&c You cannot invite yourself!' cannot-invite-self: '&c You cannot invite yourself!'
cooldown: '&c You cannot invite that person for another [number] seconds.' cooldown: '&c You cannot invite that person for another [number] seconds.'

View File

@ -0,0 +1,144 @@
# Name of panel used for indentification in the code - must be the same name as the filename.
team_invite_panel:
# Title of the panel shown to the user. This is a reference and the reference will be translatable in the locale file
title: commands.island.team.invite.gui.titles.team-invite-panel
# The type of panel to show. Options are INVENTORY, HOPPER, DROPPER. INVENTORY is that standard chest inventory and
# the others refer to the inventories shown for those items.
type: INVENTORY
# The background of the panel. These items will be shown if other items are not there. STAINED_GLASS_PANEs give a good effect.
background:
icon: BLACK_STAINED_GLASS_PANE
# Each item may have text applied to it, but usually for background items, nothing is shown.
title: "&b&r" # Empty text. This is using the Bukkit chat color coding with &'s.
border:
# The border of each panel may be shown as a different item.
# It can be used to provide a contrast to items in the panel.
icon: BLUE_STAINED_GLASS_PANE
title: "&b&r" # Empty text
# This tag indicates which rows in the panel must be shown. The panel will be sized vertically accordingly. This does not include the borders.
# This can be a list and rows must be between 1 and 6, if used.
force-shown: []
# The content section contains details of each item/button in the panel. The numbers indicate the rows and then then columns of each item.
content:
# Row number
1:
2:
title: "protection.panel.previous"
icon: ARROW
data:
type: PREVIOUS
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
view:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.previous
5:
title: "commands.island.team.invite.gui.button.search"
description: "commands.island.team.invite.gui.button.searching"
icon: PLAYER_HEAD
data:
type: SEARCH
actions:
search:
click-type: LEFT
tooltip: commands.island.team.invite.gui.tips.search
8:
title: "protection.panel.next"
icon: ARROW
data:
type: NEXT
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
view:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.next
2:
2: prospect_button
3: prospect_button
4: prospect_button
5: prospect_button
6: prospect_button
7: prospect_button
8: prospect_button
3:
2: prospect_button
3: prospect_button
4: prospect_button
5: prospect_button
6: prospect_button
7: prospect_button
8: prospect_button
4:
2: prospect_button
3: prospect_button
4: prospect_button
5: prospect_button
6: prospect_button
7: prospect_button
8: prospect_button
5:
2: prospect_button
3: prospect_button
4: prospect_button
5: prospect_button
6: prospect_button
7: prospect_button
8: prospect_button
6:
2: prospect_button
3: prospect_button
4: prospect_button
5: prospect_button
6: prospect_button
7: prospect_button
8: prospect_button
9:
title: "commands.island.team.invite.gui.tips.LEFT.back"
icon: OAK_DOOR
data:
type: BACK
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
back:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.LEFT.back
# This is where reusable buttons are defined.
reusable:
# This is the name of the button that is referenced
prospect_button:
# If the icon for a button is not defined, it defaults to AIR and so effectively will not be shown.
# icons are usually not defined if the icon is going to be dynamically set in the panel, e.g. in this case the material will vary
#icon: STONE
title: commands.island.team.invite.gui.buttons.member.name
description: commands.island.team.invite.gui.buttons.member.description
data:
type: PROSPECT
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
invite:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: LEFT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.invite.gui.tips.LEFT.invite
coop:
click-type: RIGHT
tooltip: commands.island.team.invite.gui.tips.RIGHT.coop
trust:
click-type: SHIFT_LEFT
tooltip: commands.island.team.invite.gui.tips.SHIFT_LEFT.trust

View File

@ -0,0 +1,139 @@
# Name of panel used for indentification in the code - must be the same name as the filename.
team_panel:
# Title of the panel shown to the user. This is a reference and the reference will be translatable in the locale file
title: commands.island.team.gui.titles.team-panel
# The type of panel to show. Options are INVENTORY, HOPPER, DROPPER. INVENTORY is that standard chest inventory and
# the others refer to the inventories shown for those items.
type: INVENTORY
# The background of the panel. These items will be shown if other items are not there. STAINED_GLASS_PANEs give a good effect.
background:
icon: BLACK_STAINED_GLASS_PANE
# Each item may have text applied to it, but usually for background items, nothing is shown.
title: "&b&r" # Empty text. This is using the Bukkit chat color coding with &'s.
border:
# The border of each panel may be shown as a different item.
# It can be used to provide a contrast to items in the panel.
icon: BLUE_STAINED_GLASS_PANE
title: "&b&r" # Empty text
# This tag indicates which rows in the panel must be shown. The panel will be sized vertically accordingly. This does not include the borders.
# This can be a list and rows must be between 1 and 6, if used.
force-shown: []
# The content section contains details of each item/button in the panel. The numbers indicate the rows and then then columns of each item.
content:
# Row number
1:
# Column number
1:
# The data section is a key-value list of data relavent for this button. It is interpreted by the code implemented the panel.
# The convention is to specify the type and the panel tab that will open if pressed. These are Enums in the code.
data:
type: STATUS
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
view:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: UNKNOWN
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.gui.tips.click-to-view
3:
# Rank filter
data:
type: RANK
name: commands.island.team.gui.buttons.rank-filter
actions:
cycle-up:
click-type: LEFT
tooltip: commands.island.team.gui.tips.right-click.rank
cycle-down:
click-type: RIGHT
tooltip: commands.island.team.gui.tips.right-click.rank
5:
# Invited button - this appears if you have been invited to join a team
data:
type: INVITED
name: commands.island.team.gui.buttons.invited
actions:
accept:
click-type: SHIFT_LEFT
tooltip: commands.island.team.gui.tips.SHIFT_LEFT.accept
reject:
click-type: SHIFT_RIGHT
tooltip: commands.island.team.gui.tips.SHIFT_RIGHT.reject
7:
# Invite button
data:
type: INVITE
name: commands.island.team.gui.buttons.invite
actions:
invite:
click-type: LEFT
tooltip: commands.island.team.gui.tips.LEFT.invite
2:
2: member_button
3: member_button
4: member_button
5: member_button
6: member_button
7: member_button
8: member_button
3:
2: member_button
3: member_button
4: member_button
5: member_button
6: member_button
7: member_button
8: member_button
4:
2: member_button
3: member_button
4: member_button
5: member_button
6: member_button
7: member_button
8: member_button
5:
2: member_button
3: member_button
4: member_button
5: member_button
6: member_button
7: member_button
8: member_button
6:
2: member_button
3: member_button
4: member_button
5: member_button
6: member_button
7: member_button
8: member_button
# This is where reusable buttons are defined.
reusable:
# This is the name of the button that is referenced
member_button:
# If the icon for a button is not defined, it defaults to AIR and so effectively will not be shown.
# icons are usually not defined if the icon is going to be dynamically set in the panel, e.g. in this case the material will vary
#icon: STONE
title: commands.island.team.gui.buttons.member.name
description: commands.island.team.gui.buttons.member.description
data:
type: MEMBER
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
kick:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: SHIFT_RIGHT
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: commands.island.team.gui.tips.SHIFT_RIGHT.kick
leave:
click-type: SHIFT_RIGHT
tooltip: commands.island.team.gui.tips.SHIFT_RIGHT.leave
setowner:
click-type: SHIFT_LEFT
tooltip: commands.island.team.gui.tips.SHIFT_LEFT.setowner

View File

@ -47,7 +47,7 @@ import world.bentobox.bentobox.util.Util;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) @PrepareForTest({ Bukkit.class, BentoBox.class, User.class, RanksManager.class })
public class AdminGetrankCommandTest { public class AdminGetrankCommandTest {
private static final String[] NAMES = {"adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe"}; private static final String[] NAMES = {"adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe"};
@ -80,7 +80,8 @@ public class AdminGetrankCommandTest {
Util.setPlugin(plugin); Util.setPlugin(plugin);
// Ranks Manager // Ranks Manager
when(plugin.getRanksManager()).thenReturn(rm); PowerMockito.mockStatic(RanksManager.class, Mockito.RETURNS_MOCKS);
when(RanksManager.getInstance()).thenReturn(rm);
// Players Manager // Players Manager
when(plugin.getPlayers()).thenReturn(pm); when(plugin.getPlayers()).thenReturn(pm);

View File

@ -43,7 +43,6 @@ import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager; import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest; import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -87,8 +86,6 @@ public class AdminInfoCommandTest extends RanksManagerBeforeClassTest {
// IWM // IWM
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Bukkit // Bukkit
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
@ -193,7 +190,7 @@ public class AdminInfoCommandTest extends RanksManagerBeforeClassTest {
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-members-title");
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "");
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "-400,0,-400", "[xz2]", "400,0,400"); verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "-400,0,-400", "[xz2]", "400,0,400");
@ -215,7 +212,7 @@ public class AdminInfoCommandTest extends RanksManagerBeforeClassTest {
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-members-title");
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "");
verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-protection-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "-400,0,-400", "[xz2]", "400,0,400"); verify(user).sendMessage("commands.admin.info.island-coords", "[xz1]", "-400,0,-400", "[xz2]", "400,0,400");

View File

@ -5,7 +5,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; 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;
@ -57,7 +56,6 @@ public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
@Mock @Mock
private PlayersManager pm; private PlayersManager pm;
private RanksManager rm;
private AdminSetrankCommand c; private AdminSetrankCommand c;
private UUID targetUUID; private UUID targetUUID;
@ -71,10 +69,6 @@ public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
super.setUp(); super.setUp();
Util.setPlugin(plugin); Util.setPlugin(plugin);
// Ranks Manager
rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Players Manager // Players Manager
when(plugin.getPlayers()).thenReturn(pm); when(plugin.getPlayers()).thenReturn(pm);
@ -212,8 +206,7 @@ public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
when(im.getIsland(any(), any(UUID.class))).thenReturn(island); when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(island.getCenter()).thenReturn(location); when(island.getCenter()).thenReturn(location);
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member"))); assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"), eq("[from]"), eq("ranks.sub-owner"), eq("[to]"), verify(user).sendMessage("commands.admin.setrank.rank-set", "[from]", "", "[to]", "", "[name]", null);
eq("ranks.member"), eq("[name]"), eq(null));
} }
/** /**

View File

@ -52,7 +52,6 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager; import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest; import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -176,10 +175,6 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
FlagsManager fm = new FlagsManager(plugin); FlagsManager fm = new FlagsManager(plugin);
when(plugin.getFlagsManager()).thenReturn(fm); when(plugin.getFlagsManager()).thenReturn(fm);
// RnksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
asc = new AdminSettingsCommand(ac); asc = new AdminSettingsCommand(ac);
} }

View File

@ -32,7 +32,6 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest; import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
/** /**
@ -69,11 +68,6 @@ public class DefaultPlayerCommandTest extends RanksManagerBeforeClassTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Addon
// User // User
when(user.getUniqueId()).thenReturn(UUID.randomUUID()); when(user.getUniqueId()).thenReturn(UUID.randomUUID());

View File

@ -165,10 +165,6 @@ public class IslandBanCommandTest extends RanksManagerBeforeClassTest {
when(targetPlayer.hasPermission(anyString())).thenReturn(false); when(targetPlayer.hasPermission(anyString())).thenReturn(false);
User.getInstance(targetPlayer); User.getInstance(targetPlayer);
// Ranks Manager
rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Island Ban Command // Island Ban Command
ibc = new IslandBanCommand(ic); ibc = new IslandBanCommand(ic);
@ -212,7 +208,7 @@ public class IslandBanCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill"))); assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
@Test @Test

View File

@ -116,10 +116,6 @@ public class IslandBanlistCommandTest extends RanksManagerBeforeClassTest {
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock"); when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -155,7 +151,7 @@ public class IslandBanlistCommandTest extends RanksManagerBeforeClassTest {
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandBanlistCommand iubc = new IslandBanlistCommand(ic); IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.emptyList())); assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -84,10 +84,6 @@ public class IslandDeletehomeCommandTest extends RanksManagerBeforeClassTest {
CommandsManager cm = mock(CommandsManager.class); CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm); when(plugin.getCommandsManager()).thenReturn(cm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Addon // Addon
GameModeAddon addon = mock(GameModeAddon.class); GameModeAddon addon = mock(GameModeAddon.class);
@ -192,8 +188,7 @@ public class IslandDeletehomeCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(user)).thenReturn(RanksManager.COOP_RANK); when(island.getRank(user)).thenReturn(RanksManager.COOP_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(idh.canExecute(user, "label", List.of("something"))); assertFalse(idh.canExecute(user, "label", List.of("something")));
verify(user).sendMessage("general.errors.insufficient-rank", verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
TextVariables.RANK, "ranks.coop");
} }
/** /**

View File

@ -158,10 +158,6 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager); when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer); when(placeholdersManager.replacePlaceholders(any(), any())).thenAnswer(answer);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Class // Class
iec = new IslandExpelCommand(ic); iec = new IslandExpelCommand(ic);
} }
@ -248,7 +244,7 @@ public class IslandExpelCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK); when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty"))); assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.visitor")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -43,7 +43,6 @@ import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager; import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlaceholdersManager; import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest; import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -87,8 +86,6 @@ public class IslandInfoCommandTest extends RanksManagerBeforeClassTest {
// IWM // IWM
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Bukkit // Bukkit
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS); PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
@ -189,7 +186,7 @@ public class IslandInfoCommandTest extends RanksManagerBeforeClassTest {
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-members-title");
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "");
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100"); verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "-100,0,-100", "[xz2]", "99,0,99"); verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "-100,0,-100", "[xz2]", "99,0,99");
@ -206,7 +203,7 @@ public class IslandInfoCommandTest extends RanksManagerBeforeClassTest {
verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0"); verify(user).sendMessage("commands.admin.info.deaths", "[number]", "0");
verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0"); verify(user).sendMessage("commands.admin.info.resets-left", "[number]", "0", "[total]", "0");
verify(user).sendMessage("commands.admin.info.team-members-title"); verify(user).sendMessage("commands.admin.info.team-members-title");
verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "ranks.owner"); verify(user).sendMessage("commands.admin.info.team-owner-format", "[name]", null, "[rank]", "");
verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0"); verify(user).sendMessage("commands.admin.info.island-center", "[xyz]", "0,0,0");
verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100"); verify(user).sendMessage("commands.admin.info.protection-range", "[range]", "100");
verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "-100,0,-100", "[xz2]", "99,0,99"); verify(user).sendMessage("commands.admin.info.protection-coords", "[xz1]", "-100,0,-100", "[xz2]", "99,0,99");

View File

@ -137,11 +137,6 @@ public class IslandSetnameCommandTest {
// Placeholder manager // Placeholder manager
when(plugin.getPlaceholdersManager()).thenReturn(phm); when(plugin.getPlaceholdersManager()).thenReturn(phm);
// Ranks Manager
rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Test // Test
isc = new IslandSetnameCommand(ic); isc = new IslandSetnameCommand(ic);
} }

View File

@ -125,10 +125,6 @@ public class IslandUnbanCommandTest extends RanksManagerBeforeClassTest {
PluginManager pim = mock(PluginManager.class); PluginManager pim = mock(PluginManager.class);
when(Bukkit.getPluginManager()).thenReturn(pim); when(Bukkit.getPluginManager()).thenReturn(pim);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -173,7 +169,7 @@ public class IslandUnbanCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill"))); assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type; import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager; import world.bentobox.bentobox.managers.CommandsManager;
@ -123,10 +122,6 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock."); when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock.");
// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Command under test // Command under test
tc = new IslandTeamCommand(ic); tc = new IslandTeamCommand(ic);
} }
@ -153,33 +148,23 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
} }
/** /**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. * Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testExecuteUserStringListOfStringNoIsland() { public void testCanExecuteUserStringListOfStringNoIsland() {
when(im.getPrimaryIsland(world, uuid)).thenReturn(null); when(im.getPrimaryIsland(world, uuid)).thenReturn(null);
assertFalse(tc.execute(user, "team", Collections.emptyList())); assertFalse(tc.canExecute(user, "team", Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.no-island")); verify(user).sendMessage(eq("general.errors.no-island"));
} }
/** /**
* Test method for * Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
* {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */
@Test @Test
public void testExecuteUserStringListOfStringIslandIsNotFull() { public void testCanExecuteUserStringListOfStringIslandIsFull() {
assertTrue(tc.execute(user, "team", Collections.emptyList()));
verify(user).sendMessage(eq("commands.island.team.invite.you-can-invite"), eq(TextVariables.NUMBER), eq("3"));
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringIslandIsFull() {
// Max members // Max members
when(im.getMaxMembers(eq(island), eq(RanksManager.MEMBER_RANK))).thenReturn(0); when(im.getMaxMembers(eq(island), eq(RanksManager.MEMBER_RANK))).thenReturn(0);
assertTrue(tc.execute(user, "team", Collections.emptyList())); assertTrue(tc.canExecute(user, "team", Collections.emptyList()));
verify(user).sendMessage(eq("commands.island.team.invite.errors.island-is-full")); verify(user).sendMessage(eq("commands.island.team.invite.errors.island-is-full"));
} }

View File

@ -137,10 +137,6 @@ public class IslandTeamCoopCommandTest extends RanksManagerBeforeClassTest {
// Placeholder manager // Placeholder manager
when(plugin.getPlaceholdersManager()).thenReturn(phm); when(plugin.getPlaceholdersManager()).thenReturn(phm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -164,7 +160,7 @@ public class IslandTeamCoopCommandTest extends RanksManagerBeforeClassTest {
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic); IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -11,6 +11,7 @@ import static org.mockito.Mockito.never;
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.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -19,6 +20,10 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
@ -92,6 +97,10 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
// Settings // Settings
when(plugin.getSettings()).thenReturn(s); when(plugin.getSettings()).thenReturn(s);
// Data folder for panels
when(plugin.getDataFolder())
.thenReturn(new File("src" + File.separator + "main" + File.separator + "resources"));
// Player & users // Player & users
PowerMockito.mockStatic(User.class); PowerMockito.mockStatic(User.class);
@ -165,9 +174,14 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
// Parent command // Parent command
when(ic.getTopLabel()).thenReturn("island"); when(ic.getTopLabel()).thenReturn("island");
// Ranks Manager // Mock item factory (for itemstacks)
RanksManager rm = new RanksManager(); ItemFactory itemFactory = mock(ItemFactory.class);
when(plugin.getRanksManager()).thenReturn(rm); ItemMeta bannerMeta = mock(ItemMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(bannerMeta);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
Inventory inventory = mock(Inventory.class);
when(Bukkit.createInventory(eq(null), anyInt(), any())).thenReturn(inventory);
when(Bukkit.createInventory(eq(null), any(InventoryType.class), any())).thenReturn(inventory);
// Command under test // Command under test
itl = new IslandTeamInviteCommand(ic); itl = new IslandTeamInviteCommand(ic);
@ -204,7 +218,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(itl.canExecute(user, itl.getLabel(), List.of("target"))); assertFalse(itl.canExecute(user, itl.getLabel(), List.of("target")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**
@ -224,9 +238,9 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testCanExecuteNoTarget() { public void testCanExecuteNoTarget() {
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList())); assertTrue(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show help // Show panel
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock"); verify(p).openInventory(any(Inventory.class));
} }
/** /**

View File

@ -7,6 +7,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
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.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -181,10 +182,6 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid)); when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid));
when(island.getRankCommand(anyString())).thenReturn(RanksManager.VISITOR_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.VISITOR_RANK);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Ranks // Ranks
when(island.getRank(uuid)).thenReturn(RanksManager.OWNER_RANK); when(island.getRank(uuid)).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(user)).thenReturn(RanksManager.OWNER_RANK); when(island.getRank(user)).thenReturn(RanksManager.OWNER_RANK);
@ -192,18 +189,18 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
} }
/** /**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteNoTeam() { public void testExecuteNoTeam() {
when(im.inTeam(any(), eq(uuid))).thenReturn(false); when(im.inTeam(any(), eq(uuid))).thenReturn(false);
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList())); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.no-team")); verify(user).sendMessage(eq("general.errors.no-team"));
} }
/** /**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteLowerTeamRank() { public void testExecuteLowerTeamRank() {
@ -216,12 +213,12 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID)); when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch")); verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
} }
/** /**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteEqualTeamRank() { public void testExecuteEqualTeamRank() {
@ -234,7 +231,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID)); when(island.getMemberSet()).thenReturn(ImmutableSet.of(notUUID));
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch")); verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick-rank"), eq(TextVariables.NAME), eq("poslovitch"));
} }
@ -258,7 +255,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
} }
/** /**
* Test method for {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * Test method for {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteNoCommandRank() { public void testExecuteNoCommandRank() {
@ -266,61 +263,61 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK);
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList())); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**
* Test method for * Test method for
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteNoTarget() { public void testExecuteNoTarget() {
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.emptyList())); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));
// Show help // Show help
} }
/** /**
* Test method for * Test method for
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteUnknownPlayer() { public void testExecuteUnknownPlayer() {
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
when(pm.getUUID(any())).thenReturn(null); when(pm.getUUID(any())).thenReturn(null);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage("general.errors.unknown-player", "[name]", "poslovitch"); verify(user).sendMessage("general.errors.unknown-player", "[name]", "poslovitch");
} }
/** /**
* Test method for * Test method for
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteSamePlayer() { public void testExecuteSamePlayer() {
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
when(pm.getUUID(any())).thenReturn(uuid); when(pm.getUUID(any())).thenReturn(uuid);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick")); verify(user).sendMessage(eq("commands.island.team.kick.cannot-kick"));
} }
/** /**
* Test method for * Test method for
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteDifferentPlayerNotInTeam() { public void testExecuteDifferentPlayerNotInTeam() {
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
when(pm.getUUID(any())).thenReturn(notUUID); when(pm.getUUID(any())).thenReturn(notUUID);
// when(im.getMembers(any(), any())).thenReturn(Collections.emptySet()); // when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("general.errors.not-in-team")); verify(user).sendMessage(eq("general.errors.not-in-team"));
} }
/** /**
* Test method for * Test method for
* {@link IslandTeamKickCommand#execute(User, String, java.util.List)} * {@link IslandTeamKickCommand#canExecute(User, String, java.util.List)}
*/ */
@Test @Test
public void testExecuteDifferentPlayerNoRank() { public void testExecuteDifferentPlayerNoRank() {
@ -328,8 +325,8 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
when(pm.getUUID(any())).thenReturn(notUUID); when(pm.getUUID(any())).thenReturn(notUUID);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK); when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.visitor")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**
@ -368,7 +365,7 @@ public class IslandTeamKickCommandTest extends RanksManagerBeforeClassTest {
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch"))); assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(im).removePlayer(any(World.class), eq(notUUID)); verify(im).removePlayer(any(World.class), eq(notUUID));
verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich"); verify(user).sendMessage("commands.island.team.kick.success", TextVariables.NAME, "poslovitch", TextVariables.DISPLAY_NAME, "&Cposlovich");
verify(target, Mockito.never()).getInventory(); verify(target, never()).getInventory();
} }

View File

@ -119,9 +119,7 @@ public class IslandTeamPromoteCommandTest extends RanksManagerBeforeClassTest {
// In team // In team
when(im.inTeam(world, uuid)).thenReturn(true); when(im.inTeam(world, uuid)).thenReturn(true);
// Ranks Manager // Ranks
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK); // Allow sub owners when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK); // Allow sub owners
when(island.getRank(user)).thenReturn(RanksManager.SUB_OWNER_RANK); when(island.getRank(user)).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(target)).thenReturn(RanksManager.SUB_OWNER_RANK); when(island.getRank(target)).thenReturn(RanksManager.SUB_OWNER_RANK);
@ -194,7 +192,7 @@ public class IslandTeamPromoteCommandTest extends RanksManagerBeforeClassTest {
public void testCanExecuteUserStringListOfStringInsufficientRank() { public void testCanExecuteUserStringListOfStringInsufficientRank() {
when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(user)).thenReturn(RanksManager.MEMBER_RANK);
assertFalse(ipc.canExecute(user, "promote", List.of("tastybento"))); assertFalse(ipc.canExecute(user, "promote", List.of("tastybento")));
verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, RanksManager.MEMBER_RANK_REF); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**
@ -256,10 +254,12 @@ public class IslandTeamPromoteCommandTest extends RanksManagerBeforeClassTest {
@Test @Test
public void testExecuteUserStringListOfString() { public void testExecuteUserStringListOfString() {
when(island.getRank(target)).thenReturn(RanksManager.MEMBER_RANK); when(island.getRank(target)).thenReturn(RanksManager.MEMBER_RANK);
when(rm.getRankUpValue(RanksManager.MEMBER_RANK)).thenReturn(RanksManager.SUB_OWNER_RANK);
ipc.canExecute(user, "promote", List.of("target")); ipc.canExecute(user, "promote", List.of("target"));
assertTrue(ipc.execute(user, "promote", List.of("target"))); assertTrue(ipc.execute(user, "promote", List.of("target")));
verify(island).setRank(target, RanksManager.SUB_OWNER_RANK); verify(island).setRank(target, RanksManager.SUB_OWNER_RANK);
verify(user).sendMessage("commands.island.team.promote.success", TextVariables.NAME, "target", TextVariables.RANK, RanksManager.SUB_OWNER_RANK_REF, TextVariables.DISPLAY_NAME, "Target"); verify(user).sendMessage("commands.island.team.promote.success", TextVariables.NAME, "target",
TextVariables.RANK, "", TextVariables.DISPLAY_NAME, "Target");
} }

View File

@ -147,10 +147,6 @@ public class IslandTeamTrustCommandTest extends RanksManagerBeforeClassTest {
// Placeholder manager // Placeholder manager
when(plugin.getPlaceholdersManager()).thenReturn(phm); when(plugin.getPlaceholdersManager()).thenReturn(phm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -174,7 +170,7 @@ public class IslandTeamTrustCommandTest extends RanksManagerBeforeClassTest {
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic); IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill"))); assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -134,10 +134,6 @@ public class IslandTeamUncoopCommandTest extends RanksManagerBeforeClassTest {
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock"); when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -161,7 +157,7 @@ public class IslandTeamUncoopCommandTest extends RanksManagerBeforeClassTest {
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic); IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill"))); assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -134,10 +134,6 @@ public class IslandTeamUntrustCommandTest extends RanksManagerBeforeClassTest {
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock"); when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Ranks Manager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
} }
/** /**
@ -161,7 +157,7 @@ public class IslandTeamUntrustCommandTest extends RanksManagerBeforeClassTest {
when(island.getRankCommand(any())).thenReturn(RanksManager.OWNER_RANK); when(island.getRankCommand(any())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic); IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill"))); assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage(eq("general.errors.insufficient-rank"), eq(TextVariables.RANK), eq("ranks.member")); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
} }
/** /**

View File

@ -57,7 +57,7 @@ import world.bentobox.bentobox.util.Util;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class }) @PrepareForTest({ BentoBox.class, Util.class, Bukkit.class, RanksManager.class })
public class FlagTest { public class FlagTest {
private Flag f; private Flag f;
@ -376,8 +376,9 @@ public class FlagTest {
when(im.getIslandAt(any(Location.class))).thenReturn(oL); when(im.getIslandAt(any(Location.class))).thenReturn(oL);
when(plugin.getIslands()).thenReturn(im); when(plugin.getIslands()).thenReturn(im);
PowerMockito.mockStatic(RanksManager.class);
RanksManager rm = mock(RanksManager.class); RanksManager rm = mock(RanksManager.class);
when(plugin.getRanksManager()).thenReturn(rm); when(RanksManager.getInstance()).thenReturn(rm);
when(rm.getRank(RanksManager.VISITOR_RANK)).thenReturn("Visitor"); when(rm.getRank(RanksManager.VISITOR_RANK)).thenReturn("Visitor");
when(rm.getRank(RanksManager.OWNER_RANK)).thenReturn("Owner"); when(rm.getRank(RanksManager.OWNER_RANK)).thenReturn("Owner");

View File

@ -52,7 +52,7 @@ import world.bentobox.bentobox.panels.settings.SettingsTab;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class }) @PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class, RanksManager.class })
public class CycleClickTest { public class CycleClickTest {
private static final Integer PROTECTION_RANGE = 200; private static final Integer PROTECTION_RANGE = 200;
@ -77,11 +77,11 @@ public class CycleClickTest {
@Mock @Mock
private IslandWorldManager iwm; private IslandWorldManager iwm;
@Mock @Mock
private RanksManager rm;
@Mock
private PluginManager pim; private PluginManager pim;
@Mock @Mock
private SettingsTab settingsTab; private SettingsTab settingsTab;
@Mock
private RanksManager rm;
/** /**
* @throws java.lang.Exception - exception * @throws java.lang.Exception - exception
@ -181,12 +181,11 @@ public class CycleClickTest {
when(fm.getFlag(anyString())).thenReturn(Optional.of(flag)); when(fm.getFlag(anyString())).thenReturn(Optional.of(flag));
when(plugin.getFlagsManager()).thenReturn(fm); when(plugin.getFlagsManager()).thenReturn(fm);
// Ranks Manager
when(plugin.getRanksManager()).thenReturn(rm);
// Provide a current rank value - member // Provide a current rank value - member
when(island.getFlag(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
PowerMockito.mockStatic(RanksManager.class);
when(RanksManager.getInstance().getInstance()).thenReturn(rm);
when(rm.getRankUpValue(eq(RanksManager.VISITOR_RANK))).thenReturn(RanksManager.COOP_RANK); when(rm.getRankUpValue(eq(RanksManager.VISITOR_RANK))).thenReturn(RanksManager.COOP_RANK);
when(rm.getRankUpValue(eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.TRUSTED_RANK); when(rm.getRankUpValue(eq(RanksManager.COOP_RANK))).thenReturn(RanksManager.TRUSTED_RANK);
when(rm.getRankUpValue(eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.MEMBER_RANK); when(rm.getRankUpValue(eq(RanksManager.TRUSTED_RANK))).thenReturn(RanksManager.MEMBER_RANK);
@ -310,18 +309,5 @@ public class CycleClickTest {
verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class)); verify(pim, times(2)).callEvent(any(FlagProtectionChangeEvent.class));
} }
@Test
public void testNotOwner() {
UUID u = UUID.randomUUID();
when(island.getOwner()).thenReturn(u);
verify(plugin, Mockito.never()).getRanksManager();
}
@Test
public void testNullIsland() {
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
verify(plugin, Mockito.never()).getRanksManager();
}
} }

View File

@ -81,7 +81,6 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
private @Nullable Island island; private @Nullable Island island;
private UUID uuid = UUID.randomUUID(); private UUID uuid = UUID.randomUUID();
private RanksManager rm;
@Mock @Mock
private CommandsManager cm; private CommandsManager cm;
@Mock @Mock
@ -130,9 +129,6 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
// Util // Util
PowerMockito.mockStatic(Util.class, Mockito.CALLS_REAL_METHODS); PowerMockito.mockStatic(Util.class, Mockito.CALLS_REAL_METHODS);
when(Util.getWorld(any())).thenReturn(world); when(Util.getWorld(any())).thenReturn(world);
// RanksManager
rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
// Commands Manager // Commands Manager
when(plugin.getCommandsManager()).thenReturn(cm); when(plugin.getCommandsManager()).thenReturn(cm);
Map<String, CompositeCommand> map = new HashMap<>(); Map<String, CompositeCommand> map = new HashMap<>();
@ -174,7 +170,7 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
public void testOnClickNoFlag() { public void testOnClickNoFlag() {
when(island.isAllowed(user, Flags.CHANGE_SETTINGS)).thenReturn(false); when(island.isAllowed(user, Flags.CHANGE_SETTINGS)).thenReturn(false);
assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0)); assertTrue(crcl.onClick(panel, user, ClickType.LEFT, 0));
verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "ranks.visitor"); verify(user).sendMessage("general.errors.insufficient-rank", TextVariables.RANK, "");
verify(player).playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); verify(player).playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
} }
@ -227,9 +223,9 @@ public class CommandRankClickListenerTest extends RanksManagerBeforeClassTest {
PanelItem pi = crcl.getPanelItem("test", user, world); PanelItem pi = crcl.getPanelItem("test", user, world);
assertEquals(Material.MAP, pi.getItem().getType()); assertEquals(Material.MAP, pi.getItem().getType());
assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0)); assertEquals("protection.panel.flag-item.description-layout", pi.getDescription().get(0));
assertEquals("protection.panel.flag-item.minimal-rankranks.member", pi.getDescription().get(1)); //assertEquals("protection.panel.flag-item.minimal-rankranks.member", pi.getDescription().get(1));
assertEquals("protection.panel.flag-item.allowed-rankranks.sub-owner", pi.getDescription().get(2)); //assertEquals("protection.panel.flag-item.allowed-rankranks.sub-owner", pi.getDescription().get(2));
assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(3)); //assertEquals("protection.panel.flag-item.allowed-rankranks.owner", pi.getDescription().get(3));
assertTrue(pi.getClickHandler().isPresent()); assertTrue(pi.getClickHandler().isPresent());
assertEquals("test", pi.getName()); assertEquals("test", pi.getName());
} }

View File

@ -18,11 +18,15 @@ 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.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.TestWorldSettings; import world.bentobox.bentobox.TestWorldSettings;
import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
@ -32,15 +36,17 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager; import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.managers.RanksManagerBeforeClassTest;
/** /**
* @author tastybento * @author tastybento
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
public class GameModePlaceholderTest extends RanksManagerBeforeClassTest { @PrepareForTest(RanksManager.class)
public class GameModePlaceholderTest {
@Mock
private BentoBox plugin;
@Mock @Mock
private GameModeAddon addon; private GameModeAddon addon;
@Mock @Mock
@ -56,7 +62,6 @@ public class GameModePlaceholderTest extends RanksManagerBeforeClassTest {
private IslandWorldManager iwm; private IslandWorldManager iwm;
@Mock @Mock
private IslandsManager im; private IslandsManager im;
private RanksManager rm;
@Mock @Mock
private @Nullable Location location; private @Nullable Location location;
@ -64,8 +69,7 @@ public class GameModePlaceholderTest extends RanksManagerBeforeClassTest {
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); PowerMockito.mockStatic(RanksManager.class, Mockito.RETURNS_MOCKS);
rm = new RanksManager();
uuid = UUID.randomUUID(); uuid = UUID.randomUUID();
when(addon.getPlayers()).thenReturn(pm); when(addon.getPlayers()).thenReturn(pm);
when(addon.getIslands()).thenReturn(im); when(addon.getIslands()).thenReturn(im);
@ -87,7 +91,6 @@ public class GameModePlaceholderTest extends RanksManagerBeforeClassTest {
when(addon.getWorldSettings()).thenReturn(ws); when(addon.getWorldSettings()).thenReturn(ws);
when(pm.getName(any())).thenReturn("tastybento"); when(pm.getName(any())).thenReturn("tastybento");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(plugin.getRanksManager()).thenReturn(rm);
when(user.getTranslation(anyString())) when(user.getTranslation(anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class)); .thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getLocation()).thenReturn(location); when(user.getLocation()).thenReturn(location);
@ -160,7 +163,7 @@ public class GameModePlaceholderTest extends RanksManagerBeforeClassTest {
assertEquals("true", GameModePlaceholder.HAS_ISLAND.getReplacer().onReplace(addon, user, island)); assertEquals("true", GameModePlaceholder.HAS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("false", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island)); assertEquals("false", GameModePlaceholder.ON_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("true", GameModePlaceholder.OWNS_ISLAND.getReplacer().onReplace(addon, user, island)); assertEquals("true", GameModePlaceholder.OWNS_ISLAND.getReplacer().onReplace(addon, user, island));
assertEquals("ranks.owner", GameModePlaceholder.RANK.getReplacer().onReplace(addon, user, island)); assertEquals("", GameModePlaceholder.RANK.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.RESETS.getReplacer().onReplace(addon, user, island)); assertEquals("0", GameModePlaceholder.RESETS.getReplacer().onReplace(addon, user, island));
assertEquals("0", GameModePlaceholder.RESETS_LEFT.getReplacer().onReplace(addon, user, island)); assertEquals("0", GameModePlaceholder.RESETS_LEFT.getReplacer().onReplace(addon, user, island));
} }

View File

@ -1,21 +1,17 @@
package world.bentobox.bentobox.managers; package world.bentobox.bentobox.managers;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.beans.IntrospectionException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Comparator; import java.util.Comparator;
import java.util.concurrent.CompletableFuture; import java.util.Map;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -26,7 +22,6 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseSetup; import world.bentobox.bentobox.database.DatabaseSetup;
/** /**
@ -34,31 +29,49 @@ import world.bentobox.bentobox.database.DatabaseSetup;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, DatabaseSetup.class }) @PrepareForTest({ BentoBox.class, DatabaseSetup.class, RanksManager.class })
public abstract class RanksManagerBeforeClassTest { public abstract class RanksManagerBeforeClassTest {
private static AbstractDatabaseHandler<Object> h; // Constants that define the hard coded rank values
public static final String ADMIN_RANK_REF = "ranks.admin";
public static final String MOD_RANK_REF = "ranks.mod";
public static final String OWNER_RANK_REF = "ranks.owner";
public static final String SUB_OWNER_RANK_REF = "ranks.sub-owner";
public static final String MEMBER_RANK_REF = "ranks.member";
public static final String TRUSTED_RANK_REF = "ranks.trusted";
public static final String COOP_RANK_REF = "ranks.coop";
public static final String VISITOR_RANK_REF = "ranks.visitor";
public static final String BANNED_RANK_REF = "ranks.banned";
public static final int ADMIN_RANK = 10000;
public static final int MOD_RANK = 5000;
public static final int OWNER_RANK = 1000;
public static final int SUB_OWNER_RANK = 900;
public static final int MEMBER_RANK = 500;
public static final int TRUSTED_RANK = 400;
public static final int COOP_RANK = 200;
public static final int VISITOR_RANK = 0;
public static final int BANNED_RANK = -1;
// The store of ranks
public static final Map<String, Integer> DEFAULT_RANKS = Map.of(ADMIN_RANK_REF, ADMIN_RANK, MOD_RANK_REF, MOD_RANK,
OWNER_RANK_REF, OWNER_RANK, SUB_OWNER_RANK_REF, SUB_OWNER_RANK, MEMBER_RANK_REF, MEMBER_RANK,
TRUSTED_RANK_REF, TRUSTED_RANK, COOP_RANK_REF, COOP_RANK, VISITOR_RANK_REF, VISITOR_RANK, BANNED_RANK_REF,
BANNED_RANK);
@Mock @Mock
public BentoBox plugin; public BentoBox plugin;
@Mock
@SuppressWarnings("unchecked") public RanksManager rm;
@BeforeClass
public static void beforeClass() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
// This has to be done beforeClass otherwise the tests will interfere with each other
h = mock(AbstractDatabaseHandler.class);
// Database
PowerMockito.mockStatic(DatabaseSetup.class);
DatabaseSetup dbSetup = mock(DatabaseSetup.class);
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
when(dbSetup.getHandler(any())).thenReturn(h);
when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true));
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Set up plugin // Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// RanksManager
PowerMockito.mockStatic(RanksManager.class, Mockito.RETURNS_MOCKS);
when(RanksManager.getInstance()).thenReturn(rm);
when(rm.getRanks()).thenReturn(DEFAULT_RANKS);
when(rm.getRank(anyInt())).thenReturn("");
} }
@After @After

View File

@ -3,15 +3,35 @@ package world.bentobox.bentobox.managers;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.beans.IntrospectionException;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
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.Mock;
import org.mockito.Mockito;
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 world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseSetup; import world.bentobox.bentobox.database.DatabaseSetup;
/** /**
@ -19,17 +39,46 @@ import world.bentobox.bentobox.database.DatabaseSetup;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({ DatabaseSetup.class, }) @PrepareForTest({ BentoBox.class, DatabaseSetup.class })
public class RanksManagerTest extends RanksManagerBeforeClassTest { public class RanksManagerTest {
public static RanksManager ranksManager; private static AbstractDatabaseHandler<Object> h;
@Mock
public BentoBox plugin;
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() throws IllegalAccessException, InvocationTargetException, IntrospectionException {
// This has to be done beforeClass otherwise the tests will interfere with each other
h = mock(AbstractDatabaseHandler.class);
// Database
PowerMockito.mockStatic(DatabaseSetup.class);
DatabaseSetup dbSetup = mock(DatabaseSetup.class);
when(DatabaseSetup.getDatabase()).thenReturn(dbSetup);
when(dbSetup.getHandler(any())).thenReturn(h);
when(h.saveObject(any())).thenReturn(CompletableFuture.completedFuture(true));
}
/**
*/
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); // Set up plugin
ranksManager = new RanksManager(); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
}
@After
public void tearDown() throws IOException {
User.clearUsers();
Mockito.framework().clearInlineMocks();
deleteAll(new File("database"));
deleteAll(new File("database_backup"));
}
private void deleteAll(File file) throws IOException {
if (file.exists()) {
Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
} }
/** /**
@ -37,7 +86,7 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testAddRank() { public void testAddRank() {
assertTrue(ranksManager.addRank("test.rank.reference", 750)); assertTrue(RanksManager.getInstance().addRank("test.rank.reference", 750));
} }
/** /**
@ -45,10 +94,10 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testRemoveRank() { public void testRemoveRank() {
assertTrue(ranksManager.addRank("test.rank.reference2", 650)); assertTrue(RanksManager.getInstance().addRank("test.rank.reference2", 650));
assertTrue(ranksManager.removeRank("test.rank.reference2")); assertTrue(RanksManager.getInstance().removeRank("test.rank.reference2"));
// Second time should fail // Second time should fail
assertFalse(ranksManager.removeRank("test.rank.reference2")); assertFalse(RanksManager.getInstance().removeRank("test.rank.reference2"));
} }
/** /**
@ -56,8 +105,8 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testGetRankValue() { public void testGetRankValue() {
ranksManager.addRank("test.rank.reference.value", 600); RanksManager.getInstance().addRank("test.rank.reference.value", 600);
assertEquals(600, ranksManager.getRankValue("test.rank.reference.value")); assertEquals(600, RanksManager.getInstance().getRankValue("test.rank.reference.value"));
} }
/** /**
@ -65,7 +114,7 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testGetRanks() { public void testGetRanks() {
Map<String, Integer> ranks = ranksManager.getRanks(); Map<String, Integer> ranks = RanksManager.getInstance().getRanks();
assertTrue(ranks.containsKey(RanksManager.BANNED_RANK_REF)); assertTrue(ranks.containsKey(RanksManager.BANNED_RANK_REF));
assertTrue(ranks.containsKey(RanksManager.VISITOR_RANK_REF)); assertTrue(ranks.containsKey(RanksManager.VISITOR_RANK_REF));
assertTrue(ranks.containsKey(RanksManager.MEMBER_RANK_REF)); assertTrue(ranks.containsKey(RanksManager.MEMBER_RANK_REF));
@ -77,12 +126,12 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testGetNextRankValue() { public void testGetNextRankValue() {
assertEquals(RanksManager.BANNED_RANK, ranksManager.getRankUpValue(-20)); assertEquals(RanksManager.BANNED_RANK, RanksManager.getInstance().getRankUpValue(-20));
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankUpValue(RanksManager.BANNED_RANK)); assertEquals(RanksManager.VISITOR_RANK, RanksManager.getInstance().getRankUpValue(RanksManager.BANNED_RANK));
assertEquals(RanksManager.COOP_RANK, ranksManager.getRankUpValue(RanksManager.VISITOR_RANK)); assertEquals(RanksManager.COOP_RANK, RanksManager.getInstance().getRankUpValue(RanksManager.VISITOR_RANK));
assertEquals(RanksManager.SUB_OWNER_RANK, ranksManager.getRankUpValue(RanksManager.MEMBER_RANK)); assertEquals(RanksManager.SUB_OWNER_RANK, RanksManager.getInstance().getRankUpValue(800));
assertEquals(RanksManager.OWNER_RANK, ranksManager.getRankUpValue(RanksManager.OWNER_RANK)); assertEquals(RanksManager.OWNER_RANK, RanksManager.getInstance().getRankUpValue(RanksManager.OWNER_RANK));
assertEquals(RanksManager.OWNER_RANK, ranksManager.getRankUpValue(2000)); assertEquals(RanksManager.OWNER_RANK, RanksManager.getInstance().getRankUpValue(2000));
} }
/** /**
@ -91,10 +140,10 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
@Test @Test
public void testGetPreviousRankValue() { public void testGetPreviousRankValue() {
// Lowest rank is Visitor // Lowest rank is Visitor
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankDownValue(-20)); assertEquals(RanksManager.VISITOR_RANK, RanksManager.getInstance().getRankDownValue(-20));
assertEquals(RanksManager.VISITOR_RANK, ranksManager.getRankDownValue(RanksManager.VISITOR_RANK)); assertEquals(RanksManager.VISITOR_RANK, RanksManager.getInstance().getRankDownValue(RanksManager.VISITOR_RANK));
assertEquals(RanksManager.TRUSTED_RANK, ranksManager.getRankDownValue(RanksManager.MEMBER_RANK)); assertEquals(RanksManager.TRUSTED_RANK, RanksManager.getInstance().getRankDownValue(RanksManager.MEMBER_RANK));
assertEquals(RanksManager.SUB_OWNER_RANK, ranksManager.getRankDownValue(RanksManager.OWNER_RANK)); assertEquals(RanksManager.SUB_OWNER_RANK, RanksManager.getInstance().getRankDownValue(RanksManager.OWNER_RANK));
} }
/** /**
@ -102,10 +151,10 @@ public class RanksManagerTest extends RanksManagerBeforeClassTest {
*/ */
@Test @Test
public void testGetRank() { public void testGetRank() {
assertEquals(RanksManager.BANNED_RANK_REF, ranksManager.getRank(RanksManager.BANNED_RANK)); assertEquals(RanksManager.BANNED_RANK_REF, RanksManager.getInstance().getRank(RanksManager.BANNED_RANK));
assertEquals(RanksManager.VISITOR_RANK_REF, ranksManager.getRank(RanksManager.VISITOR_RANK)); assertEquals(RanksManager.VISITOR_RANK_REF, RanksManager.getInstance().getRank(RanksManager.VISITOR_RANK));
assertEquals(RanksManager.MEMBER_RANK_REF, ranksManager.getRank(RanksManager.MEMBER_RANK)); assertEquals(RanksManager.MEMBER_RANK_REF, RanksManager.getInstance().getRank(RanksManager.MEMBER_RANK));
assertEquals(RanksManager.OWNER_RANK_REF, ranksManager.getRank(RanksManager.OWNER_RANK)); assertEquals(RanksManager.OWNER_RANK_REF, RanksManager.getInstance().getRank(RanksManager.OWNER_RANK));
assertEquals("", ranksManager.getRank(-999)); assertEquals("", RanksManager.getInstance().getRank(-999));
} }
} }