|
| 1 | +package parallelmc.parallelutils.util; |
| 2 | + |
| 3 | +import net.kyori.adventure.text.Component; |
| 4 | +import net.kyori.adventure.text.TextComponent; |
| 5 | +import net.kyori.adventure.text.format.NamedTextColor; |
| 6 | +import org.bukkit.Bukkit; |
| 7 | +import org.bukkit.entity.Player; |
| 8 | +import parallelmc.parallelutils.Constants; |
| 9 | + |
| 10 | +/** |
| 11 | + * A set of utilities to make sending messages easier |
| 12 | + */ |
| 13 | +public class MessageTools { |
| 14 | + |
| 15 | + /** |
| 16 | + * Sends a message to a player with the Parallel prefix prepended to it |
| 17 | + * (This version of the method sends an "INFO" style message) |
| 18 | + * @param player The player to send the message to |
| 19 | + * @param message The message without the prefix |
| 20 | + */ |
| 21 | + public static void sendMessage(Player player, String message) { |
| 22 | + TextComponent finalMessage = (TextComponent) Constants.PLUGIN_PREFIX |
| 23 | + .append(Component.text(message, NamedTextColor.AQUA)); |
| 24 | + player.sendMessage(finalMessage); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Sends a message to a player with the Parallel prefix prepended to it |
| 29 | + * @param player The player to send the message to |
| 30 | + * @param message The message without the prefix |
| 31 | + * @param messageType The type of message; this determines the message color |
| 32 | + */ |
| 33 | + public static void sendMessage(Player player, String message, MessageType messageType) { |
| 34 | + TextComponent finalMessage = switch (messageType) { |
| 35 | + case INFO -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.AQUA)); |
| 36 | + case SUCCESS -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.GREEN)); |
| 37 | + case ERROR -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.RED)); |
| 38 | + }; |
| 39 | + player.sendMessage(finalMessage); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Sends a message to console with the Parallel prefix prepended to it |
| 44 | + * (This version of the method sends an "INFO" style message) |
| 45 | + * @param message The message without the prefix |
| 46 | + */ |
| 47 | + public static void sendConsoleMessage(String message) { |
| 48 | + TextComponent finalMessage = (TextComponent) Constants.PLUGIN_PREFIX |
| 49 | + .append(Component.text(message, NamedTextColor.AQUA)); |
| 50 | + Bukkit.getConsoleSender().sendMessage(finalMessage); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Sends a message to console with the Parallel prefix prepended to it |
| 55 | + * @param message The message without the prefix |
| 56 | + * @param messageType The type of message; this determines the message color |
| 57 | + */ |
| 58 | + public static void sendConsoleMessage(String message, MessageType messageType) { |
| 59 | + TextComponent finalMessage = switch (messageType) { |
| 60 | + case INFO -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.AQUA)); |
| 61 | + case SUCCESS -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.GREEN)); |
| 62 | + case ERROR -> (TextComponent) Constants.PLUGIN_PREFIX.append(Component.text(message, NamedTextColor.RED)); |
| 63 | + }; |
| 64 | + Bukkit.getConsoleSender().sendMessage(finalMessage); |
| 65 | + } |
| 66 | +} |
0 commit comments