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
+5
View File
@@ -624,6 +624,11 @@ avant M4 (TODO:crafts-machines).
ECART : sans grades (GUI, M-faction-3), regle simplifiee chef/membres. Lecon : la ligne ECART : sans grades (GUI, M-faction-3), regle simplifiee chef/membres. Lecon : la ligne
/f list finissait par 4 parentheses (register inclus) — assert endswith trompeur. /f list finissait par 4 parentheses (register inclus) — assert endswith trompeur.
VERIFIE : build SUCCESSFUL, boot Done, 0 erreur. UNVERIFIED en jeu. VERIFIE : build SUCCESSFUL, boot Done, 0 erreur. UNVERIFIED en jeu.
- M-faction-3a LIVRE 2026-10-19 ~05:05 : grades commandes (co-chefs viceLeaders,
/f promote/demote chef-uniquement, invite/kick/unclaim/sethome elargis aux co-chefs,
/f info + /f help maj). ECART : perms fines GUI en M-faction-3b. Lecon : bloc
argument-then = 5 parentheses finales (getPlayer inclus), verifier au parencheck.
VERIFIE : build SUCCESSFUL, boot Done, 0 erreur. UNVERIFIED en jeu.
- M-palaforge LIVRE 2026-10-19 ~03:55 : bloc + BE partagee (3e mode) + gate mineur 14 + - M-palaforge LIVRE 2026-10-19 ~03:55 : bloc + BE partagee (3e mode) + gate mineur 14 +
table fonte wiki §3.2 (31 items, ratio floor usure) + fuels bois (+buche/planches/baton, table fonte wiki §3.2 (31 items, ratio floor usure) + fuels bois (+buche/planches/baton,
lave exclue : seau non rendu) + craft (1 findium + 4 furnaces + 4 briques, positions lave exclue : seau non rendu) + craft (1 findium + 4 furnaces + 4 briques, positions
@@ -181,6 +181,14 @@ public final class PalaCommands {
.then(Commands.argument("cible", EntityArgument.player()) .then(Commands.argument("cible", EntityArgument.player())
.executes(command -> fTransfer(command.getSource(), .executes(command -> fTransfer(command.getSource(),
EntityArgument.getPlayer(command, "cible"))))) 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.literal("desc")
.then(Commands.argument("texte", .then(Commands.argument("texte",
@@ -433,6 +441,8 @@ public final class PalaCommands {
} }
source.sendSuccess(() -> Component.literal("§6[Faction " + faction.name + "] §7" source.sendSuccess(() -> Component.literal("§6[Faction " + faction.name + "] §7"
+ faction.members.size() + " membres" + faction.members.size() + " membres"
+ (faction.viceLeaders == null || faction.viceLeaders.isEmpty() ? ""
: " (co-chefs : " + faction.viceLeaders.size() + ")")
+ (faction.description.isEmpty() ? "" : " : " + faction.description)), false); + (faction.description.isEmpty() ? "" : " : " + faction.description)), false);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -447,8 +457,9 @@ public final class PalaCommands {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction.")); source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0; return 0;
} }
if (!faction.owner.equals(player.getUUID().toString())) { if (!fr.surviepote.pala.core.PalaFactions.isOfficer(faction,
source.sendFailure(Component.literal("§cSeul le chef peut inviter.")); player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0; return 0;
} }
if (fr.surviepote.pala.core.PalaFactions.get() 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.Faction faction =
fr.surviepote.pala.core.PalaFactions.get() fr.surviepote.pala.core.PalaFactions.get()
.byMember(player.getUUID().toString()); .byMember(player.getUUID().toString());
if (faction == null || !faction.owner.equals(player.getUUID().toString())) { if (faction == null || !fr.surviepote.pala.core.PalaFactions.isOfficer(
source.sendFailure(Component.literal("§cSeul le chef peut exclure.")); faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0; return 0;
} }
if (cible.getUUID().equals(player.getUUID())) { if (cible.getUUID().equals(player.getUUID())) {
@@ -608,7 +620,8 @@ public final class PalaCommands {
private static int fHelp(CommandSourceStack source) { private static int fHelp(CommandSourceStack source) {
source.sendSuccess(() -> Component.literal("§6[Faction] §7/f create|info|invite|join|" 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; return Command.SINGLE_SUCCESS;
} }
@@ -657,8 +670,9 @@ public final class PalaCommands {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction.")); source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0; return 0;
} }
if (!faction.owner.equals(player.getUUID().toString())) { if (!fr.surviepote.pala.core.PalaFactions.isOfficer(
source.sendFailure(Component.literal("§cSeul le chef peut unclaim.")); faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0; return 0;
} }
if (all) { if (all) {
@@ -740,8 +754,9 @@ public final class PalaCommands {
fr.surviepote.pala.core.PalaFactions.get(); fr.surviepote.pala.core.PalaFactions.get();
fr.surviepote.pala.core.PalaFactions.Faction faction = fr.surviepote.pala.core.PalaFactions.Faction faction =
fa.byMember(player.getUUID().toString()); fa.byMember(player.getUUID().toString());
if (faction == null || !faction.owner.equals(player.getUUID().toString())) { if (faction == null || !fr.surviepote.pala.core.PalaFactions.isOfficer(
source.sendFailure(Component.literal("§cSeul le chef peut definir le home.")); faction, player.getUUID().toString())) {
source.sendFailure(Component.literal("§cChef ou co-chef requis."));
return 0; return 0;
} }
net.minecraft.core.BlockPos pos = player.blockPosition(); 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) { private static int fDisband(CommandSourceStack source) {
try { try {
ServerPlayer player = source.getPlayerOrException(); ServerPlayer player = source.getPlayerOrException();
@@ -34,6 +34,9 @@ public final class PalaFactions {
public List<String> claims = new ArrayList<>(); public List<String> claims = new ArrayList<>();
// M-faction-2c : home ("dimension:x:y:z", vide = non defini). // M-faction-2c : home ("dimension:x:y:z", vide = non defini).
public String home = ""; 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<>(); private final Map<String, Faction> factions = new HashMap<>();
@@ -70,6 +73,12 @@ public final class PalaFactions {
dirty = true; 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. */ /** Faction proprietaire du chunk (cle "dimension:x:z"), ou null. */
public Faction byClaim(String key) { public Faction byClaim(String key) {
for (Faction faction : factions.values()) { for (Faction faction : factions.values()) {
@@ -125,6 +134,9 @@ public final class PalaFactions {
if (faction.claims == null) { if (faction.claims == null) {
faction.claims = new ArrayList<>(); faction.claims = new ArrayList<>();
} }
if (faction.viceLeaders == null) {
faction.viceLeaders = new ArrayList<>();
}
factions.put(String.valueOf(entry.getKey()), faction); factions.put(String.valueOf(entry.getKey()), faction);
} }
} }
Binary file not shown.