From 643486cfe5a99f7f22cf356bcb72ddd4629cf9ad Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 5 Oct 2023 21:10:55 +0200 Subject: [PATCH] Fix Depth Signed-off-by: yoyosource --- .../features/cannon/CannonDetector.java | 25 ++++++++----------- .../bausystem/features/cannon/CannonKey.java | 6 ++++- .../features/cannon/depth/Depth.java | 1 - 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java index 09893fd5..3ab4fe70 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonDetector.java @@ -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 velocities = new HashMap<>(); + private Map> 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 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> 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; - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java index 73270eab..c260e8a9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/CannonKey.java @@ -22,12 +22,16 @@ package de.steamwar.bausystem.features.cannon; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; +import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; +import java.util.Set; +import java.util.UUID; + @AllArgsConstructor @EqualsAndHashCode @Getter public final class CannonKey { - private Vector locationVector; + private Set propulsions; private Vector velocityVector; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java index 506b6e93..a13d6250 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/cannon/depth/Depth.java @@ -51,7 +51,6 @@ public class Depth { List blocksList = blocks.stream() .filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) .collect(Collectors.toList()); - if (blocksList.isEmpty()) return; tntCount++; for (Block block : blocksList) { internalUpdate(block);