pala M-tp-zones: /minage + /farmland (zones config)

This commit is contained in:
Anaïs Saraiva
2026-10-19 07:42:49 +02:00
parent 89ea9fe43a
commit 44c172021c
4 changed files with 70 additions and 1 deletions
@@ -92,6 +92,10 @@ public final class PalaCommands {
.executes(command -> craft(command.getSource())));
dispatcher.register(Commands.literal("spawn")
.executes(command -> spawn(command.getSource())));
dispatcher.register(Commands.literal("minage")
.executes(command -> minage(command.getSource())));
dispatcher.register(Commands.literal("farmland")
.executes(command -> farmland(command.getSource())));
dispatcher.register(Commands.literal("tpa")
.then(Commands.argument("cible", EntityArgument.player())
.executes(command -> tpa(command.getSource(),
@@ -1080,6 +1084,61 @@ public final class PalaCommands {
}
}
// M-tp-zones (wiki grades) : /minage + /farmland vers zones configurees.
private static int minage(CommandSourceStack source) {
return zoneTeleport(source,
fr.surviepote.pala.core.PalaConfig.get().miningZone, "Minage");
}
private static int farmland(CommandSourceStack source) {
return zoneTeleport(source,
fr.surviepote.pala.core.PalaConfig.get().farmlandZone, "Farmland");
}
private static int zoneTeleport(CommandSourceStack source, String zone, String label) {
try {
ServerPlayer player = source.getPlayerOrException();
if (zone == null || zone.isEmpty()) {
source.sendFailure(Component.literal(
"§cZone " + label + " non configuree (admin : config pala.json)."));
return 0;
}
String[] parts = zone.split(":");
if (parts.length != 4) {
source.sendFailure(Component.literal("§cZone " + label + " corrompue."));
return 0;
}
net.minecraft.server.MinecraftServer server = source.getServer();
net.minecraft.server.level.ServerLevel target = null;
for (net.minecraft.server.level.ServerLevel level : server.getAllLevels()) {
if (level.dimension().identifier().toString().equals(parts[0])) {
target = level;
break;
}
}
if (target == null) {
source.sendFailure(Component.literal("§cDimension inconnue."));
return 0;
}
int x;
int y;
int z;
try {
x = Integer.parseInt(parts[1]);
y = Integer.parseInt(parts[2]);
z = Integer.parseInt(parts[3]);
} catch (NumberFormatException e) {
source.sendFailure(Component.literal("§cZone " + label + " corrompue."));
return 0;
}
teleportPlayer(player, target,
new net.minecraft.core.BlockPos(x, y, z));
return Command.SINGLE_SUCCESS;
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException e) {
return 0;
}
}
private static int fDisband(CommandSourceStack source) {
try {
ServerPlayer player = source.getPlayerOrException();
@@ -91,6 +91,11 @@ public final class PalaConfig {
// M-market-2 (wiki §3.8) : expiration des annonces en jours (defaut 7).
public int marketExpiryDays = 7;
// M-tp-zones (wiki grades : /minage + /farmland) : zones designees "dimension:x:y:z"
// (vide = non configure, l'admin les definit). Positions UNVERIFIED par nature.
public String miningZone = "";
public String farmlandZone = "";
// M-rtp (wiki commandes) : cooldown minutes entre deux /rtp (wiki : 15).
public int rtpCooldownMinutes = 15;
// Rayon max du /rtp autour du spawn (blocs). UNVERIFIED (wiki : "aleatoire", sans borne).
@@ -246,7 +251,8 @@ public final class PalaConfig {
"furnaceSmelts", "furnaceFuels",
"serverName", "wikiUrl", "discordUrl", "shopUrl",
"afkKickMinutes", "rtpCooldownMinutes", "rtpRadius",
"factionMaxClaims", "marketExpiryDays");
"factionMaxClaims", "marketExpiryDays",
"miningZone", "farmlandZone");
boolean complete = true;
try (Reader keysReader = Files.newBufferedReader(path)) {
com.google.gson.JsonObject obj =