GastinelClaims 1.1.0 : zones protégées (spawn incassable)
Zones configurables (config/gastinelclaims-zones.json, /zoneprotegee liste|ici|recharger), zone « spawn » x 3284..3320 y 185..204 z -615..-566. Non-ops : ni casse, ni pose, ni seau/briquet, interactions limitées à une liste. Explosions, pistons, mobs, liquides venus de l'extérieur et feu (mixins FlowingFluid/FireBlock) n'y modifient rien. /claim inchangé. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
f7ea72ed99
révision
4fff64919e
13 fichiers modifiés
+639
-6
Aucun fichier ne correspond à votre recherche
+17
-1
@@ -23,4 +23,20 @@ Casser/poser des blocs, clic droit sur un bloc (coffres, portes, leviers, bouton
|
|||||||
- Lave/eau qui coule d'un chunk voisin, flèches/projectiles sur les cadres, dispensers : non bloqués.
|
- Lave/eau qui coule d'un chunk voisin, flèches/projectiles sur les cadres, dispensers : non bloqués.
|
||||||
|
|
||||||
## Build (sur cornafserver, pas sur le PC)
|
## Build (sur cornafserver, pas sur le PC)
|
||||||
Copier le dossier puis `sh build-sur-cornafserver.sh` (conteneur `eclipse-temurin:21-jdk` jetable, cache Gradle dans `~/.cache/gastinelclaims-gradle`). Lance les tests JUnit puis produit `build/libs/gastinelclaims-neoforge-1.21.1-1.0.0.jar`.
|
Copier le dossier puis `sh build-sur-cornafserver.sh` (conteneur `eclipse-temurin:21-jdk` jetable, cache Gradle dans `~/.cache/gastinelclaims-gradle`). Lance les tests JUnit puis produit `build/libs/gastinelclaims-neoforge-1.21.1-1.1.0.jar`.
|
||||||
|
|
||||||
|
## Zones protégées (depuis 1.1.0) — spawn incassable
|
||||||
|
Module séparé de `/claim` (fichiers `ZonesProtegees.java`, `ZoneEvents.java`, `mixin/`, `core/ZonesConfig.java`). Une zone se cumule avec les claims et passe avant eux (priorité `HIGHEST`) ; `/claim` n'est pas modifié.
|
||||||
|
|
||||||
|
**Config** : `config/gastinelclaims-zones.json` (créé au premier démarrage depuis `src/main/resources/gastinelclaims/zones-defaut.json`). Liste `zones` : `nom`, `dimension`, `coin1`/`coin2` (deux coins opposés `[x, y, z]`, bornes incluses, dans n'importe quel ordre), `active` (facultatif). Zone livrée : `spawn`, overworld, x 3284..3320, y 185..204, z -615..-566 (le spawn du monde 3300 189 -586 est dedans, vérifié dans level.dat et au démarrage : ligne `Spawn du monde … dans la zone protégée « spawn »`). Ajouter une zone : éditer le fichier puis `/zoneprotegee recharger`.
|
||||||
|
`niveau_op_ignore` (2) : les ops de ce niveau ne sont pas concernés (les machines / FakePlayer le sont toujours).
|
||||||
|
`interactions_autorisees` : blocs qu'un joueur peut encore utiliser au clic droit (ids ou tags `#…`), sans jamais utiliser l'objet en main. Par défaut : boutons, plaques de pression, portes/trappes en bois, portillons, levier, établi, coffre de l'Ender, table d'enchantement. Mettre `[]` pour tout interdire (marcher sur une plaque de pression reste toujours possible).
|
||||||
|
|
||||||
|
**Commandes (op 2)** : `/zoneprotegee liste`, `/zoneprotegee ici`, `/zoneprotegee recharger`.
|
||||||
|
|
||||||
|
**Bloqué dans une zone** (joueurs non-op, machines) : casser, poser (toute entité : joueur, enderman, machine), outils qui modifient un bloc (écorcer, aplanir, labourer), clic droit sur tout bloc non autorisé (coffres, fours, tonneaux, pupitres, pots…), seaux / briquet / boule de feu visant la zone ou utilisés dedans, piétinement des cultures, frapper ou modifier cadres / tableaux / supports d'armure.
|
||||||
|
**Bloqué pour le monde** : explosions (TNT, creeper, lit, ancre, wither…) ne détruisent aucun bloc ni décor de la zone ; liquides venus de l'extérieur n'y entrent pas (mixin `FlowingFluid.canSpreadTo` ; une fontaine posée dedans par un op coule normalement) ; lave+eau ne crée pas de pierre/obsidienne dedans ; feu : ne brûle aucun bloc de la zone et ne s'y propage pas (mixin `FireBlock.checkBurnOut` / `getIgniteOdds`) ; pistons (poussée, traction, destruction) touchant la zone ; wither / dragon / ravageur (`LivingDestroyBlockEvent`) ; « mobGriefing » (enderman, zombie et portes, lapins, moutons…) à moins de 4 blocs de la zone.
|
||||||
|
|
||||||
|
**Testé le 09/10/2026 sur une copie du monde** (serveur jetable, tous les mods du serveur dont Lithium et Create) : TNT dedans/dehors, eau en canal (s'arrête à x=3320), feu (planches dehors brûlées, dedans intactes), pistons vers la zone et témoin hors zone, chargement de la config et vérification du spawn. **Non testé en jeu** (pas de client) : casse/pose/seau/clic par un vrai joueur, enderman/wither (monde en peaceful).
|
||||||
|
|
||||||
|
**Limites** : les contraptions Create en mouvement (piston mécanique, roulement, chariot) et les perceuses/scies Create qui ne passent pas par un FakePlayer ne sont pas garanties ; les projectiles (flèches sur un cadre) et les dispensers ne sont pas bloqués ; la foudre peut allumer un feu (qui ne brûlera rien dans la zone).
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
set -e
|
set -e
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
mkdir -p "$HOME/.cache/gastinelclaims-gradle"
|
mkdir -p "$HOME/.cache/gastinelclaims-gradle"
|
||||||
docker run --rm \
|
nice -n 10 docker run --rm --memory 4g --cpus 4 \
|
||||||
-u "$(id -u):$(id -g)" \
|
-u "$(id -u):$(id -g)" \
|
||||||
-e GRADLE_USER_HOME=/gradle-home \
|
-e GRADLE_USER_HOME=/gradle-home \
|
||||||
-v "$HOME/.cache/gastinelclaims-gradle:/gradle-home" \
|
-v "$HOME/.cache/gastinelclaims-gradle:/gradle-home" \
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx2G
|
org.gradle.jvmargs=-Xmx2G
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
mod_version=1.0.0
|
mod_version=1.1.0
|
||||||
mod_group_id=com.gastinelclaims
|
mod_group_id=com.gastinelclaims
|
||||||
mod_id=gastinelclaims
|
mod_id=gastinelclaims
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ public class GastinelClaims {
|
|||||||
|
|
||||||
NeoForge.EVENT_BUS.register(ClaimCommands.class);
|
NeoForge.EVENT_BUS.register(ClaimCommands.class);
|
||||||
NeoForge.EVENT_BUS.register(ProtectionEvents.class);
|
NeoForge.EVENT_BUS.register(ProtectionEvents.class);
|
||||||
|
NeoForge.EVENT_BUS.register(ZonesProtegees.class);
|
||||||
|
NeoForge.EVENT_BUS.register(ZoneEvents.class);
|
||||||
|
|
||||||
LOGGER.info("[GastinelClaims] Protection de terrains chargée.");
|
LOGGER.info("[GastinelClaims] Protection de terrains et zones protégées chargées.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
package com.gastinelclaims;
|
||||||
|
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
|
import net.minecraft.world.entity.decoration.HangingEntity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.item.BucketItem;
|
||||||
|
import net.minecraft.world.item.FireChargeItem;
|
||||||
|
import net.minecraft.world.item.FlintAndSteelItem;
|
||||||
|
import net.minecraft.world.level.ClipContext;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.piston.PistonStructureResolver;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
import net.minecraft.world.phys.HitResult;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.neoforged.bus.api.EventPriority;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.neoforge.common.util.TriState;
|
||||||
|
import net.neoforged.neoforge.event.entity.EntityMobGriefingEvent;
|
||||||
|
import net.neoforged.neoforge.event.entity.living.LivingDestroyBlockEvent;
|
||||||
|
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
|
||||||
|
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||||
|
import net.neoforged.neoforge.event.level.BlockEvent;
|
||||||
|
import net.neoforged.neoforge.event.level.ExplosionEvent;
|
||||||
|
import net.neoforged.neoforge.event.level.PistonEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protection des zones (spawn incassable). Priorité HIGHEST : passe avant /claim, sans le modifier.
|
||||||
|
* Le feu et l'écoulement des liquides sont gérés par les mixins (pas d'événement NeoForge pour eux).
|
||||||
|
*/
|
||||||
|
public final class ZoneEvents {
|
||||||
|
|
||||||
|
/** Distance autour d'une zone où un mob ne peut pas « griefer » (enderman, wither, ravageur…). */
|
||||||
|
private static final double MARGE_MOBS = 4.0;
|
||||||
|
|
||||||
|
private ZoneEvents() {}
|
||||||
|
|
||||||
|
private static boolean refuse(Player p, Level level, BlockPos pos) {
|
||||||
|
return ZonesProtegees.protege(level, pos) && !ZonesProtegees.ignore(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Joueurs (et machines Create à FakePlayer) ---
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onBreak(BlockEvent.BreakEvent event) {
|
||||||
|
if (event.getLevel() instanceof Level level && refuse(event.getPlayer(), level, event.getPos())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
ZonesProtegees.prevenir(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pose de bloc par n'importe quelle entité (joueur, enderman, machine…), y compris lits et portes. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onPlace(BlockEvent.EntityPlaceEvent event) {
|
||||||
|
if (!(event.getLevel() instanceof Level level) || !ZonesProtegees.protege(level, event.getPos())) return;
|
||||||
|
Entity e = event.getEntity();
|
||||||
|
if (e instanceof Player p && ZonesProtegees.ignore(p)) return;
|
||||||
|
event.setCanceled(true);
|
||||||
|
if (e instanceof Player p) ZonesProtegees.prevenir(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onTrample(BlockEvent.FarmlandTrampleEvent event) {
|
||||||
|
if (event.getLevel() instanceof Level level && ZonesProtegees.protege(level, event.getPos())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Outils (hache, pelle, houe : écorcer, aplanir, labourer) et ruches/cire, etc. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onToolModify(BlockEvent.BlockToolModificationEvent event) {
|
||||||
|
if (event.isSimulated()) return;
|
||||||
|
if (event.getLevel() instanceof Level level && refuse(event.getPlayer(), level, event.getPos())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clic droit sur un bloc : seuls les blocs de interactions_autorisees restent utilisables, et jamais
|
||||||
|
* avec l'objet en main (pas de pose, pas de seau, pas de briquet).
|
||||||
|
*/
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
|
||||||
|
Player p = event.getEntity();
|
||||||
|
Level level = event.getLevel();
|
||||||
|
if (level.isClientSide() || ZonesProtegees.ignore(p)) return;
|
||||||
|
BlockPos pos = event.getPos();
|
||||||
|
boolean dedans = ZonesProtegees.protege(level, pos);
|
||||||
|
boolean voisin = event.getFace() != null && ZonesProtegees.protege(level, pos.relative(event.getFace()));
|
||||||
|
if (!dedans && !voisin) return;
|
||||||
|
if (dedans && ZonesProtegees.interactionAutorisee(level.getBlockState(pos))) {
|
||||||
|
event.setUseItem(TriState.FALSE); // le bloc s'utilise, l'objet en main ne sert pas
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event.setCanceled(true);
|
||||||
|
ZonesProtegees.prevenir(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Seau, briquet, boule de feu visant la zone à distance. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onRightClickItem(PlayerInteractEvent.RightClickItem event) {
|
||||||
|
var item = event.getItemStack().getItem();
|
||||||
|
if (!(item instanceof BucketItem || item instanceof FlintAndSteelItem || item instanceof FireChargeItem)) return;
|
||||||
|
Player p = event.getEntity();
|
||||||
|
Level level = event.getLevel();
|
||||||
|
if (level.isClientSide() || ZonesProtegees.ignore(p)) return;
|
||||||
|
Vec3 eye = p.getEyePosition();
|
||||||
|
Vec3 end = eye.add(p.getViewVector(1.0F).scale(p.blockInteractionRange()));
|
||||||
|
BlockHitResult hit = level.clip(new ClipContext(eye, end, ClipContext.Block.OUTLINE, ClipContext.Fluid.SOURCE_ONLY, p));
|
||||||
|
boolean viseZone = hit.getType() == HitResult.Type.BLOCK && (ZonesProtegees.protege(level, hit.getBlockPos())
|
||||||
|
|| ZonesProtegees.protege(level, hit.getBlockPos().relative(hit.getDirection())));
|
||||||
|
if (viseZone || ZonesProtegees.protege(level, p.blockPosition())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
ZonesProtegees.prevenir(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cadres, tableaux, supports d'armure de la zone : ni cassés ni modifiés. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onAttack(AttackEntityEvent event) {
|
||||||
|
Entity t = event.getTarget();
|
||||||
|
if (decor(t) && refuse(event.getEntity(), t.level(), t.blockPosition())) event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
|
||||||
|
Entity t = event.getTarget();
|
||||||
|
if (decor(t) && refuse(event.getEntity(), t.level(), t.blockPosition())) event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onEntityInteractSpecific(PlayerInteractEvent.EntityInteractSpecific event) {
|
||||||
|
Entity t = event.getTarget();
|
||||||
|
if (decor(t) && refuse(event.getEntity(), t.level(), t.blockPosition())) event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean decor(Entity e) {
|
||||||
|
return e instanceof HangingEntity || e instanceof ArmorStand;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Monde : explosions, pistons, liquides (mélanges), mobs ---
|
||||||
|
|
||||||
|
/** TNT, creeper, lit, ancre de réapparition, wither… : aucun bloc ni décor de la zone n'est détruit. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onExplosion(ExplosionEvent.Detonate event) {
|
||||||
|
Level level = event.getLevel();
|
||||||
|
if (level.isClientSide()) return;
|
||||||
|
event.getAffectedBlocks().removeIf(pos -> ZonesProtegees.protege(level, pos));
|
||||||
|
event.getAffectedEntities().removeIf(e -> decor(e) && ZonesProtegees.protege(level, e.blockPosition()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pistons : refusés si un bloc poussé, détruit ou la tête touche la zone (dans un sens ou dans l'autre). */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onPiston(PistonEvent.Pre event) {
|
||||||
|
if (!(event.getLevel() instanceof Level level) || level.isClientSide()) return;
|
||||||
|
if (ZonesProtegees.config().zones.isEmpty()) return;
|
||||||
|
if (ZonesProtegees.protege(level, event.getPos()) || ZonesProtegees.protege(level, event.getFaceOffsetPos())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PistonStructureResolver r = event.getStructureHelper();
|
||||||
|
if (r == null) return;
|
||||||
|
r.resolve();
|
||||||
|
var dir = event.getPistonMoveType().isExtend ? event.getDirection() : event.getDirection().getOpposite();
|
||||||
|
for (BlockPos b : r.getToPush()) {
|
||||||
|
if (ZonesProtegees.protege(level, b) || ZonesProtegees.protege(level, b.relative(dir))) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (BlockPos b : r.getToDestroy()) {
|
||||||
|
if (ZonesProtegees.protege(level, b)) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lave + eau (pierre, obsidienne) et lave qui allume un feu : rien ne se crée dans la zone. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onFluidPlace(BlockEvent.FluidPlaceBlockEvent event) {
|
||||||
|
if (event.getLevel() instanceof Level level && ZonesProtegees.protege(level, event.getPos())) {
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wither, dragon, ravageur… qui cassent un bloc précis. */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onLivingDestroy(LivingDestroyBlockEvent event) {
|
||||||
|
if (ZonesProtegees.protege(event.getEntity().level(), event.getPos())) event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Enderman (prendre un bloc), zombie (portes), lapins, moutons… près de la zone : pas de « grief ». */
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onMobGriefing(EntityMobGriefingEvent event) {
|
||||||
|
Entity e = event.getEntity();
|
||||||
|
if (e != null && !(e instanceof Player) && ZonesProtegees.proche(e, MARGE_MOBS)) event.setCanGrief(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package com.gastinelclaims;
|
||||||
|
|
||||||
|
import com.gastinelclaims.core.ZonesConfig;
|
||||||
|
import com.gastinelclaims.core.ZonesConfig.Zone;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.minecraft.ChatFormatting;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.commands.Commands;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
|
import net.minecraft.core.registries.Registries;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.tags.TagKey;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.BlockGetter;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.neoforge.common.util.FakePlayer;
|
||||||
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
|
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zones protégées (spawn incassable…). État global lu depuis config/gastinelclaims-zones.json
|
||||||
|
* (créé depuis la version intégrée au jar s'il manque). Utilisé par {@link ZoneEvents} et les mixins.
|
||||||
|
* Indépendant des claims (/claim) : un claim et une zone se cumulent, la zone gagne.
|
||||||
|
*/
|
||||||
|
public final class ZonesProtegees {
|
||||||
|
|
||||||
|
static final String FICHIER = "config/gastinelclaims-zones.json";
|
||||||
|
|
||||||
|
private static volatile ZonesConfig config = ZonesConfig.VIDE;
|
||||||
|
private static volatile List<TagKey<Block>> tagsAutorises = List.of();
|
||||||
|
private static volatile List<Block> blocsAutorises = List.of();
|
||||||
|
|
||||||
|
private ZonesProtegees() {}
|
||||||
|
|
||||||
|
public static ZonesConfig config() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Le bloc est-il dans une zone protégée ? (appelé aussi par les mixins, doit rester rapide). */
|
||||||
|
public static boolean protege(BlockGetter getter, BlockPos pos) {
|
||||||
|
ZonesConfig c = config;
|
||||||
|
if (c.zones.isEmpty() || !(getter instanceof Level level) || level.isClientSide()) return false;
|
||||||
|
return c.zoneDe(level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ()) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Zone zoneDe(Level level, BlockPos pos) {
|
||||||
|
ZonesConfig c = config;
|
||||||
|
if (c.zones.isEmpty() || level.isClientSide()) return null;
|
||||||
|
return c.zoneDe(level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Entité à moins de {@code marge} blocs d'une zone (pour les mobs qui cassent autour d'eux). */
|
||||||
|
public static boolean proche(Entity e, double marge) {
|
||||||
|
ZonesConfig c = config;
|
||||||
|
if (c.zones.isEmpty() || e.level().isClientSide()) return false;
|
||||||
|
return c.proche(e.level().dimension().location().toString(), e.getX(), e.getY(), e.getZ(), marge);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Joueur qui ignore la protection : op du niveau configuré (jamais une machine / FakePlayer). */
|
||||||
|
public static boolean ignore(Player p) {
|
||||||
|
return p != null && !(p instanceof FakePlayer) && p.hasPermissions(config.niveauOp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean interactionAutorisee(BlockState s) {
|
||||||
|
for (Block b : blocsAutorises) if (s.is(b)) return true;
|
||||||
|
for (TagKey<Block> t : tagsAutorises) if (s.is(t)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (Re)lit le fichier. Renvoie un message de résultat. En cas d'erreur, l'ancienne config est gardée. */
|
||||||
|
static String charger(MinecraftServer server) {
|
||||||
|
Path f = server.getServerDirectory().resolve(FICHIER);
|
||||||
|
try {
|
||||||
|
if (!Files.exists(f)) {
|
||||||
|
try (InputStream in = ZonesProtegees.class.getResourceAsStream("/gastinelclaims/zones-defaut.json")) {
|
||||||
|
if (in == null) throw new IllegalStateException("zones-defaut.json absent du jar");
|
||||||
|
Files.createDirectories(f.getParent());
|
||||||
|
Files.copy(in, f);
|
||||||
|
GastinelClaims.LOGGER.info("[GastinelClaims] Fichier de zones protégées créé : {}", f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ZonesConfig c = ZonesConfig.parse(Files.readString(f, StandardCharsets.UTF_8));
|
||||||
|
List<TagKey<Block>> tags = new ArrayList<>();
|
||||||
|
List<Block> blocs = new ArrayList<>();
|
||||||
|
for (String id : c.interactionsAutorisees) {
|
||||||
|
if (id.startsWith("#")) {
|
||||||
|
tags.add(TagKey.create(Registries.BLOCK, ResourceLocation.parse(id.substring(1))));
|
||||||
|
} else {
|
||||||
|
ResourceLocation rl = ResourceLocation.parse(id);
|
||||||
|
if (BuiltInRegistries.BLOCK.containsKey(rl)) blocs.add(BuiltInRegistries.BLOCK.get(rl));
|
||||||
|
else GastinelClaims.LOGGER.warn("[GastinelClaims] Bloc inconnu dans interactions_autorisees : {}", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tagsAutorises = List.copyOf(tags);
|
||||||
|
blocsAutorises = List.copyOf(blocs);
|
||||||
|
config = c;
|
||||||
|
for (Zone z : c.zones) {
|
||||||
|
GastinelClaims.LOGGER.info("[GastinelClaims] Zone protégée active : {} {} x {}..{} y {}..{} z {}..{}",
|
||||||
|
z.nom(), z.dimension(), z.minX(), z.maxX(), z.minY(), z.maxY(), z.minZ(), z.maxZ());
|
||||||
|
}
|
||||||
|
return c.zones.size() + " zone(s) protégée(s) chargée(s).";
|
||||||
|
} catch (Exception e) {
|
||||||
|
GastinelClaims.LOGGER.error("[GastinelClaims] Zones protégées illisibles ({}) : {} — ancienne config gardée.", f, e.toString());
|
||||||
|
return "Erreur de lecture de " + FICHIER + " : " + e.getMessage() + " (ancienne config gardée).";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onStarted(ServerStartedEvent event) {
|
||||||
|
charger(event.getServer());
|
||||||
|
// Vérification utile : le spawn du monde est-il dans une zone ?
|
||||||
|
var ow = event.getServer().overworld();
|
||||||
|
BlockPos s = ow.getSharedSpawnPos();
|
||||||
|
Zone z = zoneDe(ow, s);
|
||||||
|
GastinelClaims.LOGGER.info("[GastinelClaims] Spawn du monde {} {} {} : {}", s.getX(), s.getY(), s.getZ(),
|
||||||
|
z == null ? "HORS de toute zone protégée" : "dans la zone protégée « " + z.nom() + " »");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onStopped(ServerStoppedEvent event) {
|
||||||
|
config = ZonesConfig.VIDE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRegister(RegisterCommandsEvent event) {
|
||||||
|
CommandDispatcher<CommandSourceStack> d = event.getDispatcher();
|
||||||
|
d.register(Commands.literal("zoneprotegee")
|
||||||
|
.requires(s -> s.hasPermission(2))
|
||||||
|
.then(Commands.literal("recharger").executes(ctx -> {
|
||||||
|
String m = charger(ctx.getSource().getServer());
|
||||||
|
ctx.getSource().sendSuccess(() -> Component.literal(m), true);
|
||||||
|
return config.zones.size();
|
||||||
|
}))
|
||||||
|
.then(Commands.literal("liste").executes(ctx -> {
|
||||||
|
if (config.zones.isEmpty()) {
|
||||||
|
ctx.getSource().sendSuccess(() -> Component.literal("Aucune zone protégée."), false);
|
||||||
|
}
|
||||||
|
for (Zone z : config.zones) {
|
||||||
|
ctx.getSource().sendSuccess(() -> Component.literal("- " + z.nom() + " (" + z.dimension() + ") x "
|
||||||
|
+ z.minX() + ".." + z.maxX() + ", y " + z.minY() + ".." + z.maxY() + ", z "
|
||||||
|
+ z.minZ() + ".." + z.maxZ()), false);
|
||||||
|
}
|
||||||
|
return config.zones.size();
|
||||||
|
}))
|
||||||
|
.then(Commands.literal("ici").executes(ctx -> {
|
||||||
|
CommandSourceStack src = ctx.getSource();
|
||||||
|
BlockPos p = BlockPos.containing(src.getPosition());
|
||||||
|
Zone z = zoneDe(src.getLevel(), p);
|
||||||
|
src.sendSuccess(() -> Component.literal(z == null ? "Hors zone protégée." : "Dans la zone protégée « " + z.nom() + " ».")
|
||||||
|
.withStyle(z == null ? ChatFormatting.GRAY : ChatFormatting.GOLD), false);
|
||||||
|
return z == null ? 0 : 1;
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prevenir(Player p) {
|
||||||
|
if (p instanceof ServerPlayer sp && !(p instanceof FakePlayer)) {
|
||||||
|
sp.displayClientMessage(Component.literal("Zone protégée : impossible de modifier ici.")
|
||||||
|
.withStyle(ChatFormatting.RED), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.gastinelclaims.core;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zones protégées (spawn incassable…) lues depuis config/gastinelclaims-zones.json.
|
||||||
|
* Logique pure (Gson seulement), testable sans Minecraft.
|
||||||
|
*/
|
||||||
|
public final class ZonesConfig {
|
||||||
|
|
||||||
|
/** Cube aux bornes incluses (en blocs), ordonnées quel que soit l'ordre des coins donnés. */
|
||||||
|
public record Zone(String nom, String dimension, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||||
|
public static Zone deCoins(String nom, String dimension, int[] a, int[] b) {
|
||||||
|
return new Zone(nom, dimension, Math.min(a[0], b[0]), Math.min(a[1], b[1]), Math.min(a[2], b[2]),
|
||||||
|
Math.max(a[0], b[0]), Math.max(a[1], b[1]), Math.max(a[2], b[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contient(String dim, int x, int y, int z) {
|
||||||
|
return dimension.equals(dim) && x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Vrai si le point est à moins de {@code marge} blocs de la zone (marge 0 = dedans). */
|
||||||
|
public boolean proche(String dim, double x, double y, double z, double marge) {
|
||||||
|
return dimension.equals(dim) && x >= minX - marge && x < maxX + 1 + marge && y >= minY - marge
|
||||||
|
&& y < maxY + 1 + marge && z >= minZ - marge && z < maxZ + 1 + marge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final List<Zone> zones;
|
||||||
|
/** Niveau d'op à partir duquel on ignore la protection (2 par défaut). */
|
||||||
|
public final int niveauOp;
|
||||||
|
/** Blocs utilisables (clic droit) dans les zones : ids "minecraft:lever" ou tags "#minecraft:buttons". */
|
||||||
|
public final List<String> interactionsAutorisees;
|
||||||
|
|
||||||
|
private ZonesConfig(List<Zone> zones, int niveauOp, List<String> interactionsAutorisees) {
|
||||||
|
this.zones = zones;
|
||||||
|
this.niveauOp = niveauOp;
|
||||||
|
this.interactionsAutorisees = interactionsAutorisees;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ZonesConfig VIDE = new ZonesConfig(List.of(), 2, List.of());
|
||||||
|
|
||||||
|
public static ZonesConfig parse(String json) {
|
||||||
|
JsonObject o = JsonParser.parseString(json).getAsJsonObject();
|
||||||
|
List<Zone> zones = new ArrayList<>();
|
||||||
|
if (o.has("zones")) {
|
||||||
|
for (JsonElement e : o.getAsJsonArray("zones")) {
|
||||||
|
JsonObject z = e.getAsJsonObject();
|
||||||
|
if (z.has("active") && !z.get("active").getAsBoolean()) continue;
|
||||||
|
zones.add(Zone.deCoins(
|
||||||
|
z.get("nom").getAsString(),
|
||||||
|
z.has("dimension") ? z.get("dimension").getAsString() : "minecraft:overworld",
|
||||||
|
coin(z.getAsJsonArray("coin1")), coin(z.getAsJsonArray("coin2"))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> inter = new ArrayList<>();
|
||||||
|
if (o.has("interactions_autorisees")) {
|
||||||
|
for (JsonElement e : o.getAsJsonArray("interactions_autorisees")) inter.add(e.getAsString());
|
||||||
|
}
|
||||||
|
int op = o.has("niveau_op_ignore") ? o.get("niveau_op_ignore").getAsInt() : 2;
|
||||||
|
return new ZonesConfig(List.copyOf(zones), op, List.copyOf(inter));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] coin(JsonArray a) {
|
||||||
|
if (a == null || a.size() != 3) throw new IllegalArgumentException("coin attendu : [x, y, z]");
|
||||||
|
return new int[]{a.get(0).getAsInt(), a.get(1).getAsInt(), a.get(2).getAsInt()};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Première zone contenant le bloc, ou null. */
|
||||||
|
public Zone zoneDe(String dim, int x, int y, int z) {
|
||||||
|
for (Zone zo : zones) if (zo.contient(dim, x, y, z)) return zo;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean proche(String dim, double x, double y, double z, double marge) {
|
||||||
|
for (Zone zo : zones) if (zo.proche(dim, x, y, z, marge)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.gastinelclaims.mixin;
|
||||||
|
|
||||||
|
import com.gastinelclaims.ZonesProtegees;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.util.RandomSource;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.LevelReader;
|
||||||
|
import net.minecraft.world.level.block.FireBlock;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
/** Le feu ne brûle aucun bloc d'une zone protégée et ne s'y propage pas. */
|
||||||
|
@Mixin(FireBlock.class)
|
||||||
|
public abstract class FireBlockMixin {
|
||||||
|
|
||||||
|
/** Combustion (destruction) d'un bloc voisin du feu. */
|
||||||
|
@Inject(method = "checkBurnOut", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void gastinelclaims$brulure(Level level, BlockPos pos, int chance, RandomSource random, int age, Direction face,
|
||||||
|
CallbackInfo ci) {
|
||||||
|
if (ZonesProtegees.protege(level, pos)) ci.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Propagation : une case de la zone n'a jamais de chance de s'enflammer. */
|
||||||
|
@Inject(method = "getIgniteOdds(Lnet/minecraft/world/level/LevelReader;Lnet/minecraft/core/BlockPos;)I",
|
||||||
|
at = @At("HEAD"), cancellable = true)
|
||||||
|
private void gastinelclaims$propagation(LevelReader level, BlockPos pos, CallbackInfoReturnable<Integer> cir) {
|
||||||
|
if (level instanceof Level l && ZonesProtegees.protege(l, pos)) cir.setReturnValue(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.gastinelclaims.mixin;
|
||||||
|
|
||||||
|
import com.gastinelclaims.ZonesProtegees;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.Direction;
|
||||||
|
import net.minecraft.world.level.BlockGetter;
|
||||||
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
import net.minecraft.world.level.material.Fluid;
|
||||||
|
import net.minecraft.world.level.material.FluidState;
|
||||||
|
import net.minecraft.world.level.material.FlowingFluid;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
/** Un liquide venu de l'extérieur n'entre jamais dans une zone protégée (les fontaines internes coulent normalement). */
|
||||||
|
@Mixin(FlowingFluid.class)
|
||||||
|
public abstract class FlowingFluidMixin {
|
||||||
|
|
||||||
|
@Inject(method = "canSpreadTo", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void gastinelclaims$zone(BlockGetter level, BlockPos from, BlockState fromState, Direction dir, BlockPos to,
|
||||||
|
BlockState toState, FluidState toFluid, Fluid fluid, CallbackInfoReturnable<Boolean> cir) {
|
||||||
|
if (ZonesProtegees.protege(level, to) && !ZonesProtegees.protege(level, from)) cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,10 @@ license="MIT"
|
|||||||
|
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="gastinelclaims"
|
modId="gastinelclaims"
|
||||||
version="1.0.0"
|
version="1.1.0"
|
||||||
displayName="GastinelClaims"
|
displayName="GastinelClaims"
|
||||||
authors="Théo Gastinel"
|
authors="Théo Gastinel"
|
||||||
description='''Protection de terrains par chunk (/claim, /unclaim, /friend). Mod côté serveur uniquement.'''
|
description='''Protection de terrains par chunk (/claim, /unclaim, /friend) et zones protégées (spawn incassable, /zoneprotegee). Mod côté serveur uniquement.'''
|
||||||
# Les clients n'ont pas besoin du mod : ne pas exiger sa présence côté client.
|
# Les clients n'ont pas besoin du mod : ne pas exiger sa présence côté client.
|
||||||
displayTest="IGNORE_ALL_VERSION"
|
displayTest="IGNORE_ALL_VERSION"
|
||||||
|
|
||||||
@@ -24,3 +24,6 @@ displayTest="IGNORE_ALL_VERSION"
|
|||||||
versionRange="[1.21.1,1.21.2)"
|
versionRange="[1.21.1,1.21.2)"
|
||||||
ordering="NONE"
|
ordering="NONE"
|
||||||
side="SERVER"
|
side="SERVER"
|
||||||
|
|
||||||
|
[[mixins]]
|
||||||
|
config="gastinelclaims.mixins.json"
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"required": true,
|
||||||
|
"minVersion": "0.8",
|
||||||
|
"package": "com.gastinelclaims.mixin",
|
||||||
|
"compatibilityLevel": "JAVA_21",
|
||||||
|
"mixins": ["FlowingFluidMixin", "FireBlockMixin"],
|
||||||
|
"injectors": {"defaultRequire": 1}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"_doc": "Zones protégées de GastinelClaims (indépendantes de /claim). Dans une zone, un joueur sans op (niveau_op_ignore) ne peut ni casser, ni poser, ni utiliser seau/briquet, ni ouvrir de coffre ; explosions, feu, liquides venus de l'extérieur, pistons et mobs n'y cassent rien. coin1/coin2 : deux coins opposés [x, y, z], bornes incluses. Ajouter une zone = ajouter un objet dans 'zones' puis /zoneprotegee recharger (op). 'active': false la désactive. interactions_autorisees : blocs qu'on peut quand même utiliser (clic droit), ids ou tags (#...). Mettre [] pour tout interdire.",
|
||||||
|
"niveau_op_ignore": 2,
|
||||||
|
"zones": [
|
||||||
|
{"nom": "spawn", "dimension": "minecraft:overworld", "coin1": [3320, 204, -566], "coin2": [3284, 185, -615]}
|
||||||
|
],
|
||||||
|
"interactions_autorisees": [
|
||||||
|
"#minecraft:buttons",
|
||||||
|
"#minecraft:pressure_plates",
|
||||||
|
"#minecraft:wooden_doors",
|
||||||
|
"#minecraft:wooden_trapdoors",
|
||||||
|
"#minecraft:fence_gates",
|
||||||
|
"minecraft:lever",
|
||||||
|
"minecraft:crafting_table",
|
||||||
|
"minecraft:ender_chest",
|
||||||
|
"minecraft:enchanting_table"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.gastinelclaims.core;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ZonesConfigTest {
|
||||||
|
|
||||||
|
private static final String OW = "minecraft:overworld";
|
||||||
|
|
||||||
|
private static ZonesConfig defaut() throws Exception {
|
||||||
|
try (InputStream in = ZonesConfigTest.class.getResourceAsStream("/gastinelclaims/zones-defaut.json")) {
|
||||||
|
return ZonesConfig.parse(new String(in.readAllBytes(), StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void zoneSpawnParDefautBornesIncluses() throws Exception {
|
||||||
|
ZonesConfig c = defaut();
|
||||||
|
assertEquals(1, c.zones.size());
|
||||||
|
ZonesConfig.Zone z = c.zones.get(0);
|
||||||
|
assertEquals("spawn", z.nom());
|
||||||
|
assertEquals(3284, z.minX()); assertEquals(3320, z.maxX());
|
||||||
|
assertEquals(185, z.minY()); assertEquals(204, z.maxY());
|
||||||
|
assertEquals(-615, z.minZ()); assertEquals(-566, z.maxZ());
|
||||||
|
assertNotNull(c.zoneDe(OW, 3300, 189, -586)); // spawn du monde
|
||||||
|
assertNotNull(c.zoneDe(OW, 3284, 185, -615)); // coin
|
||||||
|
assertNotNull(c.zoneDe(OW, 3320, 204, -566)); // coin opposé
|
||||||
|
assertNull(c.zoneDe(OW, 3321, 190, -580));
|
||||||
|
assertNull(c.zoneDe(OW, 3300, 184, -580));
|
||||||
|
assertNull(c.zoneDe(OW, 3300, 205, -580));
|
||||||
|
assertNull(c.zoneDe(OW, 3300, 190, -565));
|
||||||
|
assertNull(c.zoneDe("minecraft:the_nether", 3300, 190, -580));
|
||||||
|
assertEquals(2, c.niveauOp);
|
||||||
|
assertTrue(c.interactionsAutorisees.contains("#minecraft:buttons"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void procheAvecMarge() throws Exception {
|
||||||
|
ZonesConfig c = defaut();
|
||||||
|
assertTrue(c.proche(OW, 3323.5, 190, -580, 4));
|
||||||
|
assertFalse(c.proche(OW, 3326, 190, -580, 4));
|
||||||
|
assertTrue(c.proche(OW, 3300.5, 190.0, -580.5, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void zonesMultiplesEtInactives() {
|
||||||
|
ZonesConfig c = ZonesConfig.parse("""
|
||||||
|
{"zones":[{"nom":"a","coin1":[0,0,0],"coin2":[1,1,1]},
|
||||||
|
{"nom":"b","dimension":"minecraft:the_nether","coin1":[10,10,10],"coin2":[5,5,5]},
|
||||||
|
{"nom":"c","active":false,"coin1":[100,0,100],"coin2":[110,10,110]}]}""");
|
||||||
|
assertEquals(2, c.zones.size());
|
||||||
|
assertEquals("a", c.zoneDe(OW, 1, 1, 1).nom());
|
||||||
|
assertEquals("b", c.zoneDe("minecraft:the_nether", 7, 7, 7).nom());
|
||||||
|
assertNull(c.zoneDe(OW, 105, 5, 105));
|
||||||
|
assertTrue(c.interactionsAutorisees.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void coinInvalideRefuse() {
|
||||||
|
assertThrows(RuntimeException.class, () -> ZonesConfig.parse("{\"zones\":[{\"nom\":\"x\",\"coin1\":[0,0],\"coin2\":[1,1,1]}]}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur