Merge remote-tracking branch 'origin/master'

This commit is contained in:
Elias Müller 2024-11-05 21:23:48 +01:00
commit fc5b76290e
3 changed files with 151 additions and 0 deletions

View File

@ -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<TextComponent, TextComponent.Builder> 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<ApplianceCommand<?>> commands() {
return List.of(
new AcInformCommand()
);
}
}

View File

@ -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<AcInform> {
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);
}
}

View File

@ -45,3 +45,4 @@ commands:
playtime:
adminchat:
aliases: [ "sc" ]
acInform: