Fix Depth
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
1a93f2fc41
Commit
643486cfe5
@ -28,28 +28,29 @@ import de.steamwar.linkage.Linked;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
public class CannonDetector implements Listener {
|
public class CannonDetector implements Listener {
|
||||||
|
|
||||||
private Map<TNTPrimed, Vector> velocities = new HashMap<>();
|
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) {
|
public void onEntityExplode(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof TNTPrimed)) {
|
if (!(event.getEntity() instanceof TNTPrimed)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TNTPrimed tnt = (TNTPrimed) event.getEntity();
|
TNTPrimed tnt = (TNTPrimed) event.getEntity();
|
||||||
|
propulsionOfProjectile.remove(tnt);
|
||||||
|
|
||||||
DepthManager.update(tnt, event.blockList());
|
DepthManager.update(tnt, event.blockList());
|
||||||
|
|
||||||
List<TNTPrimed> tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
|
List<TNTPrimed> tnts = Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)
|
||||||
@ -66,6 +67,7 @@ public class CannonDetector implements Listener {
|
|||||||
boolean isEmpty = velocities.isEmpty();
|
boolean isEmpty = velocities.isEmpty();
|
||||||
tnts.forEach(tntPrimed -> {
|
tnts.forEach(tntPrimed -> {
|
||||||
velocities.put(tntPrimed, tntPrimed.getVelocity().clone());
|
velocities.put(tntPrimed, tntPrimed.getVelocity().clone());
|
||||||
|
propulsionOfProjectile.computeIfAbsent(tntPrimed, __ -> new HashSet<>()).add(tnt.getUniqueId());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isEmpty) {
|
if (!isEmpty) {
|
||||||
@ -75,7 +77,10 @@ public class CannonDetector implements Listener {
|
|||||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
|
Map<CannonKey, List<TNTPrimed>> grouped = new HashMap<>();
|
||||||
velocities.forEach((tntPrimed, vector) -> {
|
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) -> {
|
grouped.forEach((cannonKey, tntPrimeds) -> {
|
||||||
if (tntPrimeds.size() <= 5) return;
|
if (tntPrimeds.size() <= 5) return;
|
||||||
@ -88,12 +93,4 @@ public class CannonDetector implements Listener {
|
|||||||
velocities.clear();
|
velocities.clear();
|
||||||
}, 1);
|
}, 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,16 @@ package de.steamwar.bausystem.features.cannon;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@Getter
|
@Getter
|
||||||
public final class CannonKey {
|
public final class CannonKey {
|
||||||
private Vector locationVector;
|
private Set<UUID> propulsions;
|
||||||
private Vector velocityVector;
|
private Vector velocityVector;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@ public class Depth {
|
|||||||
List<Block> blocksList = blocks.stream()
|
List<Block> blocksList = blocks.stream()
|
||||||
.filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
|
.filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (blocksList.isEmpty()) return;
|
|
||||||
tntCount++;
|
tntCount++;
|
||||||
for (Block block : blocksList) {
|
for (Block block : blocksList) {
|
||||||
internalUpdate(block);
|
internalUpdate(block);
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren