- /spawn : spawn du monde (getSharedSpawnPos), délai annulé si mouvement/blessure, recharge. - /rtp : zone déjà générée uniquement (chunk + 8 voisins complets sur disque, région absente jamais lue), atterrissage sûr, évite les claims GastinelClaims, recharge, messages FR. - /rtp spawn : réservé aux blocs de commande, tirage pondéré parmi le top N de beaux-spots.json. - /rtp diagnostic (op) : recherche sans téléportation, avec motifs de rejet. - outils/beaux_spots.py : notation de beauté v0 sur une copie du monde. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
55 lignes
2.3 KiB
Java
55 lignes
2.3 KiB
Java
package com.gastineltpa;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.neoforged.fml.ModList;
|
|
|
|
import java.lang.reflect.Constructor;
|
|
import java.lang.reflect.Method;
|
|
import java.util.UUID;
|
|
|
|
/**
|
|
* Lien optionnel vers GastinelClaims, par réflexion (pas de dépendance de compilation) :
|
|
* si le mod est absent ou change d'API, on considère qu'il n'y a pas de claim (et on le journalise une fois).
|
|
*/
|
|
final class ClaimsBridge {
|
|
|
|
private static boolean init;
|
|
private static Method get, registry, canAccess;
|
|
private static Constructor<?> chunkKey;
|
|
|
|
private ClaimsBridge() {}
|
|
|
|
private static synchronized boolean pret() {
|
|
if (init) return get != null;
|
|
init = true;
|
|
if (!ModList.get().isLoaded("gastinelclaims")) return false;
|
|
try {
|
|
Class<?> data = Class.forName("com.gastinelclaims.ClaimsData");
|
|
Class<?> reg = Class.forName("com.gastinelclaims.core.ClaimRegistry");
|
|
Class<?> key = Class.forName("com.gastinelclaims.core.ChunkKey");
|
|
get = data.getMethod("get", MinecraftServer.class);
|
|
registry = data.getMethod("registry");
|
|
canAccess = reg.getMethod("canAccess", UUID.class, key, boolean.class);
|
|
chunkKey = key.getConstructor(String.class, int.class, int.class);
|
|
GastinelTpa.LOGGER.info("[GastinelTpa] GastinelClaims détecté : /rtp évite les claims des autres.");
|
|
} catch (ReflectiveOperationException e) {
|
|
get = null;
|
|
GastinelTpa.LOGGER.warn("[GastinelTpa] API GastinelClaims introuvable, claims ignorés : {}", e.toString());
|
|
}
|
|
return get != null;
|
|
}
|
|
|
|
/** Vrai si le joueur a le droit d'être dans ce chunk (pas de claim, le sien, ou celui d'un ami). */
|
|
static boolean autorise(ServerLevel level, UUID joueur, int blocX, int blocZ) {
|
|
if (!pret()) return true;
|
|
try {
|
|
Object reg = registry.invoke(get.invoke(null, level.getServer()));
|
|
Object key = chunkKey.newInstance(level.dimension().location().toString(), blocX >> 4, blocZ >> 4);
|
|
return (Boolean) canAccess.invoke(reg, joueur, key, false);
|
|
} catch (ReflectiveOperationException | RuntimeException e) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|