|
|
|
@ -28,28 +28,29 @@ import de.steamwar.linkage.Linked;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Linked
|
|
|
|
|
public class CannonDetector implements Listener {
|
|
|
|
|
|
|
|
|
|
private Map<TNTPrimed, Vector> velocities = new HashMap<>();
|
|
|
|
|
private Map<TNTPrimed, Set<UUID>> propulsionOfProjectile = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
|
|
|
|
public void onEntityExplode(EntityExplodeEvent event) {
|
|
|
|
|
if (!(event.getEntity() instanceof TNTPrimed)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TNTPrimed tnt = (TNTPrimed) event.getEntity();
|
|
|
|
|
propulsionOfProjectile.remove(tnt);
|
|
|
|
|
|
|
|
|
|
DepthManager.update(tnt, event.blockList());
|
|
|
|
|
|
|
|
|
|
List<TNTPrimed> tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
|
|
|
|
@ -66,6 +67,7 @@ public class CannonDetector implements Listener {
|
|
|
|
|
boolean isEmpty = velocities.isEmpty();
|
|
|
|
|
tnts.forEach(tntPrimed -> {
|
|
|
|
|
velocities.put(tntPrimed, tntPrimed.getVelocity().clone());
|
|
|
|
|
propulsionOfProjectile.computeIfAbsent(tntPrimed, __ -> new HashSet<>()).add(tnt.getUniqueId());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!isEmpty) {
|
|
|
|
@ -75,7 +77,10 @@ public class CannonDetector implements Listener {
|
|
|
|
|
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
|
|
|
|
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
|
|
|
|
|
velocities.forEach((tntPrimed, vector) -> {
|
|
|
|
|
grouped.computeIfAbsent(new CannonKey(round(tntPrimed.getLocation().toVector()), round(vector)), ignored -> new ArrayList<>()).add(tntPrimed);
|
|
|
|
|
boolean xBiggest = Math.abs(vector.getX()) > Math.abs(vector.getZ());
|
|
|
|
|
boolean zBiggest = Math.abs(vector.getZ()) > Math.abs(vector.getX());
|
|
|
|
|
Vector vec = new Vector(xBiggest ? Math.signum(vector.getX()) : 0, Math.round(vector.getY() * 100), zBiggest ? Math.signum(vector.getZ()) : 0);
|
|
|
|
|
grouped.computeIfAbsent(new CannonKey(propulsionOfProjectile.get(tntPrimed), vec), ignored -> new ArrayList<>()).add(tntPrimed);
|
|
|
|
|
});
|
|
|
|
|
grouped.forEach((cannonKey, tntPrimeds) -> {
|
|
|
|
|
if (tntPrimeds.size() <= 5) return;
|
|
|
|
@ -88,12 +93,4 @@ public class CannonDetector implements Listener {
|
|
|
|
|
velocities.clear();
|
|
|
|
|
}, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Vector round(Vector vector) {
|
|
|
|
|
vector.multiply(10000);
|
|
|
|
|
vector.setX(Math.round(vector.getX()));
|
|
|
|
|
vector.setY(Math.round(vector.getY()));
|
|
|
|
|
vector.setZ(Math.round(vector.getZ()));
|
|
|
|
|
return vector;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|