GastinelTpa 1.2.1 : pseudos avec caractere non tapable (guillemet) vises sans ce caractere, ambiguite annoncee
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
608528fba1
révision
4b7f16c5af
7 fichiers modifiés
+288
-13
Aucun fichier ne correspond à votre recherche
+2
-1
@@ -4,6 +4,7 @@ Téléportations pour NeoForge 1.21.1 (21.1.234). **Mod côté serveur uniquemen
|
|||||||
|
|
||||||
## Commandes
|
## Commandes
|
||||||
- `/tpa <joueur>`, `/tpahere <joueur>`, `/tpaccept [joueur]`, `/tpadeny [joueur]` : demandes entre joueurs (expiration 1 min).
|
- `/tpa <joueur>`, `/tpahere <joueur>`, `/tpaccept [joueur]`, `/tpadeny [joueur]` : demandes entre joueurs (expiration 1 min).
|
||||||
|
- **Pseudos spéciaux (depuis 1.2.1)** : `/tpa gabybou201` vise le joueur en ligne `gabybou201"` (pseudo exact d'abord, puis forme normalisée : minuscules, hors `[A-Za-z0-9_]` retiré). Plusieurs comptes correspondent -> refus avec la liste des candidats. Tab et boutons [Accepter]/[Refuser] utilisent la forme sans guillemet. Logique pure : `core/PseudoMatcher.java`.
|
||||||
- `/spawn` : téléporte au point de spawn du monde (lu dans le monde via `getSharedSpawnPos()`, celui de `/setworldspawn`, aucune coordonnée en dur). Délai 3 s annulé si le joueur bouge ou est blessé, recharge 60 s.
|
- `/spawn` : téléporte au point de spawn du monde (lu dans le monde via `getSharedSpawnPos()`, celui de `/setworldspawn`, aucune coordonnée en dur). Délai 3 s annulé si le joueur bouge ou est blessé, recharge 60 s.
|
||||||
- `/rtp` : endroit aléatoire dans la zone **déjà générée**, jamais de nouveau chunk. Délai 3 s (annulable), recharge 300 s. Atterrissage sûr : sol solide, pas d'eau (ni profonde à côté), pas de lave/feu/magma/cactus/baies/neige poudreuse/stalactite/rose du wither autour, pas de falaise > 3 blocs, pas sur les feuilles. Évite les claims GastinelClaims des autres (par réflexion, sans dépendance).
|
- `/rtp` : endroit aléatoire dans la zone **déjà générée**, jamais de nouveau chunk. Délai 3 s (annulable), recharge 300 s. Atterrissage sûr : sol solide, pas d'eau (ni profonde à côté), pas de lave/feu/magma/cactus/baies/neige poudreuse/stalactite/rose du wither autour, pas de falaise > 3 blocs, pas sur les feuilles. Évite les claims GastinelClaims des autres (par réflexion, sans dépendance).
|
||||||
- `/rtp spawn [joueurs]` : **blocs de commande uniquement** (plaque de pression de l'entrée) ; joueur ou console -> refus avec un message clair. Sans argument : le joueur le plus proche du bloc (4 blocs). Choisit un « beau spot » de `beaux-spots.json` parmi les N meilleurs, tirage pondéré par le score (repli sur la zone /rtp si fichier absent).
|
- `/rtp spawn [joueurs]` : **blocs de commande uniquement** (plaque de pression de l'entrée) ; joueur ou console -> refus avec un message clair. Sans argument : le joueur le plus proche du bloc (4 blocs). Choisit un « beau spot » de `beaux-spots.json` parmi les N meilleurs, tirage pondéré par le score (repli sur la zone /rtp si fichier absent).
|
||||||
@@ -23,4 +24,4 @@ Un point n'est examiné que si le chunk **et ses 8 voisins** sont déjà chargé
|
|||||||
`outils/beaux_spots.py` (+ `nbt_anvil.py`, `beaux-spots-config.json`) : lit une **copie** des fichiers région (jamais le monde en service), note chaque chunk complet (relief, vue, eau 5-30 %, végétation, variété/rareté des biomes, Terralith, sûreté ; pénalités océan profond, désert plat, danger), garde 300 spots espacés d'au moins 96 blocs, score 0-10. Lancer sur cornafserver : `nice -n 19 python3 -I beaux_spots.py --monde <copie-du-monde> --config beaux-spots-config.json --sortie beaux-spots.json` (82 s pour 89 397 chunks). Limite : les scores saturent près de 10 en tête (42 spots ≥ 9,5), le tirage pondéré du top 60 est donc presque uniforme.
|
`outils/beaux_spots.py` (+ `nbt_anvil.py`, `beaux-spots-config.json`) : lit une **copie** des fichiers région (jamais le monde en service), note chaque chunk complet (relief, vue, eau 5-30 %, végétation, variété/rareté des biomes, Terralith, sûreté ; pénalités océan profond, désert plat, danger), garde 300 spots espacés d'au moins 96 blocs, score 0-10. Lancer sur cornafserver : `nice -n 19 python3 -I beaux_spots.py --monde <copie-du-monde> --config beaux-spots-config.json --sortie beaux-spots.json` (82 s pour 89 397 chunks). Limite : les scores saturent près de 10 en tête (42 spots ≥ 9,5), le tirage pondéré du top 60 est donc presque uniforme.
|
||||||
|
|
||||||
## Build (sur cornafserver)
|
## Build (sur cornafserver)
|
||||||
`sh envoyer-et-compiler.sh` depuis le PC, ou `sh build-sur-cornafserver.sh` sur le serveur (JDK 21 jetable, `nice`, 4 Go max). Tests JUnit (`core/`) puis `build/libs/gastineltpa-neoforge-1.21.1-1.2.0.jar`.
|
`sh envoyer-et-compiler.sh` depuis le PC, ou `sh build-sur-cornafserver.sh` sur le serveur (JDK 21 jetable, `nice`, 4 Go max). Tests JUnit (`core/`) puis `build/libs/gastineltpa-neoforge-1.21.1-1.2.1.jar`.
|
||||||
@@ -6,5 +6,5 @@ tar czf /tmp/gastineltpa-src.tgz --exclude=build --exclude=.gradle --exclude=bui
|
|||||||
scp /tmp/gastineltpa-src.tgz cornafserver:gastineltpa-src.tgz
|
scp /tmp/gastineltpa-src.tgz cornafserver:gastineltpa-src.tgz
|
||||||
ssh cornafserver 'set -e; rm -rf "$HOME/staging/GastinelTpa"; mkdir -p "$HOME/staging/GastinelTpa"; tar xzf "$HOME/gastineltpa-src.tgz" -C "$HOME/staging/GastinelTpa"; rm "$HOME/gastineltpa-src.tgz"; cd "$HOME/staging/GastinelTpa" && sh build-sur-cornafserver.sh'
|
ssh cornafserver 'set -e; rm -rf "$HOME/staging/GastinelTpa"; mkdir -p "$HOME/staging/GastinelTpa"; tar xzf "$HOME/gastineltpa-src.tgz" -C "$HOME/staging/GastinelTpa"; rm "$HOME/gastineltpa-src.tgz"; cd "$HOME/staging/GastinelTpa" && sh build-sur-cornafserver.sh'
|
||||||
mkdir -p build-out
|
mkdir -p build-out
|
||||||
scp 'cornafserver:staging/GastinelTpa/build/libs/gastineltpa-neoforge-1.21.1-1.2.0.jar' build-out/
|
scp 'cornafserver:staging/GastinelTpa/build/libs/gastineltpa-neoforge-1.21.1-1.2.1.jar' build-out/
|
||||||
ls -l build-out
|
ls -l build-out
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
org.gradle.jvmargs=-Xmx2G
|
org.gradle.jvmargs=-Xmx2G
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
mod_version=1.2.0
|
mod_version=1.2.1
|
||||||
mod_group_id=com.gastineltpa
|
mod_group_id=com.gastineltpa
|
||||||
mod_id=gastineltpa
|
mod_id=gastineltpa
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.gastineltpa;
|
package com.gastineltpa;
|
||||||
|
|
||||||
|
import com.gastineltpa.core.PseudoMatcher;
|
||||||
|
import com.gastineltpa.core.PseudoMatcher.Profil;
|
||||||
import com.gastineltpa.core.TpaRegistry;
|
import com.gastineltpa.core.TpaRegistry;
|
||||||
import com.gastineltpa.core.TpaRegistry.Request;
|
import com.gastineltpa.core.TpaRegistry.Request;
|
||||||
import com.gastineltpa.core.TpaRegistry.Type;
|
import com.gastineltpa.core.TpaRegistry.Type;
|
||||||
@@ -47,13 +49,13 @@ public final class TpaCommands {
|
|||||||
d.register(Commands.literal("tpa")
|
d.register(Commands.literal("tpa")
|
||||||
.then(Commands.argument("joueur", StringArgumentType.word())
|
.then(Commands.argument("joueur", StringArgumentType.word())
|
||||||
.suggests((ctx, b) -> SharedSuggestionProvider.suggest(
|
.suggests((ctx, b) -> SharedSuggestionProvider.suggest(
|
||||||
ctx.getSource().getServer().getPlayerNames(), b))
|
PseudoMatcher.suggestions(List.of(ctx.getSource().getServer().getPlayerNames())), b))
|
||||||
.executes(ctx -> demander(ctx, Type.TPA))));
|
.executes(ctx -> demander(ctx, Type.TPA))));
|
||||||
|
|
||||||
d.register(Commands.literal("tpahere")
|
d.register(Commands.literal("tpahere")
|
||||||
.then(Commands.argument("joueur", StringArgumentType.word())
|
.then(Commands.argument("joueur", StringArgumentType.word())
|
||||||
.suggests((ctx, b) -> SharedSuggestionProvider.suggest(
|
.suggests((ctx, b) -> SharedSuggestionProvider.suggest(
|
||||||
ctx.getSource().getServer().getPlayerNames(), b))
|
PseudoMatcher.suggestions(List.of(ctx.getSource().getServer().getPlayerNames())), b))
|
||||||
.executes(ctx -> demander(ctx, Type.TPAHERE))));
|
.executes(ctx -> demander(ctx, Type.TPAHERE))));
|
||||||
|
|
||||||
d.register(Commands.literal("tpaccept")
|
d.register(Commands.literal("tpaccept")
|
||||||
@@ -126,7 +128,9 @@ public final class TpaCommands {
|
|||||||
nettoyerExpirees(server);
|
nettoyerExpirees(server);
|
||||||
|
|
||||||
String nom = StringArgumentType.getString(ctx, "joueur");
|
String nom = StringArgumentType.getString(ctx, "joueur");
|
||||||
ServerPlayer cible = server.getPlayerList().getPlayerByName(nom);
|
Cherche c = chercherEnLigne(server, nom);
|
||||||
|
if (c.ambigu != null) return echec(ctx, c.ambigu);
|
||||||
|
ServerPlayer cible = c.joueur;
|
||||||
if (cible == null) {
|
if (cible == null) {
|
||||||
return echec(ctx, "Joueur introuvable ou hors ligne : " + nom);
|
return echec(ctx, "Joueur introuvable ou hors ligne : " + nom);
|
||||||
}
|
}
|
||||||
@@ -146,9 +150,9 @@ public final class TpaCommands {
|
|||||||
.append(Component.literal(type == Type.TPA
|
.append(Component.literal(type == Type.TPA
|
||||||
? nomMoi + " souhaite se téléporter vers toi. "
|
? nomMoi + " souhaite se téléporter vers toi. "
|
||||||
: nomMoi + " souhaite que tu te téléportes vers lui. ").withStyle(ChatFormatting.YELLOW))
|
: nomMoi + " souhaite que tu te téléportes vers lui. ").withStyle(ChatFormatting.YELLOW))
|
||||||
.append(bouton("[Accepter]", "/tpaccept " + nomMoi, ChatFormatting.GREEN, "Accepter la demande"))
|
.append(bouton("[Accepter]", "/tpaccept " + PseudoMatcher.tapable(nomMoi), ChatFormatting.GREEN, "Accepter la demande"))
|
||||||
.append(Component.literal(" "))
|
.append(Component.literal(" "))
|
||||||
.append(bouton("[Refuser]", "/tpadeny " + nomMoi, ChatFormatting.RED, "Refuser la demande"))
|
.append(bouton("[Refuser]", "/tpadeny " + PseudoMatcher.tapable(nomMoi), ChatFormatting.RED, "Refuser la demande"))
|
||||||
.append(Component.literal(" (expire dans 60 s)").withStyle(ChatFormatting.GRAY));
|
.append(Component.literal(" (expire dans 60 s)").withStyle(ChatFormatting.GRAY));
|
||||||
cible.sendSystemMessage(msg);
|
cible.sendSystemMessage(msg);
|
||||||
return 1;
|
return 1;
|
||||||
@@ -168,7 +172,9 @@ public final class TpaCommands {
|
|||||||
return echec(ctx, "Aucune demande de téléportation en attente.");
|
return echec(ctx, "Aucune demande de téléportation en attente.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ServerPlayer demandeur = server.getPlayerList().getPlayerByName(nomDemandeur);
|
Cherche c = chercherEnLigne(server, nomDemandeur);
|
||||||
|
if (c.ambigu != null) return echec(ctx, c.ambigu);
|
||||||
|
ServerPlayer demandeur = c.joueur;
|
||||||
if (demandeur == null) {
|
if (demandeur == null) {
|
||||||
return echec(ctx, "Joueur introuvable ou hors ligne : " + nomDemandeur);
|
return echec(ctx, "Joueur introuvable ou hors ligne : " + nomDemandeur);
|
||||||
}
|
}
|
||||||
@@ -215,7 +221,9 @@ public final class TpaCommands {
|
|||||||
annulee = REGISTRE.cancel(moi.getUUID(), null);
|
annulee = REGISTRE.cancel(moi.getUUID(), null);
|
||||||
if (annulee.isEmpty()) return echec(ctx, "Tu n'as aucune demande de téléportation en cours à annuler.");
|
if (annulee.isEmpty()) return echec(ctx, "Tu n'as aucune demande de téléportation en cours à annuler.");
|
||||||
} else {
|
} else {
|
||||||
ServerPlayer cible = server.getPlayerList().getPlayerByName(nomCible);
|
Cherche c = chercherEnLigne(server, nomCible);
|
||||||
|
if (c.ambigu != null) return echec(ctx, c.ambigu);
|
||||||
|
ServerPlayer cible = c.joueur;
|
||||||
annulee = cible == null ? Optional.empty() : REGISTRE.cancel(moi.getUUID(), cible.getUUID());
|
annulee = cible == null ? Optional.empty() : REGISTRE.cancel(moi.getUUID(), cible.getUUID());
|
||||||
if (annulee.isEmpty()) return echec(ctx, "Tu n'as aucune demande en cours vers " + nomCible + ".");
|
if (annulee.isEmpty()) return echec(ctx, "Tu n'as aucune demande en cours vers " + nomCible + ".");
|
||||||
}
|
}
|
||||||
@@ -238,11 +246,31 @@ public final class TpaCommands {
|
|||||||
ServerPlayer p = moi.server.getPlayerList().getPlayer(r.to());
|
ServerPlayer p = moi.server.getPlayerList().getPlayer(r.to());
|
||||||
if (p != null) noms.add(p.getGameProfile().getName());
|
if (p != null) noms.add(p.getGameProfile().getName());
|
||||||
}
|
}
|
||||||
return SharedSuggestionProvider.suggest(noms, b);
|
return SharedSuggestionProvider.suggest(PseudoMatcher.suggestions(noms), b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Utilitaires ---
|
// --- Utilitaires ---
|
||||||
|
|
||||||
|
/** Résultat de la recherche d'un joueur en ligne : soit un joueur, soit un message d'ambiguïté, soit rien. */
|
||||||
|
private record Cherche(ServerPlayer joueur, String ambigu) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pseudo exact d'abord, puis forme normalisée (sans guillemet etc.) parmi les joueurs en ligne.
|
||||||
|
* Si plusieurs comptes ressemblent à la saisie, on ne choisit pas : message avec les candidats.
|
||||||
|
*/
|
||||||
|
private static Cherche chercherEnLigne(MinecraftServer server, String saisie) {
|
||||||
|
List<Profil> enLigne = new ArrayList<>();
|
||||||
|
for (ServerPlayer sp : server.getPlayerList().getPlayers()) {
|
||||||
|
enLigne.add(new Profil(sp.getUUID(), sp.getGameProfile().getName()));
|
||||||
|
}
|
||||||
|
PseudoMatcher.Resultat r = PseudoMatcher.resoudreParmi(saisie, enLigne);
|
||||||
|
if (r.statut() == PseudoMatcher.Statut.AMBIGU) {
|
||||||
|
return new Cherche(null, PseudoMatcher.messageAmbigu(saisie, r.candidats()));
|
||||||
|
}
|
||||||
|
if (r.trouve()) return new Cherche(server.getPlayerList().getPlayer(r.profil().id()), null);
|
||||||
|
return new Cherche(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
/** Téléporte vers la position de la destination (même dimension ou non), en gardant le regard du voyageur. */
|
/** Téléporte vers la position de la destination (même dimension ou non), en gardant le regard du voyageur. */
|
||||||
private static void teleporter(ServerPlayer voyageur, ServerPlayer destination) {
|
private static void teleporter(ServerPlayer voyageur, ServerPlayer destination) {
|
||||||
ServerLevel niveau = destination.serverLevel();
|
ServerLevel niveau = destination.serverLevel();
|
||||||
@@ -275,7 +303,7 @@ public final class TpaCommands {
|
|||||||
ServerPlayer p = moi.server.getPlayerList().getPlayer(r.from());
|
ServerPlayer p = moi.server.getPlayerList().getPlayer(r.from());
|
||||||
if (p != null) noms.add(p.getGameProfile().getName());
|
if (p != null) noms.add(p.getGameProfile().getName());
|
||||||
}
|
}
|
||||||
return SharedSuggestionProvider.suggest(noms, b);
|
return SharedSuggestionProvider.suggest(PseudoMatcher.suggestions(noms), b);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MutableComponent bouton(String texte, String commande, ChatFormatting couleur, String survol) {
|
private static MutableComponent bouton(String texte, String commande, ChatFormatting couleur, String survol) {
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.gastineltpa.core;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Résolution tolérante d'un pseudo tapé en commande (logique pure, sans Minecraft).
|
||||||
|
*
|
||||||
|
* Problème : un pseudo hors-ligne peut contenir des caractères qu'un argument {@code word()} ne sait pas
|
||||||
|
* taper (ex. {@code gabybou201"}). Règle : on compare d'abord le pseudo exact (sans tenir compte de la casse),
|
||||||
|
* puis les formes normalisées (minuscules, tout ce qui n'est pas [A-Za-z0-9_] retiré).
|
||||||
|
* Sécurité : si la forme normalisée correspond à PLUSIEURS comptes différents (UUID différents), on ne choisit
|
||||||
|
* jamais : le résultat est AMBIGU et la liste des candidats est annoncée. L'UUID retenu est toujours celui du
|
||||||
|
* vrai profil trouvé, jamais un UUID recalculé à partir du texte tapé.
|
||||||
|
*
|
||||||
|
* Ordre : joueurs en ligne d'abord ; le cache de profils (usercache) n'est consulté que si aucun joueur en ligne
|
||||||
|
* ne correspond.
|
||||||
|
*/
|
||||||
|
public final class PseudoMatcher {
|
||||||
|
|
||||||
|
public record Profil(UUID id, String nom) { }
|
||||||
|
|
||||||
|
public enum Statut { TROUVE, AMBIGU, INCONNU }
|
||||||
|
|
||||||
|
/** approximatif : vrai si le pseudo tapé diffère du vrai pseudo (match par forme normalisée). */
|
||||||
|
public record Resultat(Statut statut, Profil profil, List<Profil> candidats, boolean approximatif) {
|
||||||
|
public boolean trouve() { return statut == Statut.TROUVE; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Resultat INCONNU = new Resultat(Statut.INCONNU, null, List.of(), false);
|
||||||
|
|
||||||
|
/** Minuscules, caractères hors [A-Za-z0-9_] retirés. */
|
||||||
|
public static String normaliser(String s) {
|
||||||
|
if (s == null) return "";
|
||||||
|
StringBuilder sb = new StringBuilder(s.length());
|
||||||
|
for (int i = 0; i < s.length(); i++) {
|
||||||
|
char c = s.charAt(i);
|
||||||
|
if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') sb.append(c);
|
||||||
|
else if (c >= 'A' && c <= 'Z') sb.append((char) (c + 32));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Forme tapable dans un argument word() de Brigadier : [0-9A-Za-z_.+-] seulement. */
|
||||||
|
public static String tapable(String nom) {
|
||||||
|
if (nom == null) return "";
|
||||||
|
StringBuilder sb = new StringBuilder(nom.length());
|
||||||
|
for (int i = 0; i < nom.length(); i++) {
|
||||||
|
char c = nom.charAt(i);
|
||||||
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')
|
||||||
|
|| c == '_' || c == '.' || c == '+' || c == '-') sb.append(c);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Suggestions (tab) : formes tapables, sans doublon, ordre conservé, sans entrée vide. */
|
||||||
|
public static List<String> suggestions(Collection<String> noms) {
|
||||||
|
LinkedHashSet<String> out = new LinkedHashSet<>();
|
||||||
|
for (String n : noms) {
|
||||||
|
String t = tapable(n);
|
||||||
|
if (!t.isEmpty()) out.add(t);
|
||||||
|
}
|
||||||
|
return new ArrayList<>(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Un seul groupe de profils (ex. les joueurs en ligne, ou les amis). */
|
||||||
|
public static Resultat resoudreParmi(String saisie, Collection<Profil> profils) {
|
||||||
|
return resoudre(saisie, profils, List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Resultat resoudre(String saisie, Collection<Profil> enLigne, Collection<Profil> cache) {
|
||||||
|
if (saisie == null || saisie.isEmpty()) return INCONNU;
|
||||||
|
Resultat r = etape(saisie, dedoublonner(enLigne), false);
|
||||||
|
if (r.statut() != Statut.INCONNU) return r;
|
||||||
|
return etape(saisie, dedoublonner(cache), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strict (cache) : un pseudo exact qui partage sa forme normalisée avec un AUTRE compte reste AMBIGU
|
||||||
|
* (profils fantômes d'anciens essais) : on ne désigne pas un compte au hasard.
|
||||||
|
*/
|
||||||
|
private static Resultat etape(String saisie, List<Profil> profils, boolean strict) {
|
||||||
|
List<Profil> exacts = new ArrayList<>();
|
||||||
|
for (Profil p : profils) if (p.nom().equalsIgnoreCase(saisie)) exacts.add(p);
|
||||||
|
String norm = normaliser(saisie);
|
||||||
|
List<Profil> proches = new ArrayList<>();
|
||||||
|
if (!norm.isEmpty()) for (Profil p : profils) if (normaliser(p.nom()).equals(norm)) proches.add(p);
|
||||||
|
|
||||||
|
if (exacts.size() == 1 && (!strict || proches.size() <= 1)) {
|
||||||
|
return new Resultat(Statut.TROUVE, exacts.get(0), List.of(exacts.get(0)), false);
|
||||||
|
}
|
||||||
|
if (!exacts.isEmpty()) {
|
||||||
|
// plusieurs exacts (casse différente) ou exact + comptes proches dans le cache : jamais au hasard
|
||||||
|
return new Resultat(Statut.AMBIGU, null, List.copyOf(strict ? proches : exacts), false);
|
||||||
|
}
|
||||||
|
if (proches.size() == 1) return new Resultat(Statut.TROUVE, proches.get(0), proches, true);
|
||||||
|
if (proches.size() > 1) return new Resultat(Statut.AMBIGU, null, List.copyOf(proches), true);
|
||||||
|
return INCONNU;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Profil> dedoublonner(Collection<Profil> profils) {
|
||||||
|
Map<UUID, Profil> m = new LinkedHashMap<>();
|
||||||
|
for (Profil p : profils) if (p != null && p.id() != null && p.nom() != null) m.putIfAbsent(p.id(), p);
|
||||||
|
return new ArrayList<>(m.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Message clair listant les candidats (vrais pseudos). */
|
||||||
|
public static String messageAmbigu(String saisie, List<Profil> candidats) {
|
||||||
|
StringBuilder sb = new StringBuilder("Plusieurs joueurs ressemblent à « ").append(saisie).append(" » : ");
|
||||||
|
for (int i = 0; i < candidats.size(); i++) {
|
||||||
|
if (i > 0) sb.append(", ");
|
||||||
|
sb.append(candidats.get(i).nom());
|
||||||
|
}
|
||||||
|
return sb.append(". Je ne choisis pas à ta place : fais-le te rejoindre en ligne, ou tape le pseudo exact.").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PseudoMatcher() { }
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ license="MIT"
|
|||||||
|
|
||||||
[[mods]]
|
[[mods]]
|
||||||
modId="gastineltpa"
|
modId="gastineltpa"
|
||||||
version="1.2.0"
|
version="1.2.1"
|
||||||
displayName="GastinelTpa"
|
displayName="GastinelTpa"
|
||||||
authors="Théo Gastinel"
|
authors="Théo Gastinel"
|
||||||
description='''Demandes de téléportation entre joueurs (/tpa, /tpahere, /tpaccept, /tpadeny), /spawn, /rtp et /rtp spawn (blocs de commande). Mod côté serveur uniquement.'''
|
description='''Demandes de téléportation entre joueurs (/tpa, /tpahere, /tpaccept, /tpadeny), /spawn, /rtp et /rtp spawn (blocs de commande). Mod côté serveur uniquement.'''
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.gastineltpa.core;
|
||||||
|
|
||||||
|
import com.gastineltpa.core.PseudoMatcher.Profil;
|
||||||
|
import com.gastineltpa.core.PseudoMatcher.Statut;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class PseudoMatcherTest {
|
||||||
|
|
||||||
|
private static final UUID GABY = UUID.fromString("128c0f10-9643-37ff-941d-afa49cdb30ec");
|
||||||
|
private static final UUID GABY_FANTOME = UUID.fromString("e65f2350-d100-3a51-ae80-50fbcce624c0");
|
||||||
|
private static final UUID GABY_BIZARRE = UUID.fromString("607ba0dc-3032-3d7d-9330-e0345e4eec23");
|
||||||
|
private static final UUID THEO = UUID.fromString("e1769fd1-91f1-377b-b2ac-999a4a7c9c9e");
|
||||||
|
|
||||||
|
private static final Profil GABY_P = new Profil(GABY, "gabybou201\"");
|
||||||
|
private static final Profil FANTOME_P = new Profil(GABY_FANTOME, "gabybou201");
|
||||||
|
private static final Profil BIZARRE_P = new Profil(GABY_BIZARRE, "\"gabybou201\"\"");
|
||||||
|
private static final Profil THEO_P = new Profil(THEO, "totoche10");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void normalisation() {
|
||||||
|
assertEquals("gabybou201", PseudoMatcher.normaliser("gabybou201\""));
|
||||||
|
assertEquals("steve_1", PseudoMatcher.normaliser("Ste.ve_1"));
|
||||||
|
assertEquals("", PseudoMatcher.normaliser("\"\"-"));
|
||||||
|
assertEquals("", PseudoMatcher.normaliser(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tapable() {
|
||||||
|
assertEquals("gabybou201", PseudoMatcher.tapable("gabybou201\""));
|
||||||
|
assertEquals("a.b-c+d_e", PseudoMatcher.tapable("a.b-c+d_e"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sansGuillemetVisePseudoAvecGuillemetEnLigne() {
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(THEO_P, GABY_P), List.of(FANTOME_P, GABY_P));
|
||||||
|
assertEquals(Statut.TROUVE, r.statut());
|
||||||
|
assertEquals(GABY, r.profil().id());
|
||||||
|
assertEquals("gabybou201\"", r.profil().nom());
|
||||||
|
assertTrue(r.approximatif());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void enLigneEstPrioritaireSurLeCacheMemeAvecFantome() {
|
||||||
|
var r = PseudoMatcher.resoudre("GabyBou201", List.of(GABY_P), List.of(FANTOME_P, BIZARRE_P, GABY_P));
|
||||||
|
assertTrue(r.trouve());
|
||||||
|
assertEquals(GABY, r.profil().id());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void exactEnLigneNeEstPasDetourne() {
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(FANTOME_P, GABY_P), List.of());
|
||||||
|
assertTrue(r.trouve());
|
||||||
|
assertEquals(GABY_FANTOME, r.profil().id());
|
||||||
|
assertFalse(r.approximatif());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deuxEnLigneProchesSansExactEstAmbigu() {
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(GABY_P, BIZARRE_P), List.of());
|
||||||
|
assertEquals(Statut.AMBIGU, r.statut());
|
||||||
|
assertEquals(2, r.candidats().size());
|
||||||
|
String m = PseudoMatcher.messageAmbigu("gabybou201", r.candidats());
|
||||||
|
assertTrue(m.contains("gabybou201\"") && m.contains("\"gabybou201\"\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cacheHorsLigneAvecFantomeEstAmbigu() {
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(THEO_P), List.of(FANTOME_P, GABY_P, BIZARRE_P));
|
||||||
|
assertEquals(Statut.AMBIGU, r.statut());
|
||||||
|
assertEquals(3, r.candidats().size());
|
||||||
|
assertNull(r.profil());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cacheUnSeulCandidatApproximatif() {
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(), List.of(GABY_P, THEO_P));
|
||||||
|
assertTrue(r.trouve());
|
||||||
|
assertEquals(GABY, r.profil().id());
|
||||||
|
assertTrue(r.approximatif());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void cacheExactUniqueResteExact() {
|
||||||
|
var r = PseudoMatcher.resoudre("TOTOCHE10", List.of(), List.of(GABY_P, THEO_P));
|
||||||
|
assertTrue(r.trouve());
|
||||||
|
assertEquals(THEO, r.profil().id());
|
||||||
|
assertFalse(r.approximatif());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void inconnuEtVide() {
|
||||||
|
assertEquals(Statut.INCONNU, PseudoMatcher.resoudre("zorglub", List.of(GABY_P), List.of(THEO_P)).statut());
|
||||||
|
assertEquals(Statut.INCONNU, PseudoMatcher.resoudre("", List.of(GABY_P), List.of()).statut());
|
||||||
|
assertEquals(Statut.INCONNU, PseudoMatcher.resoudre("---", List.of(GABY_P), List.of()).statut());
|
||||||
|
assertEquals(Statut.INCONNU, PseudoMatcher.resoudre(null, List.of(GABY_P), List.of()).statut());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void memeUuidSousDeuxNomsNEstPasAmbigu() {
|
||||||
|
var autreNom = new Profil(GABY, "GabyBou201");
|
||||||
|
var r = PseudoMatcher.resoudre("gabybou201", List.of(), List.of(GABY_P, autreNom));
|
||||||
|
assertTrue(r.trouve());
|
||||||
|
assertEquals(GABY, r.profil().id());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void uuidRetenuEstCeluiDuProfil() {
|
||||||
|
var r = PseudoMatcher.resoudreParmi("gabybou201", List.of(GABY_P));
|
||||||
|
assertEquals(GABY, r.profil().id());
|
||||||
|
assertNotEquals(GABY_FANTOME, r.profil().id());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void suggestionsSansGuillemetNiDoublon() {
|
||||||
|
assertEquals(List.of("gabybou201", "totoche10", "gabybou201x"),
|
||||||
|
PseudoMatcher.suggestions(List.of("gabybou201\"", "totoche10", "gabybou201", "\"\"", "gabybou201x")));
|
||||||
|
}
|
||||||
|
}
|
||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur