Skip to content

Commit

Permalink
fix: team help command (#104)
Browse files Browse the repository at this point in the history
*Avez vous lu le [Code de
Conduite](https://github.com/Margouta/PluginOpenMC/blob/main/CODE_OF_CONDUCT.md)?*:

*Votre code se compile t-il en local ?*: 

## Decrivez vos changements
*Clairement et avec des screenshots si nécessaires*
  • Loading branch information
Margouta authored Jul 7, 2024
2 parents 4ec649b + cb0c173 commit b5d57ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
40 changes: 23 additions & 17 deletions src/main/java/fr/communaywen/core/commands/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ public class TeamCommand {
TeamManager teamManager = AywenCraftPlugin.getInstance().getTeamManager();

@DefaultFor("~")
public void sendHelp(BukkitCommandActor actor, ExecutableCommand command) {
String helpCommandPath = command.getPath().toRealString() + " help";
actor.getCommandHandler().dispatch(actor, helpCommandPath);
public void sendHelp(Player player, ExecutableCommand command, CommandHelp<Component> help, @Default("1") @Range(min = 1) int page) {
if(teamManager.isInTeam(player.getUniqueId())) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
TeamMenu teamMenu = new TeamMenu(player, team, false);
teamMenu.open();
} else {
Audience audience = AywenCraftPlugin.getInstance().getAdventure().sender(player);
AywenCraftPlugin.getInstance().getInteractiveHelpMenu().sendInteractiveMenu(audience, help, 1, command, "§b§lTEAM");
}
}

@Subcommand("help")
Expand All @@ -48,8 +54,8 @@ public void sendHelp(BukkitCommandActor sender, CommandHelp<Component> help, Exe
@Subcommand("menu")
@Description("Menu de la team")
public void teamMenu(Player player) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (teamManager.isInTeam(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas dans une team !", true);
return;
}
Expand All @@ -61,7 +67,7 @@ public void teamMenu(Player player) {
@Description("Créer une team")
public void createTeam(Player player, @Named("nom") String teamName) {
TeamManager teamManager = AywenCraftPlugin.getInstance().getTeamManager();
if (teamManager.isInTeam(player.getUniqueId()) != null) {
if (teamManager.isInTeam(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous êtes déjà dans une team !", true);
return;
}
Expand Down Expand Up @@ -89,16 +95,16 @@ public void listTeams(Player player) {
@Subcommand("invite")
@Description("Inviter un joueur dans la team")
public void invitePlayer(Player player, @Named("joueur") Player target) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (team.isIn(target.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas dans une team !", true);
return;
}
if (!team.isOwner(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas le propriétaire de la team !", true);
return;
}
if (teamManager.isInTeam(target.getUniqueId()) != null) {
if (teamManager.isInTeam(target.getUniqueId())) {
CommandUtils.sendMessage(player, "Le joueur " + target.getName() + " est déjà dans une team !", true);
return;
}
Expand All @@ -117,8 +123,8 @@ public void invitePlayer(Player player, @Named("joueur") Player target) {
@Subcommand("accept")
@Description("Accepter une invitation")
public void acceptInvite(Player player) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team != null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (team.isIn(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous êtes déjà dans une team !", true);
return;
}
Expand All @@ -139,8 +145,8 @@ public void acceptInvite(Player player) {
@Subcommand("kick")
@Description("Kick un joueur de la team")
public void kickPlayer(Player player, @Named("joueur") Player target) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (team.isIn(target.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas dans une team !", true);
return;
}
Expand All @@ -164,8 +170,8 @@ public void kickPlayer(Player player, @Named("joueur") Player target) {
@Subcommand("leave")
@Description("Quitter la team")
public void leaveTeam(Player player) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (team.isIn(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas dans une team !", true);
return;
}
Expand All @@ -175,8 +181,8 @@ public void leaveTeam(Player player) {
@Subcommand("inventory")
@Description("Inventaire de la team")
public void teamInventory(Player player) {
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
Team team = teamManager.getTeamByPlayer(player.getUniqueId());
if (team.isIn(player.getUniqueId())) {
CommandUtils.sendMessage(player, "Vous n'êtes pas dans une team !", true);
return;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/fr/communaywen/core/teams/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ public boolean deleteTeam(Team team) {
return true;
}

public Team isInTeam(UUID player) {
public boolean isInTeam(UUID player) {
for (Team team : teams) {
if (team.getPlayers().contains(player)) {
return true;
}
}
return false;
}

public Team getTeamByPlayer(UUID player) {
for (Team team : teams) {
if (team.getPlayers().contains(player)) {
return team;
Expand Down

0 comments on commit b5d57ae

Please sign in to comment.