|
| 1 | +package pro.cloudnode.smp.cloudnodemsg; |
| 2 | + |
| 3 | +import net.kyori.adventure.text.Component; |
| 4 | +import net.kyori.adventure.text.minimessage.MiniMessage; |
| 5 | +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; |
| 6 | +import org.bukkit.configuration.file.FileConfiguration; |
| 7 | +import org.jetbrains.annotations.NotNull; |
| 8 | + |
| 9 | +import java.util.Objects; |
| 10 | + |
| 11 | +public final class PluginConfig { |
| 12 | + public @NotNull FileConfiguration config; |
| 13 | + |
| 14 | + public PluginConfig(final @NotNull FileConfiguration config) { |
| 15 | + this.config = config; |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * Incoming message format (recipient's point of view) |
| 20 | + * <p>Placeholders:</p> |
| 21 | + * <ul> |
| 22 | + * <li>{@code <sender>} - the username of the message sender</li> |
| 23 | + * <li>{@code <recipient>} - the username of the message recipient</li> |
| 24 | + * <li>{@code <message>} - the message text</li> |
| 25 | + * </ul> |
| 26 | + * |
| 27 | + * @param sender The username of the message sender |
| 28 | + * @param recipient The username of the message recipient |
| 29 | + * @param message The message text |
| 30 | + */ |
| 31 | + public @NotNull Component incoming(final @NotNull String sender, final @NotNull String recipient, final @NotNull String message) { |
| 32 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("incoming")) |
| 33 | + .replace("<sender>", sender) |
| 34 | + .replace("<recipient>", recipient), |
| 35 | + Placeholder.unparsed("message", message) |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Outgoing message format (sender's point of view) |
| 41 | + * <p>Placeholders:</p> |
| 42 | + * <ul> |
| 43 | + * <li>{@code <sender>} - the username of the message sender</li> |
| 44 | + * <li>{@code <recipient>} - the username of the message recipient</li> |
| 45 | + * <li>{@code <message>} - the message text</li> |
| 46 | + * </ul> |
| 47 | + * |
| 48 | + * @param sender The username of the message sender |
| 49 | + * @param recipient The username of the message recipient |
| 50 | + * @param message The message text |
| 51 | + */ |
| 52 | + public @NotNull Component outgoing(final @NotNull String sender, final @NotNull String recipient, final @NotNull String message) { |
| 53 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("outgoing")) |
| 54 | + .replace("<sender>", sender) |
| 55 | + .replace("<recipient>", recipient), |
| 56 | + Placeholder.unparsed("message", message) |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Command usage format |
| 62 | + * <p>Placeholders:</p> |
| 63 | + * <ul> |
| 64 | + * <li>{@code <command>} - the command name</li> |
| 65 | + * <li>{@code <usage>} - the command usage parameters</li> |
| 66 | + * </ul> |
| 67 | + * |
| 68 | + * @param label Command label |
| 69 | + * @param usage Command usage parameters |
| 70 | + */ |
| 71 | + public @NotNull Component usage(final @NotNull String label, final @NotNull String usage) { |
| 72 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("usage")), |
| 73 | + Placeholder.unparsed("command", label), |
| 74 | + Placeholder.unparsed("usage", usage) |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Name for console/server that should appear as {@code <sender>} or {@code <recipient>} in messages |
| 80 | + */ |
| 81 | + public @NotNull String consoleName() { |
| 82 | + return Objects.requireNonNull(config.getString("console-name")); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * No permission |
| 87 | + */ |
| 88 | + public @NotNull Component noPermission() { |
| 89 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.no-permission"))); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Player has no username (somehow) |
| 94 | + */ |
| 95 | + public @NotNull Component invalidPlayer() { |
| 96 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.invalid-player"))); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Player not found |
| 101 | + * <p>Placeholders:</p> |
| 102 | + * <ul><li>{@code <player>} - the player's username</li></ul> |
| 103 | + * |
| 104 | + * @param player The player's username |
| 105 | + */ |
| 106 | + public @NotNull Component playerNotFound(final @NotNull String player) { |
| 107 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.player-not-found")), |
| 108 | + Placeholder.unparsed("player", player) |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + public @NotNull Component messageYourself() { |
| 113 | + return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("errors.message-yourself"))); |
| 114 | + } |
| 115 | +} |
| 116 | + |
0 commit comments