pala M-faction-2b: /f claim/unclaim/list + /fc chat faction

This commit is contained in:
Anaïs Saraiva
2026-10-19 04:42:04 +02:00
parent 7da06c6581
commit 76cc105f19
4 changed files with 147 additions and 1 deletions
@@ -189,7 +189,21 @@ public final class PalaCommands {
com.mojang.brigadier.arguments.StringArgumentType
.getString(command, "texte")))))
.then(Commands.literal("help")
.executes(command -> fHelp(command.getSource()))));
.executes(command -> fHelp(command.getSource())))
.then(Commands.literal("claim")
.executes(command -> fClaim(command.getSource())))
.then(Commands.literal("unclaim")
.executes(command -> fUnclaim(command.getSource(), false)))
.then(Commands.literal("unclaimall")
.executes(command -> fUnclaim(command.getSource(), true)))
.then(Commands.literal("list")
.executes(command -> fList(command.getSource()))));
dispatcher.register(Commands.literal("fc")
.then(Commands.argument("texte",
com.mojang.brigadier.arguments.StringArgumentType.greedyString())
.executes(command -> fChat(command.getSource(),
com.mojang.brigadier.arguments.StringArgumentType
.getString(command, "texte")))));
net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.END_SERVER_TICK
.register(PalaCommands::tickSpawnQueue);
net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.END_SERVER_TICK
@@ -594,6 +608,125 @@ public final class PalaCommands {
return Command.SINGLE_SUCCESS;
}
// M-faction-2b : claims (chunk du joueur, quota config) + liste + chat faction.
private static int fClaim(CommandSourceStack source) {
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) {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0;
}
String key = fr.surviepote.pala.events.PalaFactionProtect.key(
player.level(), player.blockPosition());
if (fa.byClaim(key) != null) {
source.sendFailure(Component.literal("§cChunk deja revendique."));
return 0;
}
if (faction.claims.size()
>= fr.surviepote.pala.core.PalaConfig.get().factionMaxClaims) {
source.sendFailure(Component.literal("§cLimite de claims atteinte."));
return 0;
}
faction.claims.add(key);
fa.markDirty();
final int n = faction.claims.size();
source.sendSuccess(() -> Component.literal(
"§6[Faction] §7Chunk revendique (" + n + ")."), false);
return Command.SINGLE_SUCCESS;
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
return 0;
}
}
private static int fUnclaim(CommandSourceStack source, boolean all) {
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) {
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."));
return 0;
}
if (all) {
final int n = faction.claims.size();
faction.claims.clear();
fa.markDirty();
source.sendSuccess(() -> Component.literal(
"§6[Faction] §7" + n + " claims liberes."), false);
return Command.SINGLE_SUCCESS;
}
String key = fr.surviepote.pala.events.PalaFactionProtect.key(
player.level(), player.blockPosition());
if (!faction.claims.remove(key)) {
source.sendFailure(Component.literal("§cCe chunk n'est pas a vous."));
return 0;
}
fa.markDirty();
source.sendSuccess(() -> Component.literal("§6[Faction] §7Chunk libere."), false);
return Command.SINGLE_SUCCESS;
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
return 0;
}
}
private static int fList(CommandSourceStack source) {
java.util.List<String> names =
new java.util.ArrayList<>(fr.surviepote.pala.core.PalaFactions.get().names());
java.util.Collections.sort(names);
StringBuilder out = new StringBuilder("§6[Factions]");
if (names.isEmpty()) {
out.append("\n§7aucune faction.");
}
for (String name : names) {
fr.surviepote.pala.core.PalaFactions.Faction faction =
fr.surviepote.pala.core.PalaFactions.get().byName(name);
out.append("\n§e").append(name).append(" §7(").append(faction.members.size())
.append(" membres, ").append(faction.claims.size()).append(" claims)");
}
source.sendSuccess(() -> Component.literal(out.toString()), false);
return Command.SINGLE_SUCCESS;
}
private static int fChat(CommandSourceStack source, String texte) {
try {
ServerPlayer player = source.getPlayerOrException();
fr.surviepote.pala.core.PalaFactions.Faction faction =
fr.surviepote.pala.core.PalaFactions.get()
.byMember(player.getUUID().toString());
if (faction == null) {
source.sendFailure(Component.literal("§cVous n'etes dans aucune faction."));
return 0;
}
Component msg = Component.literal("§2[F" + faction.name + "] "
+ player.getScoreboardName() + " §f" + texte);
for (String uuid : faction.members) {
ServerPlayer member;
try {
member = source.getServer().getPlayerList().getPlayer(
java.util.UUID.fromString(uuid));
} catch (IllegalArgumentException e) {
continue;
}
if (member != null) {
member.sendSystemMessage(msg);
}
}
return Command.SINGLE_SUCCESS;
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
return 0;
}
}
private static int fDisband(CommandSourceStack source) {
try {
ServerPlayer player = source.getPlayerOrException();
@@ -92,6 +92,15 @@ public final class PalaFactions {
return factions.size();
}
/** Noms des factions (cles minuscules d'enregistrement). */
public java.util.List<String> names() {
java.util.List<String> out = new java.util.ArrayList<>();
for (Faction faction : factions.values()) {
out.add(faction.name);
}
return out;
}
public void load() {
Path path = file();
if (!Files.exists(path)) {