added confirmation on outlawed change
This commit is contained in:
@@ -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.config.Configuration;
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
||||||
import net.kyori.adventure.text.Component;
|
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.event.HoverEvent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
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 {
|
void switchLawStatus(Player player) throws OutlawChangeNotPermitted {
|
||||||
if(this.getLawStatus(player).equals(Status.FORCED)) {
|
if(this.getLawStatus(player).equals(Status.FORCED)) {
|
||||||
throw new OutlawChangeNotPermitted("Dein Vogelfreistatus wurde als Strafe auferlegt und kann daher nicht verändert werden.");
|
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) {
|
public Component getStatusDescription(Status status) {
|
||||||
return switch(status) {
|
return switch(status) {
|
||||||
case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN)
|
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)
|
case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED)
|
||||||
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));
|
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));
|
||||||
|
@@ -8,20 +8,23 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
||||||
|
public static final String commandName = "vogelfrei";
|
||||||
|
|
||||||
public OutlawedCommand() {
|
public OutlawedCommand() {
|
||||||
super("vogelfrei");
|
super(commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||||
|
if(args.length == 1 && args[0].equals("confirm")) {
|
||||||
try {
|
try {
|
||||||
this.getAppliance().switchLawStatus(this.getPlayer());
|
this.getAppliance().switchLawStatus(this.getPlayer());
|
||||||
sender.sendMessage(
|
sender.sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())));
|
||||||
this.getAppliance()
|
|
||||||
.getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer()))
|
|
||||||
);
|
|
||||||
} catch(OutlawChangeNotPermitted e) {
|
} catch(OutlawChangeNotPermitted e) {
|
||||||
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.getAppliance().askForConfirmation(this.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user