pala M-faction-3a: grades co-chefs + /f promote/demote

This commit is contained in:
Anaïs Saraiva
2026-10-19 05:08:15 +02:00
parent 7878f006bd
commit e8bfd0d99c
4 changed files with 88 additions and 9 deletions
@@ -181,6 +181,14 @@ public final class PalaCommands {
.then(Commands.argument("cible", EntityArgument.player())
.executes(command -> fTransfer(command.getSource(),
EntityArgument.getPlayer(command, "cible")))))
.then(Commands.literal("promote")
.then(Commands.argument("cible", EntityArgument.player())
.executes(command -> fPromote(command.getSource(),
EntityArgument.getPlayer(command, "cible")))))
.then(Commands.literal("demote")
.then(Commands.argument("cible", EntityArgument.player())
.executes(command -> fDemote(command.getSource(),
EntityArgument.getPlayer(command, "cible")))))
.then(Commands.literal("desc")
.then(Commands.argument("texte",
@@ -433,6 +441,8 @@ public final class PalaCommands {
}
source.sendSuccess(() -> Component.literal("§6[Faction " + faction.name + "] §7"
+ faction.members.size() + " membres"
+ (faction.viceLeaders == null || faction.viceLeaders.isEmpty() ? ""
: " (co-chefs : " + faction.viceLeaders.size() + ")")
+ (faction.description.isEmpty() ? "" : " : " + faction.description)), false);
return Command.SINGLE_SUCCESS;
}
@@ -447,8 +457,9 @@ public final class PalaCommands {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0;
}
if (!faction.owner.equals(player.getUUID().toString())) {
source.sendFailure(Component.literal("§cSeul le chef peut inviter."));
if (!fr.surviepote.pala.core.PalaFactions.isOfficer(faction,
player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0;
}
if (fr.surviepote.pala.core.PalaFactions.get()
@@ -532,8 +543,9 @@ public final class PalaCommands {
fr.surviepote.pala.core.PalaFactions.Faction faction =
fr.surviepote.pala.core.PalaFactions.get()
.byMember(player.getUUID().toString());
if (faction == null || !faction.owner.equals(player.getUUID().toString())) {
source.sendFailure(Component.literal("§cSeul le chef peut exclure."));
if (faction == null || !fr.surviepote.pala.core.PalaFactions.isOfficer(
faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0;
}
if (cible.getUUID().equals(player.getUUID())) {
@@ -608,7 +620,8 @@ public final class PalaCommands {
private static int fHelp(CommandSourceStack source) {
source.sendSuccess(() -> Component.literal("§6[Faction] §7/f create|info|invite|join|"
+ "leave|disband|kick|transfer|desc|help"), false);
+ "leave|disband|kick|transfer|desc|help|claim|unclaim|list|sethome|home|"
+ "promote|demote"), false);
return Command.SINGLE_SUCCESS;
}
@@ -657,8 +670,9 @@ public final class PalaCommands {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0;
}
if (!faction.owner.equals(player.getUUID().toString())) {
source.sendFailure(Component.literal("§cSeul le chef peut unclaim."));
if (!fr.surviepote.pala.core.PalaFactions.isOfficer(
faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0;
}
if (all) {
@@ -740,8 +754,9 @@ public final class PalaCommands {
fr.surviepote.pala.core.PalaFactions.get();
fr.surviepote.pala.core.PalaFactions.Faction faction =
fa.byMember(player.getUUID().toString());
if (faction == null || !faction.owner.equals(player.getUUID().toString())) {
source.sendFailure(Component.literal("§cSeul le chef peut definir le home."));
if (faction == null || !fr.surviepote.pala.core.PalaFactions.isOfficer(
faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0;
}
net.minecraft.core.BlockPos pos = player.blockPosition();
@@ -805,6 +820,53 @@ public final class PalaCommands {
}
}
// M-faction-3a : promote/demote co-chef (chef uniquement, cible membre, jamais le chef).
private static int fPromote(CommandSourceStack source, ServerPlayer cible) {
return setVice(source, cible, true);
}
private static int fDemote(CommandSourceStack source, ServerPlayer cible) {
return setVice(source, cible, false);
}
private static int setVice(CommandSourceStack source, ServerPlayer cible, boolean promote) {
try {
ServerPlayer player = source.getPlayerOrException();
fr.surviepote.pala.core.PalaFactions fa =
fr.surviepote.pala.core.PalaFactions.get();
fr.surviepote.pala.core.PalaFactions.Faction faction =
fa.byMember(player.getUUID().toString());
if (faction == null || !faction.owner.equals(player.getUUID().toString())) {
source.sendFailure(Component.literal("§cSeul le chef peut gerer les co-chefs."));
return 0;
}
String uuid = cible.getUUID().toString();
if (!faction.members.contains(uuid) || faction.owner.equals(uuid)) {
source.sendFailure(Component.literal("§cLa cible doit etre un membre (pas le chef)."));
return 0;
}
if (faction.viceLeaders == null) {
faction.viceLeaders = new java.util.ArrayList<>();
}
if (promote) {
if (!faction.viceLeaders.contains(uuid)) {
faction.viceLeaders.add(uuid);
fa.markDirty();
}
source.sendSuccess(() -> Component.literal("§6[Faction] §7"
+ cible.getScoreboardName() + " promu co-chef."), false);
} else {
faction.viceLeaders.remove(uuid);
fa.markDirty();
source.sendSuccess(() -> Component.literal("§6[Faction] §7"
+ cible.getScoreboardName() + " retrograde membre."), false);
}
return Command.SINGLE_SUCCESS;
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
return 0;
}
}
private static int fDisband(CommandSourceStack source) {
try {
ServerPlayer player = source.getPlayerOrException();
@@ -34,6 +34,9 @@ public final class PalaFactions {
public List<String> claims = new ArrayList<>();
// M-faction-2c : home ("dimension:x:y:z", vide = non defini).
public String home = "";
// M-faction-3a : co-chefs (UUID). Peuvent inviter/kick/unclaim/sethome.
// ECART : permissions fines par grade (GUI) en M-faction-3b.
public List<String> viceLeaders = new ArrayList<>();
}
private final Map<String, Faction> factions = new HashMap<>();
@@ -70,6 +73,12 @@ public final class PalaFactions {
dirty = true;
}
/** Chef ou co-chef : peut inviter/kick/unclaim/sethome (M-faction-3a). */
public static boolean isOfficer(Faction faction, String uuid) {
return faction.owner.equals(uuid)
|| (faction.viceLeaders != null && faction.viceLeaders.contains(uuid));
}
/** Faction proprietaire du chunk (cle "dimension:x:z"), ou null. */
public Faction byClaim(String key) {
for (Faction faction : factions.values()) {
@@ -125,6 +134,9 @@ public final class PalaFactions {
if (faction.claims == null) {
faction.claims = new ArrayList<>();
}
if (faction.viceLeaders == null) {
faction.viceLeaders = new ArrayList<>();
}
factions.put(String.valueOf(entry.getKey()), faction);
}
}