Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team gui #2251

Merged
merged 27 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
29a7fa5
WIP - add GUI for teams.
tastybento Dec 22, 2023
546b708
Merge branch 'develop' into team_gui
tastybento Dec 23, 2023
f40db47
WIP teams GUI
tastybento Dec 23, 2023
efa055b
Merge branch 'develop' into team_gui
tastybento Dec 25, 2023
bac0fe4
Moe WIP on team GUI
tastybento Dec 26, 2023
b2c4a2d
Merge branch 'develop' into team_gui
tastybento Dec 28, 2023
8d9a259
Modified file to avoid an NPE.
tastybento Dec 30, 2023
511b613
Minor refactor to prevent int to Integer warning.
tastybento Dec 30, 2023
63c7ad8
Use latest dependencies for tests to pass.
tastybento Dec 30, 2023
c6e5a43
Move to singleton pattern for RanksManager,
tastybento Dec 30, 2023
1958a71
Team GUI WIP
tastybento Jan 1, 2024
1d65566
Added support for kick, setowner, and leave.
tastybento Jan 3, 2024
7639c59
Added support for accepting and rejecting an invite.
tastybento Jan 3, 2024
de28bae
Fixed bugs with text and operations.
tastybento Jan 3, 2024
f290a2c
WIP for team invites.
tastybento Jan 4, 2024
5fcc203
Adds inviting to the GUI.
tastybento Jan 4, 2024
37de29b
Merge branch 'develop' into team_gui
tastybento Jan 4, 2024
3702870
Fix tests
tastybento Jan 5, 2024
7392e03
Fixed minor bugs reported by SonarCloud
tastybento Jan 5, 2024
1a702bc
Up Minecraft version and paper to 1.20.4 in POM
tastybento Jan 5, 2024
4e3a8e8
Added features based on Discord feedback.
tastybento Jan 5, 2024
ee0ed2c
Added back button.
tastybento Jan 5, 2024
803274b
Fixed bugs with teams and uncoop untrust etc of Ops.
tastybento Jan 7, 2024
256554e
Return to name search GUI if name not found.
tastybento Jan 8, 2024
3d3bd42
Added return to GUI for player search
tastybento Jan 8, 2024
2d2972c
Use Path.of
tastybento Jan 8, 2024
29fcbe4
Merge branch 'develop' into team_gui
tastybento Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
<version>3.11.1</version>
<scope>test</scope>
</dependency>
<!-- Spigot API -->
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class BentoBox extends JavaPlugin implements Listener {
private AddonsManager addonsManager;
private FlagsManager flagsManager;
private IslandWorldManager islandWorldManager;
private RanksManager ranksManager;
private BlueprintsManager blueprintsManager;
private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager;
Expand Down Expand Up @@ -141,7 +140,6 @@ public void onEnable(){
return;
}
islandsManager = new IslandsManager(this);
ranksManager = new RanksManager();

// Start head getter
headGetter = new HeadGetter(this);
Expand Down Expand Up @@ -429,9 +427,11 @@ public FlagsManager getFlagsManager() {

/**
* @return the ranksManager
* @deprecated Just use {@code RanksManager.getInstance()}
*/
@Deprecated(since = "2.0.0")
public RanksManager getRanksManager() {
return ranksManager;
return RanksManager.getInstance();
}

/**
Expand Down Expand Up @@ -466,6 +466,7 @@ public boolean loadSettings() {
return false;
}

log("Saving default panels...");
if (!Files.exists(Path.of(this.getDataFolder().getPath(), "panels", "island_creation_panel.yml"))) {
log("Saving default island_creation_panel...");
this.saveResource("panels/island_creation_panel.yml", false);
Expand All @@ -475,7 +476,6 @@ public boolean loadSettings() {
log("Saving default language_panel...");
this.saveResource("panels/language_panel.yml", false);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public boolean canExecute(User user, String label, List<String> args) {
@Override
public boolean execute(User user, String label, List<String> args) {
// Get rank
RanksManager rm = getPlugin().getRanksManager();
User target = User.getInstance(targetUUID);
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()));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class AdminSetrankCommand extends CompositeCommand {
private int rankValue;
private @Nullable UUID targetUUID;
private @Nullable UUID ownerUUID;
private RanksManager rm;

public AdminSetrankCommand(CompositeCommand adminCommand) {
super(adminCommand, "setrank");
Expand All @@ -36,7 +35,6 @@ public void setup() {
setOnlyPlayer(false);
setParametersHelp("commands.admin.setrank.parameters");
setDescription("commands.admin.setrank.description");
rm = getPlugin().getRanksManager();
}

@Override
Expand All @@ -53,7 +51,7 @@ public boolean canExecute(User user, String label, List<String> args) {
return false;
}
// Get rank
rankValue = rm.getRanks().entrySet().stream()
rankValue = RanksManager.getInstance().getRanks().entrySet().stream()
.filter(r -> user.getTranslation(r.getKey()).equalsIgnoreCase(args.get(1))).findFirst()
.map(Map.Entry::getValue).orElse(-999);
if (rankValue < RanksManager.BANNED_RANK) {
Expand Down Expand Up @@ -121,8 +119,8 @@ public boolean execute(User user, String label, List<String> args) {
ownerName = target.getName();
}
user.sendMessage("commands.admin.setrank.rank-set",
"[from]", user.getTranslation(rm.getRank(currentRank)),
"[to]", user.getTranslation(rm.getRank(rankValue)),
"[from]", user.getTranslation(RanksManager.getInstance().getRank(currentRank)), "[to]",
user.getTranslation(RanksManager.getInstance().getRank(rankValue)),
TextVariables.NAME, ownerName);
return true;
}
Expand All @@ -136,7 +134,7 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>

// Return the ranks
if (args.size() == 3) {
return Optional.of(getPlugin().getRanksManager().getRanks()
return Optional.of(RanksManager.getInstance().getRanks()
.entrySet().stream()
.filter(entry -> entry.getValue() > RanksManager.VISITOR_RANK)
.map(entry -> user.getTranslation(entry.getKey())).toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private boolean checkIslandSetting(User user, List<String> args) {
* @return true if rank is valid
*/
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
&& string.equalsIgnoreCase(ChatColor.stripColor(user.getTranslation(en.getKey())))) {
// We have a winner
Expand Down Expand Up @@ -277,8 +277,7 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
} else if (args.size() == 4) {
// Get flag in previous argument
options = getPlugin().getFlagsManager().getFlag(args.get(2).toUpperCase(Locale.ENGLISH)).map(f -> switch (f.getType()) {
case PROTECTION -> getPlugin().getRanksManager()
.getRanks().entrySet().stream()
case PROTECTION -> RanksManager.getInstance().getRanks().entrySet().stream()
.filter(en -> en.getValue() > RanksManager.BANNED_RANK && en.getValue() <= RanksManager.OWNER_RANK)
.map(Entry::getKey)
.map(user::getTranslation).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ public boolean execute(User user, String label, List<String> args) {

private Location getSpot(World world) {
Island island = getIslands().getIsland(world, targetUUID);
if (island != null && island.getSpawnPoint(world.getEnvironment()) != null) {
// Return the defined spawn point
return island.getSpawnPoint(world.getEnvironment());
if (island == null) {
return null;
}
// Return the default island protection center
return island.getProtectionCenter().toVector().toLocation(world);
return island.getSpawnPoint(world.getEnvironment()) != null ? island.getSpawnPoint(world.getEnvironment()) : island.getProtectionCenter().toVector().toLocation(world);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;

public class IslandBanCommand extends CompositeCommand {
Expand Down Expand Up @@ -55,7 +56,7 @@ public boolean canExecute(User user, String label, List<String> args) {
int rank = island.getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false;
}
// Get target player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;

public class IslandBanlistCommand extends CompositeCommand {

Expand Down Expand Up @@ -40,7 +41,8 @@ public boolean canExecute(User user, String label, List<String> args) {
island = getIslands().getIsland(getWorld(), user.getUniqueId());
int rank = Objects.requireNonNull(island).getRank(user);
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 true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean canExecute(User user, String label, List<String> args) {
int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
TextVariables.RANK, user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ public boolean canExecute(User user, String label, List<String> args) {
int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank", TextVariables.RANK,
user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false;
}
// Get target player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public boolean canExecute(User user, String label, List<String> args) {
// check command permission
int rank = Objects.requireNonNull(island).getRank(user);
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;


/**
Expand Down Expand Up @@ -41,7 +42,7 @@ public boolean canExecute(User user, String label, List<String> args)
int rank = Objects.requireNonNull(island).getRank(user);
if (rank < island.getRankCommand(getUsage())) {
user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK, user.getTranslation(getPlugin().getRanksManager().getRank(rank)));
TextVariables.RANK, user.getTranslation(RanksManager.getInstance().getRank(rank)));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public boolean canExecute(User user, String label, List<String> args) {

int rank = Objects.requireNonNull(island).getRank(user);
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;


/**
Expand Down Expand Up @@ -51,7 +52,8 @@ public boolean canExecute(User user, String label, List<String> args)
// Check command rank.
int rank = Objects.requireNonNull(island).getRank(user);
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;

/**
Expand Down Expand Up @@ -54,7 +55,8 @@ public boolean canExecute(User user, String label, List<String> args) {
Island island = getIslands().getIsland(getWorld(), user);
int rank = Objects.requireNonNull(island).getRank(user);
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;
}
// Get target player
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading