From ad0f46c5fefa41a6ce8212f365fe084cf2ea9cc3 Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Tue, 17 Sep 2024 17:54:00 +0200 Subject: [PATCH] feat(freeze): add the ability to pause the timer of a frozen player --- .../messages/FreezeMessagePartial.java | 24 +++++++++++++++++++ .../staff/paper/command/FreezeCommand.java | 16 ++++++++++++- .../extension/FreezePlayerExtension.java | 13 ++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/NookureStaff-API/src/main/java/com/nookure/staff/api/config/bukkit/partials/messages/FreezeMessagePartial.java b/NookureStaff-API/src/main/java/com/nookure/staff/api/config/bukkit/partials/messages/FreezeMessagePartial.java index 6c2f14dc5..67d45f64a 100644 --- a/NookureStaff-API/src/main/java/com/nookure/staff/api/config/bukkit/partials/messages/FreezeMessagePartial.java +++ b/NookureStaff-API/src/main/java/com/nookure/staff/api/config/bukkit/partials/messages/FreezeMessagePartial.java @@ -82,6 +82,22 @@ public class FreezeMessagePartial { @Comment("Message sent when a player is punished") private String punishMessage = "Freeze » You have punished {player}."; + @Setting + @Comment("Message sent when the timer has been paused for a player") + private String theTimerHasBeenPausedFor = "Freeze » The timer has been paused for {player}."; + + @Setting + @Comment("Message sent when the staff has paused the timer for a player") + private String theStaffHasPausedTheTimer = "Freeze » The staff has paused the timer for you"; + + @Setting + @Comment("Message sent when a player is not frozen.") + private String playerNotFrozen = "Freeze » That player is not frozen."; + + public String playerNotFrozen() { + return playerNotFrozen; + } + public String frozenMessage() { return frozenMessage; } @@ -141,4 +157,12 @@ public String forgiveMessage() { public String punishMessage() { return punishMessage; } + + public String theTimerHasBeenPausedFor() { + return theTimerHasBeenPausedFor; + } + + public String theStaffHasPausedTheTimer() { + return theStaffHasPausedTheTimer; + } } diff --git a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/FreezeCommand.java b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/FreezeCommand.java index a346e3dae..ec4092fa2 100644 --- a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/FreezeCommand.java +++ b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/FreezeCommand.java @@ -120,6 +120,11 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin PlayerWrapper target = optionalTarget.get(); + if (args.size() >= 2 && args.get(1).equalsIgnoreCase("pause")) { + freezeExtension.pauseFreeze(target, sender); + return; + } + if (freezeManager.isFrozen(target.getUniqueId())) { freezeExtension.unfreezePlayer(target); } else { @@ -129,6 +134,15 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin @Override public @NotNull List onTabComplete(@NotNull CommandSender sender, @NotNull String label, @NotNull List args) { - return getSuggestionFilter(Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(), args.getFirst()); + switch (args.size()) { + case 1 -> { + return getSuggestionFilter(Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(), args.getFirst()); + } + case 2 -> { + return List.of("pause"); + } + } + + return super.onTabComplete(sender, label, args); } } diff --git a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/extension/FreezePlayerExtension.java b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/extension/FreezePlayerExtension.java index cadb009d1..e03ed7da6 100644 --- a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/extension/FreezePlayerExtension.java +++ b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/extension/FreezePlayerExtension.java @@ -68,6 +68,19 @@ public void executeFreezeCommands(@NotNull PlayerWrapper target, @NotNull String config.get().freeze.commands().forEach(command -> execute(target, command, name)); } + public void pauseFreeze(@NotNull final PlayerWrapper target, @NotNull final PlayerWrapper staff) { + freezeManager.getFreezeContainer(target.getUniqueId()).ifPresentOrElse(container -> { + container.setTimeLeft(-1); + target.sendMiniMessage(messages.get().freeze.theStaffHasPausedTheTimer()); + + eventMessenger.publish(staff, new BroadcastMessage(messages.get().freeze.theTimerHasBeenPausedFor() + .replace("{player}", target.getName()) + .replace("{staff}", staff.getName()), + Permissions.STAFF_FREEZE) + ); + }, () -> target.sendMiniMessage(messages.get().freeze.playerNotOnline())); + } + public void execute(@NotNull PlayerWrapper player, @NotNull String command, @NotNull String name) { requireNonNull(player, "Player cannot be null"); requireNonNull(command, "Command cannot be null");