Skip to content

Commit

Permalink
Merge pull request #136 from Nookure/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Angelillo15 authored Dec 3, 2024
2 parents 19105e6 + 63a4461 commit d10da83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class FreezeMessagePartial {
""")
private String confirmPunishMessage = """
<gray>The <green>player</green> <red>{player}</red> has left the server while he was freezed
Do you want to execute the commands specified when a player leaves ? <hover:show_text:'Forgive the player'><red><click:run_command:'/freeze /remove {player}'>[x]</click></red></hover> <click:run_command:/freeze /exec {player}><green><hover:show_text:'Punish that player'>[✔]</hover></green> </click>
Do you want to execute the commands specified when a player leaves ? <hover:show_text:'Forgive the player'><red><click:run_command:'/freeze /remove {uuid}'>[x]</click></red></hover> <click:run_command:/freeze /exec {uuid}><green><hover:show_text:'Punish that player'>[✔]</hover></green> </click>
""";

@Setting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nookure.staff.paper.command;

import com.google.inject.Inject;
import com.nookure.staff.api.Logger;
import com.nookure.staff.api.Permissions;
import com.nookure.staff.api.PlayerWrapper;
import com.nookure.staff.api.StaffPlayerWrapper;
Expand All @@ -21,6 +22,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

@CommandData(
name = "freeze",
Expand All @@ -35,6 +37,8 @@ public class FreezeCommand extends StaffCommand {
private FreezeManager freezeManager;
@Inject
private ConfigurationContainer<BukkitConfig> config;
@Inject
private Logger logger;

@Override
protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull String label, @NotNull List<String> args) {
Expand All @@ -52,15 +56,24 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin
if (Objects.equals(args.get(0), "/exec") && args.size() > 1) {
if (!config.get().freeze.askToExecuteCommandOnExit()) return;

OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args.get(1));
OfflinePlayer offlinePlayer;

try {
UUID uuid = UUID.fromString(args.get(1));
offlinePlayer = Bukkit.getOfflinePlayer(uuid);
} catch (IllegalArgumentException e) {
offlinePlayer = Bukkit.getOfflinePlayer(args.get(1));
}

if (!freezeManager.isFrozen(offlinePlayer.getUniqueId())) {
logger.debug("Trying to execute commands on exit for a player that is not frozen.");
return;
}

Optional<FreezeManager.FreezeContainer> container = freezeManager.getFreezeContainer(offlinePlayer.getUniqueId());

if (container.isEmpty()) {
logger.debug("Trying to execute commands on exit for a player that is not frozen.");
return;
}

Expand All @@ -72,12 +85,19 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin

freezeExtension.executeFreezeCommands(sender, args.get(1));
freezeManager.removeFreezeContainer(offlinePlayer.getUniqueId());
sender.sendMiniMessage(messages.get().freeze.punishMessage(), "player", args.get(1));
sender.sendMiniMessage(messages.get().freeze.punishMessage(), "player", offlinePlayer.getName());
return;
}

if (Objects.equals(args.get(0), "/remove") && args.size() > 1) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args.get(1));
OfflinePlayer offlinePlayer;

try {
UUID uuid = UUID.fromString(args.get(1));
offlinePlayer = Bukkit.getOfflinePlayer(uuid);
} catch (IllegalArgumentException e) {
offlinePlayer = Bukkit.getOfflinePlayer(args.get(1));
}

if (!freezeManager.isFrozen(offlinePlayer.getUniqueId())) {
return;
Expand All @@ -86,6 +106,7 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin
Optional<FreezeManager.FreezeContainer> container = freezeManager.getFreezeContainer(offlinePlayer.getUniqueId());

if (container.isEmpty()) {
logger.debug("Trying to remove a freeze for a player that is not frozen.");
return;
}

Expand All @@ -96,7 +117,7 @@ protected void onStaffCommand(@NotNull StaffPlayerWrapper sender, @NotNull Strin
}

freezeManager.removeFreezeContainer(offlinePlayer.getUniqueId());
sender.sendMiniMessage(messages.get().freeze.forgiveMessage(), "player", args.get(1));
sender.sendMiniMessage(messages.get().freeze.forgiveMessage(), "player", offlinePlayer.getName());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {

staff.sendMiniMessage(messages.get().freeze.confirmPunishMessage()
.replace("{player}", event.getPlayer().getName())
.replace("{uuid}", event.getPlayer().getUniqueId().toString())
);
}
}

0 comments on commit d10da83

Please sign in to comment.