Merge pull request #158 from HaHaWTH/feat/minimessage
Minimessage support
This commit is contained in:
commit
ae76066db6
43
pom.xml
43
pom.xml
@ -463,6 +463,18 @@
|
|||||||
<pattern>com.alessiodp.libby</pattern>
|
<pattern>com.alessiodp.libby</pattern>
|
||||||
<shadedPattern>fr.xephi.authme.libs.com.alessiodp.libby</shadedPattern>
|
<shadedPattern>fr.xephi.authme.libs.com.alessiodp.libby</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori.adventure</pattern>
|
||||||
|
<shadedPattern>fr.xephi.authme.libs.net.kyori.adventure</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori.examination</pattern>
|
||||||
|
<shadedPattern>fr.xephi.authme.libs.net.kyori.examination</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori.option</pattern>
|
||||||
|
<shadedPattern>fr.xephi.authme.libs.net.kyori.option</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
|
|
||||||
<filters>
|
<filters>
|
||||||
@ -539,6 +551,12 @@
|
|||||||
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
|
<!-- Adventure API -->
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-oss-snapshots1</id>
|
||||||
|
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
|
||||||
<!-- Apache snapshots repo -->
|
<!-- Apache snapshots repo -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>apache-snapshots</id>
|
<id>apache-snapshots</id>
|
||||||
@ -807,14 +825,14 @@
|
|||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
<exclusion>
|
|
||||||
<artifactId>bungeecord-chat</artifactId>
|
|
||||||
<groupId>net.md-5</groupId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<groupId>com.googlecode.json-simple</groupId>
|
<groupId>com.googlecode.json-simple</groupId>
|
||||||
<artifactId>json-simple</artifactId>
|
<artifactId>json-simple</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>bungeecord-chat</artifactId>
|
||||||
|
<groupId>net.md-5</groupId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Keep in sync with spigot 1.19 -->
|
<!-- Keep in sync with spigot 1.19 -->
|
||||||
@ -882,6 +900,23 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Adventure API -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||||
|
<version>4.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- LuckPerms plugin -->
|
<!-- LuckPerms plugin -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.luckperms</groupId>
|
<groupId>net.luckperms</groupId>
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
|||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import fr.xephi.authme.util.TeleportUtils;
|
import fr.xephi.authme.util.TeleportUtils;
|
||||||
|
import fr.xephi.authme.util.message.MiniMessageUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.HumanEntity;
|
import org.bukkit.entity.HumanEntity;
|
||||||
@ -220,7 +221,7 @@ public class PlayerListener implements Listener{
|
|||||||
|
|
||||||
String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
|
String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
|
||||||
if (!customJoinMessage.isEmpty()) {
|
if (!customJoinMessage.isEmpty()) {
|
||||||
customJoinMessage = ChatColor.translateAlternateColorCodes('&', customJoinMessage);
|
customJoinMessage = ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(customJoinMessage));
|
||||||
event.setJoinMessage(customJoinMessage
|
event.setJoinMessage(customJoinMessage
|
||||||
.replace("{PLAYERNAME}", player.getName())
|
.replace("{PLAYERNAME}", player.getName())
|
||||||
.replace("{DISPLAYNAME}", player.getDisplayName())
|
.replace("{DISPLAYNAME}", player.getDisplayName())
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
|
|||||||
import fr.xephi.authme.mail.EmailService;
|
import fr.xephi.authme.mail.EmailService;
|
||||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||||
import fr.xephi.authme.util.expiring.Duration;
|
import fr.xephi.authme.util.expiring.Duration;
|
||||||
|
import fr.xephi.authme.util.message.MiniMessageUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -126,7 +127,7 @@ public class Messages {
|
|||||||
displayName = ((Player) sender).getDisplayName();
|
displayName = ((Player) sender).getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message)
|
return ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(message))
|
||||||
.replace(NEWLINE_TAG, "\n")
|
.replace(NEWLINE_TAG, "\n")
|
||||||
.replace(USERNAME_TAG, sender.getName())
|
.replace(USERNAME_TAG, sender.getName())
|
||||||
.replace(DISPLAYNAME_TAG, displayName);
|
.replace(DISPLAYNAME_TAG, displayName);
|
||||||
@ -142,7 +143,7 @@ public class Messages {
|
|||||||
private String retrieveMessage(MessageKey key, String name) {
|
private String retrieveMessage(MessageKey key, String name) {
|
||||||
String message = messagesFileHandler.getMessage(key.getKey());
|
String message = messagesFileHandler.getMessage(key.getKey());
|
||||||
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', message)
|
return ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(message))
|
||||||
.replace(NEWLINE_TAG, "\n")
|
.replace(NEWLINE_TAG, "\n")
|
||||||
.replace(USERNAME_TAG, name)
|
.replace(USERNAME_TAG, name)
|
||||||
.replace(DISPLAYNAME_TAG, name);
|
.replace(DISPLAYNAME_TAG, name);
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
package fr.xephi.authme.util.message;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
|
||||||
|
public class MiniMessageUtils {
|
||||||
|
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse a MiniMessage string into a legacy string.
|
||||||
|
*
|
||||||
|
* @param message The message to parse.
|
||||||
|
* @return The parsed message.
|
||||||
|
*/
|
||||||
|
public static String parseMiniMessageToLegacy(String message) {
|
||||||
|
Component component = miniMessage.deserialize(message);
|
||||||
|
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private MiniMessageUtils() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user