Skip to content

Commit

Permalink
Added: Customizing alert toggle messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed Nov 5, 2024
1 parent 5feaa77 commit 17773fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
}

group = "com.deathmotion.totemguard"
version = "1.1.0-SNAPSHOT"
version = "1.1.0"
description = "TotemGuard"

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<>();
}

Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +76,6 @@ public Pair<TextColor, TextColor> getColorScheme() {
return new Pair<>(primaryColor, secondaryColor);
}


public Component version() {
return getPrefix()
.append(Component.text("Running ", NamedTextColor.GRAY).decorate(TextDecoration.BOLD))
Expand All @@ -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));
}
Expand Down

0 comments on commit 17773fe

Please sign in to comment.