feat: Full support for multi-color gradients in /guild color, MiniMessage, and TAB with Terra World Generator

This commit is contained in:
2026-08-20 22:06:25 +02:00
parent efdfcb75fb
commit 0dd8802bee
4 changed files with 36 additions and 19 deletions
@@ -781,13 +781,14 @@ public class GuildCommands {
)
// -------------------------------------------------------------
// Sous-commande : /guild color <#hex>
// Sous-commande : /guild color <#hex1> [hex2]
// -------------------------------------------------------------
.subcommand(BetterMcCommands.subBuilder("color")
.description("Changer la couleur hexadécimale de votre guilde")
.aliases("couleur")
.description("Changer la couleur ou le dégradé de votre guilde")
.aliases("couleur", "setcolor")
.playerOnly()
.argument(Arguments.string("hex").description("Code couleur hexadécimal (ex: #FF5555)"))
.argument(Arguments.string("hex").description("Code couleur hexadécimal (ex: #00C9FF ou #00C9FF:#92FE9D)"))
.argument(Arguments.string("hex2").optional().description("Code secondaire pour dégradé (ex: #92FE9D)"))
.validate(context -> {
if (!guildManager.isInGuild(context.getPlayer().getUniqueId())) {
return ValidationResult.invalid(msg.get("guild.not_in_guild"));
@@ -796,8 +797,11 @@ public class GuildCommands {
if (g == null || !g.hasPermission(context.getPlayer().getUniqueId(), GuildPermission.MANAGE_GUILD)) {
return ValidationResult.invalid("<red>Votre rang ne vous autorise pas à modifier les informations de la guilde.</red>");
}
if (!context.getString("hex").matches("^#[0-9a-fA-F]{6}$")) {
return ValidationResult.invalid("<red>Format de couleur invalide ! Utilisez un code hexadécimal à 6 caractères (ex: <yellow>#00FFAA</yellow> ou <yellow>#FF5555</yellow>).</red>");
String hex = context.getString("hex");
Optional<String> hex2Opt = context.getOptional("hex2", String.class);
String full = (hex2Opt.isPresent() && !hex2Opt.get().isEmpty()) ? hex + ":" + hex2Opt.get() : hex;
if (!full.matches("^#[0-9a-fA-F]{6}(:#[0-9a-fA-F]{6})*$")) {
return ValidationResult.invalid("<red>Format de couleur invalide ! Utilisez un code hexadécimal (ex: <yellow>#00FFAA</yellow>) ou un dégradé (ex: <yellow>#00C9FF #92FE9D</yellow> ou <yellow>#00C9FF:#92FE9D</yellow>).</red>");
}
return ValidationResult.valid();
})
@@ -805,8 +809,10 @@ public class GuildCommands {
Player player = context.getPlayer();
Guild guild = guildManager.getGuildByPlayer(player.getUniqueId());
String hex = context.getString("hex");
Optional<String> hex2Opt = context.getOptional("hex2", String.class);
String full = (hex2Opt.isPresent() && !hex2Opt.get().isEmpty()) ? hex + ":" + hex2Opt.get() : hex;
GuildResult result = guildManager.setGuildColor(player, guild, hex);
GuildResult result = guildManager.setGuildColor(player, guild, full);
if (result.isSuccess()) {
context.replySuccess(result.getMessage());
} else {
@@ -111,12 +111,14 @@ public class GamingCorePlaceholderExpansion extends PlaceholderExpansion {
case "guild_formatted_tag":
case "formatted_tag":
// Format HEX compatible TAB et EssentialsChat (ex: &#00C9FF[VAL]&r )
return "&" + guild.getColor() + "[" + guild.getTag() + "]&r ";
case "guild_chat_tag":
case "chat_tag":
return "&" + guild.getColor() + "[" + guild.getTag() + "]&r ";
String hex = guild.getColor();
if (hex.contains(":")) {
String[] parts = hex.split(":");
return "{" + parts[0] + ">}[" + guild.getTag() + "]{" + parts[parts.length - 1] + "<}&r ";
}
return "&" + hex + "[" + guild.getTag() + "]&r ";
case "guild_rank":
case "rank":
@@ -589,8 +589,8 @@ public class GuildManager {
return GuildResult.failure("Votre rang ne vous autorise pas à modifier les paramètres de la guilde.");
}
if (!hexColor.matches("^#[0-9a-fA-F]{6}$")) {
return GuildResult.failure("Format de couleur invalide. Utilisez un code hexadécimal valide à 6 caractères (ex: #00FFAA ou #FF5555).");
if (!hexColor.matches("^#[0-9a-fA-F]{6}(:#[0-9a-fA-F]{6})*$")) {
return GuildResult.failure("Format de couleur invalide. Utilisez un code hexadécimal valide (ex: #00FFAA) ou un dégradé (ex: #00C9FF:#92FE9D).");
}
guild.setColor(hexColor);
@@ -601,7 +601,8 @@ public class GuildManager {
nametagManager.updateGuild(guild);
}
return GuildResult.success("La couleur de la guilde a été changée pour <color:" + hexColor + ">" + hexColor + "</color> !");
String displayTag = guild.getFormattedTag();
return GuildResult.success("La couleur de la guilde a été mise à jour : " + displayTag + " !");
}
public GuildResult setGuildTag(Player actor, Guild guild, String newTag) {
@@ -137,22 +137,30 @@ public class Guild {
}
/**
* Obtient le tag formaté avec la couleur hexadécimale de la guilde (MiniMessage).
* Obtient le tag formaté avec la couleur ou le dégradé hexadécimal de la guilde (MiniMessage).
*
* @return Le tag stylisé (ex: "<color:#00C9FF>[IMP]</color>").
* @return Le tag stylisé (ex: "<color:#00C9FF>[IMP]</color>" ou "<gradient:#00C9FF:#92FE9D>[IMP]</gradient>").
*/
public String getFormattedTag() {
if (tag == null || tag.isEmpty()) return "";
return "<color:" + getColor() + ">[" + tag + "]</color>";
String c = getColor();
if (c.contains(":")) {
return "<gradient:" + c + ">[" + tag + "]</gradient>";
}
return "<color:" + c + ">[" + tag + "]</color>";
}
/**
* Obtient le nom formaté en gras avec la couleur hexadécimale de la guilde.
* Obtient le nom formaté en gras avec la couleur ou le dégradé hexadécimal de la guilde.
*
* @return Le nom stylisé.
*/
public String getFormattedName() {
return "<color:" + getColor() + "><bold>" + name + "</bold></color>";
String c = getColor();
if (c.contains(":")) {
return "<gradient:" + c + "><bold>" + name + "</bold></gradient>";
}
return "<color:" + c + "><bold>" + name + "</bold></color>";
}
/**