WIP: different method for grief detection

This commit is contained in:
2025-09-20 11:35:19 +02:00
parent 4068eae5bb
commit dc1b5957f6
3 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.player.PlayerGriefListener;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
public class AntiGrief extends Appliance {
public record GriefIncident(Location location, @Nullable Block block) {
public static final Long timestamp = System.currentTimeMillis();
}
private final Map<UUID, List<GriefIncident>> griefRegistry = new HashMap<>();
public void addTracking(Player player, GriefIncident incident) {
this.griefRegistry.computeIfAbsent(player.getUniqueId(), uuid -> new ArrayList<>());
this.griefRegistry.get(player.getUniqueId()).add(incident);
}
public Map<UUID, List<GriefIncident>> getGriefRegistry() {
return this.griefRegistry;
}
@Override
protected @NotNull List<Listener> listeners() {
return List.of(new PlayerGriefListener());
}
}

View File

@@ -0,0 +1,39 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.commands;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.ScopedComponent;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class GriefOverviewCommand extends ApplianceCommand<AntiGrief> {
public GriefOverviewCommand() {
super("griefOverview");
}
@Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
sender.sendMessage(
this.getAppliance().getGriefRegistry().entrySet().stream()
.map(griefEntry -> {
List<TextComponent> entries = griefEntry.getValue().stream()
.map(incident -> Component.text(incident.location().toString()))
.toList();
ComponentBuilder<TextComponent, TextComponent.Builder> builder = Component.text()
.append(Component.text(griefEntry.getKey().toString()))
.append(Component.text(": "));
entries.forEach(builder::append);
return builder.build();
})
.reduce(ScopedComponent::append)
.orElseThrow()
);
}
}

View File

@@ -0,0 +1,20 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.player;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
public class PlayerGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void onIgnite(BlockIgniteEvent event) {
if(event.getPlayer() == null) return;
this.getAppliance().addTracking(event.getPlayer(), new AntiGrief.GriefIncident(event.getBlock().getLocation(), event.getBlock()));
}
@EventHandler
public void onTnt(ExplosionPrimeEvent event) {
}
}