From e7075140e35e9102c9a218190a1997d6a53e27d3 Mon Sep 17 00:00:00 2001 From: lars Date: Tue, 5 Nov 2024 20:48:42 +0100 Subject: [PATCH] added anticheat info command --- .../spawn/appliances/acInform/AcInform.java | 132 ++++++++++++++++++ .../appliances/acInform/AcInformCommand.java | 18 +++ src/main/resources/plugin.yml | 1 + 3 files changed, 151 insertions(+) create mode 100644 src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInform.java create mode 100644 src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInformCommand.java diff --git a/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInform.java b/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInform.java new file mode 100644 index 0000000..bd976c3 --- /dev/null +++ b/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInform.java @@ -0,0 +1,132 @@ +package eu.mhsl.craftattack.spawn.appliances.acInform; + +import eu.mhsl.craftattack.spawn.appliance.Appliance; +import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentBuilder; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.*; + +public class AcInform extends Appliance { + public void processCommand(@NotNull String[] args) { + String anticheatName = null; + String playerName = null; + String checkName = null; + Integer violationCount = null; + + for(int i = 0; i < args.length; i++) { + if(!args[i].startsWith("--")) continue; + if(i == args.length-1) continue; + String nextArgument = args[i+1]; + if(nextArgument.startsWith("--")) continue; + + switch(args[i]) { + case "--anticheatName" -> anticheatName = nextArgument; + case "--playerName" -> playerName = nextArgument; + case "--check" -> checkName = nextArgument; + case "--violationCount" -> violationCount = Integer.valueOf(nextArgument); + } + } + + this.notifyAdmins(anticheatName, playerName, checkName, violationCount); + } + + public void notifyAdmins(@Nullable String anticheatName, @Nullable String playerName, @Nullable String checkName, @Nullable Integer violationCount) { + ComponentBuilder component = Component.text(); + Component prefix = Component.text("# ", NamedTextColor.DARK_RED); + NamedTextColor textColor = NamedTextColor.GRAY; + + if(playerName == null || playerName.isBlank()) return; + + if(anticheatName != null && !anticheatName.isBlank()) { + component.append( + Component.newline() + .append(prefix) + .append(Component.text("[", textColor)) + .append(Component.text("Anticheat", NamedTextColor.RED)) + .append(Component.text("] ", textColor)) + .append(Component.text(anticheatName, NamedTextColor.WHITE)) + .append(Component.text(":", textColor)) + ); + } + + component.append( + Component.newline() + .append(prefix) + .append(Component.text("Player ", textColor)) + .append(Component.text(playerName, NamedTextColor.WHITE)) + .append(Component.text(" ")) + ); + + if(checkName == null || checkName.isBlank()) { + component.append(Component.text("got detected by Anticheat", textColor)); + } else if(violationCount != null){ + component.append( + Component.text("failed ", textColor) + .append(Component.text(String.format("%sx ", violationCount), NamedTextColor.WHITE)) + .append(Component.text("'", textColor)) + .append(Component.text(checkName, NamedTextColor.WHITE)) + .append(Component.text("'", textColor)) + ); + } else { + component.append( + Component.text("failed ", textColor) + .append(Component.text("'", textColor)) + .append(Component.text(checkName, NamedTextColor.WHITE)) + .append(Component.text("'", textColor)) + ); + } + + component.append( + Component.newline() + .append(prefix) + + .append(Component.text("[", NamedTextColor.GRAY)) + .append(Component.text("Report", NamedTextColor.GOLD)) + .append(Component.text("] ", NamedTextColor.GRAY)) + .clickEvent(ClickEvent.suggestCommand(String.format("/report %s anticheat %s flagged %s", playerName, anticheatName, checkName))) + ); + + component.append( + Component.text(" [", NamedTextColor.GRAY) + .append(Component.text("Kick", NamedTextColor.GOLD)) + .append(Component.text("] ", NamedTextColor.GRAY)) + .clickEvent(ClickEvent.suggestCommand(String.format("/kick %s", playerName))) + ); + + component.append( + Component.text(" [", NamedTextColor.GRAY) + .append(Component.text("Panic Ban", NamedTextColor.GOLD)) + .append(Component.text("]", NamedTextColor.GRAY)) + .clickEvent(ClickEvent.suggestCommand(String.format("/panicban %s", playerName))) + ); + + component.append( + Component.text(" [", NamedTextColor.GRAY) + .append(Component.text("Teleport", NamedTextColor.GOLD)) + .append(Component.text("]", NamedTextColor.GRAY)) + .clickEvent(ClickEvent.suggestCommand(String.format("/tp %s", playerName))) + ); + + component.appendNewline(); + TextComponent finalMessage = component.build(); + + Bukkit.getOnlinePlayers().stream() + .filter(player -> player.hasPermission("admin")) + .forEach(player -> player.sendMessage(finalMessage)); + + } + + @Override + protected @NotNull List> commands() { + return List.of( + new AcInformCommand() + ); + } +} diff --git a/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInformCommand.java b/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInformCommand.java new file mode 100644 index 0000000..15707e5 --- /dev/null +++ b/src/main/java/eu/mhsl/craftattack/spawn/appliances/acInform/AcInformCommand.java @@ -0,0 +1,18 @@ +package eu.mhsl.craftattack.spawn.appliances.acInform; + +import eu.mhsl.craftattack.spawn.appliance.ApplianceCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public class AcInformCommand extends ApplianceCommand { + public AcInformCommand() { + super("acInform"); + } + + @Override + protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { +// if(sender instanceof Player) throw new ApplianceCommand.Error("Dieser Command ist nicht für Spieler!"); + getAppliance().processCommand(args); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4847a79..f7108d5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -45,3 +45,4 @@ commands: playtime: adminchat: aliases: [ "sc" ] + acInform: