From 3bec5f4cbddca7a93ca8ca8fafccd154cd3de1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Sat, 20 Sep 2025 20:30:47 +0200 Subject: [PATCH] added confirmation on outlawed change --- .../gameplay/outlawed/Outlawed.java | 26 ++++++++++++++++++- .../gameplay/outlawed/OutlawedCommand.java | 21 ++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/Outlawed.java b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/Outlawed.java index 682132e..db7c5d0 100644 --- a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/Outlawed.java +++ b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/Outlawed.java @@ -8,6 +8,7 @@ import eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.whitelist.Whitel import eu.mhsl.craftattack.spawn.core.config.Configuration; import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; @@ -48,6 +49,29 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed { ); } + void askForConfirmation(Player player) { + Component confirmationMessage = switch(this.getLawStatus(player)) { + case DISABLED -> Component.text("Wenn du Vogelfrei aktivierst, darfst du von allen Spielern grundlos angegriffen werden."); + case VOLUNTARILY -> Component.text("Wenn du Vogelfrei deaktivierst, darfst du nicht mehr grundlos von Spielern angegriffen werden."); + case FORCED -> Component.text("Du darfst zurzeit deinen Vogelfreistatus nicht ändern, da dieser als Strafe auferlegt wurde!"); + }; + String command = String.format("/%s confirm", OutlawedCommand.commandName); + Component changeText = Component.text( + String.format( + "Zum ändern deines Vogelfrei status klicke auf diese Nachricht oder tippe '%s'", + command + ), + NamedTextColor.GOLD + ).clickEvent(ClickEvent.suggestCommand(command)); + + player.sendMessage( + Component.text() + .append(confirmationMessage.color(NamedTextColor.RED)) + .appendNewline() + .append(changeText) + ); + } + void switchLawStatus(Player player) throws OutlawChangeNotPermitted { if(this.getLawStatus(player).equals(Status.FORCED)) { throw new OutlawChangeNotPermitted("Dein Vogelfreistatus wurde als Strafe auferlegt und kann daher nicht verändert werden."); @@ -103,7 +127,7 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed { public Component getStatusDescription(Status status) { return switch(status) { case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN) - .append(Component.text("Es gelten die Standard Regeln!", NamedTextColor.GOLD)); + .append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD)); case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED) .append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD)); diff --git a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/OutlawedCommand.java b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/OutlawedCommand.java index 6ee8c0c..7af40cd 100644 --- a/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/OutlawedCommand.java +++ b/craftattack/src/main/java/eu/mhsl/craftattack/spawn/craftattack/appliances/gameplay/outlawed/OutlawedCommand.java @@ -8,20 +8,23 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; class OutlawedCommand extends ApplianceCommand.PlayerChecked { + public static final String commandName = "vogelfrei"; + public OutlawedCommand() { - super("vogelfrei"); + super(commandName); } @Override protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { - try { - this.getAppliance().switchLawStatus(this.getPlayer()); - sender.sendMessage( - this.getAppliance() - .getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())) - ); - } catch(OutlawChangeNotPermitted e) { - sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED)); + if(args.length == 1 && args[0].equals("confirm")) { + try { + this.getAppliance().switchLawStatus(this.getPlayer()); + sender.sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer()))); + } catch(OutlawChangeNotPermitted e) { + sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED)); + } + } else { + this.getAppliance().askForConfirmation(this.getPlayer()); } } }