From b1fa18248ca0494e294267d2f53418a6e808fb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Thu, 15 Oct 2026 01:04:46 +0200 Subject: [PATCH] GastinelClaims 1.1.2 : /friend ignore les profils Microsoft du cache en mode hors-ligne Co-Authored-By: Claude Opus 5.5 --- gradle.properties | 2 +- .../com/gastinelclaims/ClaimCommands.java | 4 +++- .../gastinelclaims/core/PseudoMatcher.java | 16 ++++++++++++++++ .../resources/META-INF/neoforge.mods.toml | 2 +- .../core/PseudoMatcherTest.java | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2084c91..743d52c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true -mod_version=1.1.1 +mod_version=1.1.2 mod_group_id=com.gastinelclaims mod_id=gastinelclaims diff --git a/src/main/java/com/gastinelclaims/ClaimCommands.java b/src/main/java/com/gastinelclaims/ClaimCommands.java index b20858b..9115abb 100644 --- a/src/main/java/com/gastinelclaims/ClaimCommands.java +++ b/src/main/java/com/gastinelclaims/ClaimCommands.java @@ -204,7 +204,9 @@ public final class ClaimCommands { for (ServerPlayer sp : server.getPlayerList().getPlayers()) { enLigne.add(new Profil(sp.getUUID(), sp.getGameProfile().getName())); } - return PseudoMatcher.resoudre(saisie, enLigne, profilsDuCache(server)); + List cache = profilsDuCache(server); + if (!server.usesAuthentication()) cache = PseudoMatcher.garderHorsLigne(cache); + return PseudoMatcher.resoudre(saisie, enLigne, cache); } /** Lit usercache.json (écrit par le serveur à chaque ajout) ; liste vide en cas de problème. */ diff --git a/src/main/java/com/gastinelclaims/core/PseudoMatcher.java b/src/main/java/com/gastinelclaims/core/PseudoMatcher.java index 5967c08..8a65d25 100644 --- a/src/main/java/com/gastinelclaims/core/PseudoMatcher.java +++ b/src/main/java/com/gastinelclaims/core/PseudoMatcher.java @@ -92,6 +92,22 @@ public final class PseudoMatcher { return new ArrayList<>(out); } + /** UUID qu'un serveur en mode hors-ligne attribue à ce pseudo (version 3 de « OfflinePlayer: »). */ + public static UUID uuidHorsLigne(String nom) { + return UUID.nameUUIDFromBytes(("OfflinePlayer:" + nom).getBytes(java.nio.charset.StandardCharsets.UTF_8)); + } + + /** + * Serveur hors-ligne : ne garde que les profils joignables, c'est-à-dire dont l'UUID est l'UUID hors-ligne du + * pseudo. Les UUID Microsoft du cache (venus de whitelist/ops) ne peuvent pas se connecter et rendraient le + * pseudo ambigu (deux « totoche10 »). + */ + public static List garderHorsLigne(Collection profils) { + List out = new ArrayList<>(); + for (Profil p : profils) if (p != null && p.nom() != null && uuidHorsLigne(p.nom()).equals(p.id())) out.add(p); + return out; + } + /** Un seul groupe de profils (ex. les joueurs en ligne, ou les amis). */ public static Resultat resoudreParmi(String saisie, Collection profils) { return resoudre(saisie, profils, List.of()); diff --git a/src/main/resources/META-INF/neoforge.mods.toml b/src/main/resources/META-INF/neoforge.mods.toml index b9a5bd8..6b7cb8d 100644 --- a/src/main/resources/META-INF/neoforge.mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -4,7 +4,7 @@ license="MIT" [[mods]] modId="gastinelclaims" -version="1.1.1" +version="1.1.2" displayName="GastinelClaims" authors="Théo Gastinel" description='''Protection de terrains par chunk (/claim, /unclaim, /friend) et zones protégées (spawn incassable, /zoneprotegee). Mod côté serveur uniquement.''' diff --git a/src/test/java/com/gastinelclaims/core/PseudoMatcherTest.java b/src/test/java/com/gastinelclaims/core/PseudoMatcherTest.java index 0b7b5ad..44673c2 100644 --- a/src/test/java/com/gastinelclaims/core/PseudoMatcherTest.java +++ b/src/test/java/com/gastinelclaims/core/PseudoMatcherTest.java @@ -160,4 +160,23 @@ class PseudoMatcherTest { assertEquals(List.of("gabybou201", "totoche10", "gabybou201x"), PseudoMatcher.suggestions(List.of("gabybou201\"", "totoche10", "gabybou201", "\"\"", "gabybou201x"))); } + + @Test + void horsLigne_uuidConnusDesPseudos() { + // Valeurs relevées sur le serveur (usercache.json, 13/10/2026). + assertEquals(UUID.fromString("e1769fd1-91f1-377b-b2ac-999a4a7c9c9e"), PseudoMatcher.uuidHorsLigne("totoche10")); + assertEquals(UUID.fromString("128c0f10-9643-37ff-941d-afa49cdb30ec"), PseudoMatcher.uuidHorsLigne("gabybou201\"")); + } + + @Test + void horsLigne_uuidMicrosoftIgnore_plusDAmbiguite() { + Profil horsLigne = new Profil(PseudoMatcher.uuidHorsLigne("totoche10"), "totoche10"); + Profil microsoft = new Profil(UUID.fromString("25b71084-eb1b-4988-8cfe-458026f7e514"), "totoche10"); + assertEquals(Statut.AMBIGU, PseudoMatcher.resoudre("totoche10", List.of(), List.of(horsLigne, microsoft)).statut()); + var cache = PseudoMatcher.garderHorsLigne(List.of(horsLigne, microsoft)); + assertEquals(List.of(horsLigne), cache); + var r = PseudoMatcher.resoudre("totoche10", List.of(), cache); + assertEquals(Statut.TROUVE, r.statut()); + assertEquals(horsLigne.id(), r.profil().id()); + } }