Skip to content

Commit

Permalink
feat(freeze): add the ability to pause the timer of a frozen player
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Sep 17, 2024
1 parent d304dc5 commit ad0f46c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ public class FreezeMessagePartial {
@Comment("Message sent when a player is punished")
private String punishMessage = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>You have punished {player}.</gray>";

@Setting
@Comment("Message sent when the timer has been paused for a player")
private String theTimerHasBeenPausedFor = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>The timer has been paused for {player}.</gray>";

@Setting
@Comment("Message sent when the staff has paused the timer for a player")
private String theStaffHasPausedTheTimer = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <gray>The staff has paused the timer for you</gray>";

@Setting
@Comment("Message sent when a player is not frozen.")
private String playerNotFrozen = "<bold><dark_aqua>Freeze <dark_gray>»</bold> <red>That player is not frozen.</red>";

public String playerNotFrozen() {
return playerNotFrozen;
}

public String frozenMessage() {
return frozenMessage;
}
Expand Down Expand Up @@ -141,4 +157,12 @@ public String forgiveMessage() {
public String punishMessage() {
return punishMessage;
}

public String theTimerHasBeenPausedFor() {
return theTimerHasBeenPausedFor;
}

public String theStaffHasPausedTheTimer() {
return theStaffHasPausedTheTimer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -129,6 +134,15 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin

@Override
public @NotNull List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String label, @NotNull List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit ad0f46c

Please sign in to comment.