Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full MiniMessage support #184

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,6 @@
<pattern>com.alessiodp.libby</pattern>
<shadedPattern>fr.xephi.authme.libs.com.alessiodp.libby</shadedPattern>
</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>

<filters>
Expand Down Expand Up @@ -903,11 +891,6 @@
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.17.0</version>
</dependency>

<!-- LuckPerms plugin -->
<dependency>
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/fr/xephi/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.security.crypts.Sha256;
import fr.xephi.authme.service.AdventureService;
import fr.xephi.authme.service.BackupService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.service.MigrationService;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class AuthMe extends JavaPlugin {
private EmailService emailService;
private CommandHandler commandHandler;
private static TaskScheduler scheduler;
private static AdventureService adventureService;
@Inject
public static Settings settings;
private DataSource database;
Expand Down Expand Up @@ -139,6 +141,13 @@ public static TaskScheduler getScheduler() {
return scheduler;
}

/**
* Get the AdventureService
*/
public static AdventureService getAdventureService() {
return adventureService;
}

/**
* The library manager
*/
Expand All @@ -153,6 +162,8 @@ public void onEnable() {
loadPluginInfo(getDescription().getVersion());
scheduler = UniversalScheduler.getScheduler(this);
libraryManager = new BukkitLibraryManager(this);
adventureService = new AdventureService(this);
adventureService.init();

// Set the Logger instance and log file path
ConsoleLogger.initialize(getLogger(), new File(getDataFolder(), LOG_FILENAME));
Expand Down Expand Up @@ -403,6 +414,11 @@ public void onDisable() {
// Wait for tasks and close data source
new TaskCloser(database).run();

// Close AdventureService
if (adventureService != null) {
adventureService.close();
}

// Disabled correctly
Consumer<String> infoLogMethod = logger == null ? getLogger()::info : logger::info;
infoLogMethod.accept("AuthMe " + this.getDescription().getVersion() + " is unloaded successfully!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.service.ValidationService.ValidationResult;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -79,7 +80,7 @@ public void executeCommand(final CommandSender sender, List<String> arguments) {
if (player != null) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() ->
// AuthMeReReloaded - Folia compatibility
bukkitService.runTaskIfFolia(player, () -> player.kickPlayer(commonService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER))));
bukkitService.runTaskIfFolia(player, () -> MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(commonService.retrieveSingleMessage(player, MessageKey.KICK_FOR_ADMIN_REGISTER)))));
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/xephi/authme/data/TempbanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.util.expiring.TimedCounter;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.entity.Player;

import javax.inject.Inject;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void tempbanPlayer(final Player player) {
bukkitService.runTask(player,() -> { // AuthMeReReloaded - Folia compatibility
if (customCommand.isEmpty()) {
bukkitService.banIp(ip, reason, expires, "AuthMe");
player.kickPlayer(reason);
MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(reason));
} else {
String command = customCommand
.replace("%player%", name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -26,7 +27,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
HashSet<String> PlayerSet = new HashSet<String>();
for (Player ep : PlayerList) {
if (PlayerSet.contains(ep.getName().toLowerCase())) {
ep.kickPlayer(service.retrieveSingleMessage(ep.getPlayer(), MessageKey.DOUBLE_LOGIN_FIX));
MiniMessageUtils.kickPlayer(ep, MiniMessageUtils.parseMiniMessage(service.retrieveSingleMessage(ep.getPlayer(), MessageKey.DOUBLE_LOGIN_FIX)));
break;
}
PlayerSet.add(ep.getName().toLowerCase());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/xephi/authme/listener/OnJoinVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerLoginEvent;
Expand Down Expand Up @@ -140,7 +141,7 @@ public boolean refusePlayerForFullServer(PlayerLoginEvent event) {
Player nonVipPlayer = generateKickPlayer(onlinePlayers);
if (nonVipPlayer != null) {
// AuthMeReReloaded - Folia compatibility
bukkitService.runTaskIfFolia(nonVipPlayer, () -> nonVipPlayer.kickPlayer(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP)));
bukkitService.runTaskIfFolia(nonVipPlayer, () -> MiniMessageUtils.kickPlayer(nonVipPlayer, MiniMessageUtils.parseMiniMessage(messages.retrieveSingle(player, MessageKey.KICK_FOR_VIP))));
event.allow();
return false;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fr/xephi/authme/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void onJoinMessage(PlayerJoinEvent event) {

String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
if (!customJoinMessage.isEmpty()) {
customJoinMessage = ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(customJoinMessage));
customJoinMessage = ChatColor.translateAlternateColorCodes('&', customJoinMessage);
event.setJoinMessage(customJoinMessage
.replace("{PLAYERNAME}", player.getName())
.replace("{DISPLAYNAME}", player.getDisplayName())
Expand Down Expand Up @@ -324,7 +324,7 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
final Player player = event.getPlayer();
if (!quickCommandsProtectionManager.isAllowed(player.getName())) {
event.setCancelled(true);
bukkitService.runTaskIfFolia(player, () -> player.kickPlayer(messages.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK)));
bukkitService.runTaskIfFolia(player, () -> MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(messages.retrieveSingle(player, MessageKey.QUICK_COMMAND_PROTECTION_KICK))));
// AuthMeReReloaded - Folia compatibility
return;
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/fr/xephi/authme/message/Messages.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fr.xephi.authme.message;

import com.google.common.collect.ImmutableMap;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.output.ConsoleLoggerFactory;
import fr.xephi.authme.service.AdventureService;
import fr.xephi.authme.util.expiring.Duration;
import fr.xephi.authme.util.message.I18NUtils;
import fr.xephi.authme.util.message.MiniMessageUtils;
Expand Down Expand Up @@ -44,6 +46,7 @@ public class Messages {
private final ConsoleLogger logger = ConsoleLoggerFactory.get(EmailService.class);

private MessagesFileHandler messagesFileHandler;
private static final AdventureService adventureService = AuthMe.getAdventureService();

/*
* Constructor.
Expand All @@ -62,7 +65,7 @@ public class Messages {
public void send(CommandSender sender, MessageKey key) {
String[] lines = retrieve(key, sender);
for (String line : lines) {
sender.sendMessage(line);
adventureService.send(sender, MiniMessageUtils.parseMiniMessage(line));
}
}

Expand All @@ -78,7 +81,7 @@ public void send(CommandSender sender, MessageKey key) {
public void send(CommandSender sender, MessageKey key, String... replacements) {
String message = retrieveSingle(sender, key, replacements);
for (String line : message.split("\n")) {
sender.sendMessage(line);
adventureService.send(sender, MiniMessageUtils.parseMiniMessage(line));
}
}

Expand Down Expand Up @@ -131,7 +134,7 @@ private String retrieveMessage(MessageKey key, CommandSender sender) {
displayName = ((Player) sender).getDisplayName();
}

return ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(message))
return ChatColor.translateAlternateColorCodes('&', message)
.replace(NEWLINE_TAG, "\n")
.replace(USERNAME_TAG, sender.getName())
.replace(DISPLAYNAME_TAG, displayName);
Expand All @@ -147,7 +150,7 @@ private String retrieveMessage(MessageKey key, CommandSender sender) {
private String retrieveMessage(MessageKey key, String name) {
String message = messagesFileHandler.getMessage(key.getKey());

return ChatColor.translateAlternateColorCodes('&', MiniMessageUtils.parseMiniMessageToLegacy(message))
return ChatColor.translateAlternateColorCodes('&', message)
.replace(NEWLINE_TAG, "\n")
.replace(USERNAME_TAG, name)
.replace(DISPLAYNAME_TAG, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.InternetProtocolUtils;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -177,7 +178,7 @@ public void processJoin(Player player) {

private void handlePlayerWithUnmetNameRestriction(Player player, String ip) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.NOT_OWNER_ERROR));
MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(service.retrieveSingleMessage(player, MessageKey.NOT_OWNER_ERROR)));
if (service.getProperty(RestrictionSettings.BAN_UNKNOWN_IP)) {
server.banIP(ip);
}
Expand Down Expand Up @@ -228,7 +229,7 @@ private boolean validatePlayerCountForIp(Player player, String ip) {
&& countOnlinePlayersByIp(ip) > service.getProperty(RestrictionSettings.MAX_JOIN_PER_IP)) {

bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(
() -> player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.SAME_IP_ONLINE)));
() -> MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(service.retrieveSingleMessage(player, MessageKey.SAME_IP_ONLINE))));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import fr.xephi.authme.util.InternetProtocolUtils;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -249,7 +250,7 @@ private void handleWrongPassword(Player player, PlayerAuth auth, String ip) {
tempbanManager.tempbanPlayer(player);
} else if (service.getProperty(RestrictionSettings.KICK_ON_WRONG_PASSWORD)) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(
() -> player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.WRONG_PASSWORD)));
() -> MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(service.retrieveSingleMessage(player, MessageKey.WRONG_PASSWORD))));
} else {
service.send(player, MessageKey.WRONG_PASSWORD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.util.PlayerUtils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.entity.Player;

import javax.inject.Inject;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void processPasswordRegister(Player player) {

// Kick Player after Registration is enabled, kick the player
if (service.getProperty(RegistrationSettings.FORCE_KICK_AFTER_REGISTER)) {
player.kickPlayer(service.retrieveSingleMessage(player, MessageKey.REGISTER_SUCCESS));
MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(service.retrieveSingleMessage(player, MessageKey.REGISTER_SUCCESS)));
return;
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/fr/xephi/authme/service/AdventureService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fr.xephi.authme.service;

import fr.xephi.authme.AuthMe;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class AdventureService {
private final AuthMe plugin;
public BukkitAudiences adventure;
public AdventureService(AuthMe plugin) {
this.plugin = plugin;
}

public void init() {
adventure = BukkitAudiences.create(plugin);
}

public void close() {
if (adventure != null) {
adventure.close();
adventure = null;
}
}

public void send(CommandSender sender, Component component) {
adventure.sender(sender).sendMessage(component);
}

public void send(Player player, Component component) {
adventure.player(player).sendMessage(component);
}

}
3 changes: 2 additions & 1 deletion src/main/java/fr/xephi/authme/task/TimeoutTask.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.xephi.authme.task;

import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.entity.Player;

/**
Expand Down Expand Up @@ -28,7 +29,7 @@ public TimeoutTask(Player player, String message, PlayerCache playerCache) {
@Override
public void run() {
if (!playerCache.isAuthenticated(player.getName())) {
player.kickPlayer(message);
MiniMessageUtils.kickPlayer(player, MiniMessageUtils.parseMiniMessage(message));
}
}
}
Loading