From 17773fe1b716daf3541bdf165867de5e748c3243 Mon Sep 17 00:00:00 2001 From: Bram Date: Tue, 5 Nov 2024 14:09:00 +0100 Subject: [PATCH] Added: Customizing alert toggle messages --- build.gradle.kts | 2 +- .../totemguard/config/Settings.java | 8 ++++++- .../totemguard/manager/AlertManager.java | 8 +++++-- .../totemguard/util/MessageService.java | 23 ++++++++++++++++++- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index af120ab..49e1156 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,7 +40,7 @@ dependencies { } group = "com.deathmotion.totemguard" -version = "1.1.0-SNAPSHOT" +version = "1.1.0" description = "TotemGuard" tasks { diff --git a/src/main/java/com/deathmotion/totemguard/config/Settings.java b/src/main/java/com/deathmotion/totemguard/config/Settings.java index 40f09d4..5a77e7e 100644 --- a/src/main/java/com/deathmotion/totemguard/config/Settings.java +++ b/src/main/java/com/deathmotion/totemguard/config/Settings.java @@ -40,7 +40,7 @@ public final class Settings { @Comment({ "", - "Supported Placeholders in the settings:", + "Supported Placeholders for alerts and punishments:", "%prefix% - Prefix of the Plugin", "%uuid% - UUID of the Player", "%player% - Name of the Player", @@ -55,6 +55,12 @@ public final class Settings { "Alert Format: The format of the alert message."}) private String alertFormat = "%prefix%&e%player%&7 failed &6%check%&f &7VL[&6%violations%/%max_violations%&7]"; + @Comment("\nAlerts Enabled: Message when enabling alerts.") + private String alertsEnabled = "%prefix%&aAlerts enabled"; + + @Comment("\nAlerts Disabled: Message when disabling alerts.") + private String alertsDisabled = "%prefix%&cAlerts disabled"; + @Comment("\nColor Scheme Settings:") private ColorScheme colorScheme = new ColorScheme(); diff --git a/src/main/java/com/deathmotion/totemguard/manager/AlertManager.java b/src/main/java/com/deathmotion/totemguard/manager/AlertManager.java index f7a00ed..44cb50f 100644 --- a/src/main/java/com/deathmotion/totemguard/manager/AlertManager.java +++ b/src/main/java/com/deathmotion/totemguard/manager/AlertManager.java @@ -23,6 +23,7 @@ import com.deathmotion.totemguard.database.DatabaseService; import com.deathmotion.totemguard.models.CheckDetails; import com.deathmotion.totemguard.models.TotemPlayer; +import com.deathmotion.totemguard.util.MessageService; import lombok.Getter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -39,10 +40,13 @@ public class AlertManager { private final TotemGuard plugin; private final DatabaseService databaseService; + private final MessageService messageService; public AlertManager(TotemGuard plugin) { this.plugin = plugin; this.databaseService = plugin.getDatabaseService(); + this.messageService = plugin.getMessageService(); + this.enabledAlerts = new ConcurrentHashMap<>(); } @@ -59,10 +63,10 @@ public void toggleAlerts(Player player) { UUID playerId = player.getUniqueId(); if (enabledAlerts.containsKey(playerId)) { enabledAlerts.remove(playerId); - sendAlertStatusMessage(player, "Alerts disabled", NamedTextColor.RED); + player.sendMessage(messageService.toggleAlerts(false, player)); } else { enabledAlerts.put(playerId, player); - sendAlertStatusMessage(player, "Alerts enabled", NamedTextColor.GREEN); + player.sendMessage(messageService.toggleAlerts(true, player)); } } diff --git a/src/main/java/com/deathmotion/totemguard/util/MessageService.java b/src/main/java/com/deathmotion/totemguard/util/MessageService.java index 93ee5f0..fc22df1 100644 --- a/src/main/java/com/deathmotion/totemguard/util/MessageService.java +++ b/src/main/java/com/deathmotion/totemguard/util/MessageService.java @@ -38,8 +38,10 @@ import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.entity.Player; import java.util.List; +import java.util.Map; public class MessageService { private final TotemGuard plugin; @@ -74,7 +76,6 @@ public Pair getColorScheme() { return new Pair<>(primaryColor, secondaryColor); } - public Component version() { return getPrefix() .append(Component.text("Running ", NamedTextColor.GRAY).decorate(TextDecoration.BOLD)) @@ -90,6 +91,26 @@ public Component version() { .clickEvent(ClickEvent.openUrl(Constants.GITHUB_URL)); } + public Component toggleAlerts(boolean enabled, Player player) { + String alertToggleFormat; + + if (enabled) { + alertToggleFormat = configManager.getSettings().getAlertsEnabled(); + } else { + alertToggleFormat = configManager.getSettings().getAlertsDisabled(); + } + + String parsedMessage = PlaceholderUtil.replacePlaceholders(alertToggleFormat, Map.of( + "%prefix%", configManager.getSettings().getPrefix(), + "%uuid%", player.getUniqueId().toString(), + "%player%", player.getName() + )); + + return Component.text() + .append(LegacyComponentSerializer.legacyAmpersand().deserialize(parsedMessage)) + .build(); + } + public Component playerNotFound() { return getPrefix().append(Component.text("Player not found!", NamedTextColor.RED)); }