Bukkit Audience
This commit is contained in:
parent
e02659d850
commit
58f8176dae
@ -31,6 +31,7 @@ import fr.xephi.authme.listener.ServerListener;
|
||||
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;
|
||||
@ -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;
|
||||
@ -139,6 +141,13 @@ public class AuthMe extends JavaPlugin {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the AdventureService
|
||||
*/
|
||||
public static AdventureService getAdventureService() {
|
||||
return adventureService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The library manager
|
||||
*/
|
||||
@ -153,6 +162,8 @@ public class AuthMe extends JavaPlugin {
|
||||
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));
|
||||
@ -403,6 +414,11 @@ public class AuthMe extends JavaPlugin {
|
||||
// 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!");
|
||||
|
||||
@ -21,7 +21,6 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.util.TeleportUtils;
|
||||
import fr.xephi.authme.util.message.I18NUtils;
|
||||
import fr.xephi.authme.util.message.MiniMessageUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@ -219,7 +218,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
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())
|
||||
|
||||
@ -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;
|
||||
@ -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.
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +81,7 @@ public class Messages {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +134,7 @@ public class Messages {
|
||||
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);
|
||||
@ -147,7 +150,7 @@ public class Messages {
|
||||
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);
|
||||
|
||||
35
src/main/java/fr/xephi/authme/service/AdventureService.java
Normal file
35
src/main/java/fr/xephi/authme/service/AdventureService.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.util.message;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
@ -17,6 +18,17 @@ public class MiniMessageUtils {
|
||||
Component component = miniMessage.deserialize(message);
|
||||
return LegacyComponentSerializer.legacyAmpersand().serialize(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a MiniMessage string into a component.
|
||||
*
|
||||
* @param message The message to parse.
|
||||
* @return The parsed message.
|
||||
*/
|
||||
public static Component parseMiniMessage(String message) {
|
||||
TextComponent component = LegacyComponentSerializer.legacySection().deserialize(message);
|
||||
return miniMessage.deserialize(miniMessage.serialize(component));
|
||||
}
|
||||
private MiniMessageUtils() {
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user