Skip to content

Commit

Permalink
Merge branch 'Margouta:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasDPX authored Jul 6, 2024
2 parents e05a1ff + f7d44d8 commit 47ab24b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 258 deletions.
123 changes: 22 additions & 101 deletions src/main/java/fr/communaywen/core/commands/TeamCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -27,18 +25,13 @@
public class TeamCommand implements CommandExecutor, TabCompleter {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
TeamManager teamManager = AywenCraftPlugin.getInstance().getTeamManager();
if (!(sender instanceof Player player)) {
return CommandUtils.sendMessage(sender, "Vous devez être un joueur pour exécuter cette commande !", true);
}
if (args.length == 0) {
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
return CommandUtils.sendMessage(sender, "Vous n'êtes pas dans une team !", true);
}
Expand All @@ -50,31 +43,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return CommandUtils.sendMessage(sender, ChatColor.WHITE + "Usage: /team create <nom de la team>", true);
}
if (args[0].equalsIgnoreCase("list")) {
Menu menu = null;
try {
menu = new TeamListMenu(player, teamManager);
} catch (SQLException e) {
throw new RuntimeException(e);
}
Menu menu = new TeamListMenu(player, teamManager);
menu.open();
}
if (args[0].equalsIgnoreCase("invite")) {
return CommandUtils.sendMessage(sender, ChatColor.WHITE + "Usage: /team invite <joueur>", true);
}
if (args[0].equalsIgnoreCase("accept")) {
try {
if (teamManager.isInTeam(player.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Vous êtes déjà dans une team !", true);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = null;
try {
team = teamManager.acceptInvite(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
if (teamManager.isInTeam(player.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Vous êtes déjà dans une team !", true);
}
Team team = teamManager.acceptInvite(player.getUniqueId());
if (team != null) {
CommandUtils.sendMessage(sender, ChatColor.GREEN + "Vous avez bien rejoint la team " + team.getName() + " !", false);
for (UUID teamPlayer : team.getPlayers()) {
Expand All @@ -91,28 +70,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return CommandUtils.sendMessage(sender, ChatColor.WHITE + "Usage: /team kick <joueur>", true);
}
if (args[0].equalsIgnoreCase("leave")) {
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
return CommandUtils.sendMessage(sender, "Vous n'êtes pas dans une team !", true);
}
try {
return TeamUtils.quit(team, player);
} catch (SQLException e) {
throw new RuntimeException(e);
}
return TeamUtils.quit(team, player);
}
if (args[0].equalsIgnoreCase("inventory")) {
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
return CommandUtils.sendMessage(sender, "Vous n'êtes pas dans une team !", true);
}
Expand All @@ -125,37 +90,21 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
for (int i = 1; i < args.length; i++) {
teamName.append(args[i]).append(" ");
}
try {
if (teamManager.isInTeam(player.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Vous êtes déjà dans une team !", true);
}
} catch (SQLException e) {
throw new RuntimeException(e);
if (teamManager.isInTeam(player.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Vous êtes déjà dans une team !", true);
}
if (teamName.length() > 16) {
return CommandUtils.sendMessage(sender, "Le nom de la team ne doit pas dépasser 16 caractères !", true);
}
Team createdTeam = null;
try {
createdTeam = teamManager.createTeam(player.getUniqueId(), teamName.toString().trim());
} catch (SQLException e) {
e.printStackTrace();
CommandUtils.sendMessage(sender, "Erreur lors de la création de la team !", true);
}
assert createdTeam != null;
Team createdTeam = teamManager.createTeam(player.getUniqueId(), teamName.toString().trim());
boolean couldAdd = createdTeam.addPlayer(player.getUniqueId());
if (!couldAdd) {
return CommandUtils.sendMessage(sender, "La team est déjà au complet !", true);
}
CommandUtils.sendMessage(sender, ChatColor.GREEN + "Vous avez créé la team " + createdTeam.getName() + " !", false);
}
if (args[0].equalsIgnoreCase("invite")) {
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
return CommandUtils.sendMessage(sender, "Vous n'êtes pas dans une team !", true);
}
Expand All @@ -166,12 +115,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (target == null) {
return CommandUtils.sendMessage(sender, "Le joueur " + args[1] + " n'est pas en ligne !", true);
}
try {
if (teamManager.isInTeam(target.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Le joueur " + target.getName() + " est déjà dans une team !", true);
}
} catch (SQLException e) {
throw new RuntimeException(e);
if (teamManager.isInTeam(target.getUniqueId()) != null) {
return CommandUtils.sendMessage(sender, "Le joueur " + target.getName() + " est déjà dans une team !", true);
}
boolean couldInvite = teamManager.invite(target.getUniqueId(), team);
if (!couldInvite) {
Expand All @@ -182,12 +127,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
CommandUtils.sendMessage(target, "Pour accepter, faites " + ChatColor.GREEN + "/team accept", false);
}
if (args[0].equalsIgnoreCase("kick")) {
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team == null) {
return CommandUtils.sendMessage(sender, "Vous n'êtes pas dans une team !", true);
}
Expand All @@ -196,12 +136,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
UUID target = team.getPlayerByUsername(args[1]);
if (target != null) {
MethodState state = null;
try {
state = team.removePlayer(target);
} catch (SQLException e) {
throw new RuntimeException(e);
}
MethodState state = team.removePlayer(target);
if (state == MethodState.VALID || state == MethodState.WARNING) CommandUtils.sendMessage(sender, "Le joueur " + args[1] + " a été kické de la team !", false);
if (state == MethodState.INVALID) return CommandUtils.sendMessage(sender, ChatColor.DARK_RED + "Impossible de kick, la team serait supprimée et il reste des items dans l'inventaire !", true);
Player targetPlayer = Bukkit.getPlayer(target);
Expand Down Expand Up @@ -231,34 +166,20 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}
if (args[0].equalsIgnoreCase("invite")) {
TeamManager teamManager = AywenCraftPlugin.getInstance().getTeamManager();
Team team = null;
try {
team = teamManager.isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = teamManager.isInTeam(player.getUniqueId());
if (team != null) {
List<String> players = new ArrayList<>();
for (Player onlinePlayer : player.getServer().getOnlinePlayers()) {
try {
if (teamManager.isInTeam(onlinePlayer.getUniqueId()) == null) {
players.add(onlinePlayer.getName());
}
} catch (SQLException e) {
throw new RuntimeException(e);
if (teamManager.isInTeam(onlinePlayer.getUniqueId()) == null) {
players.add(onlinePlayer.getName());
}
}
return players;
}

}
if (args[0].equalsIgnoreCase("kick")) {
Team team = null;
try {
team = AywenCraftPlugin.getInstance().getTeamManager().isInTeam(player.getUniqueId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
Team team = AywenCraftPlugin.getInstance().getTeamManager().isInTeam(player.getUniqueId());
if (team != null) {
List<String> players = new ArrayList<>();
for (UUID uuid : team.getPlayers()) {
Expand All @@ -271,4 +192,4 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
}
return List.of();
}
}
}
11 changes: 2 additions & 9 deletions src/main/java/fr/communaywen/core/teams/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import fr.communaywen.core.AywenCraftPlugin;
import fr.communaywen.core.teams.utils.MethodState;
import fr.communaywen.core.utils.CommandUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.sql.SQLException;
import java.util.*;

public class Team {
Expand Down Expand Up @@ -52,10 +49,6 @@ public boolean isIn(UUID player) {
}

public void openInventory(Player player) {
if(true) {
CommandUtils.sendMessage(player, "Fonctionnalité temporairement désativée :/", true);
return;
}
player.openInventory(inventory);
}

Expand Down Expand Up @@ -91,7 +84,7 @@ public boolean addPlayer(UUID player) {
return true;
}

public MethodState removePlayer(UUID player) throws SQLException {
public MethodState removePlayer(UUID player) {
if (players.size() - 1 == 0) {
players.remove(player);
if (!AywenCraftPlugin.getInstance().getTeamManager().deleteTeam(this)) {
Expand All @@ -113,4 +106,4 @@ public boolean isOwner(UUID player) {
private UUID getRandomPlayer() {
return players.get((int) (Math.random() * players.size()));
}
}
}
Loading

0 comments on commit 47ab24b

Please sign in to comment.