Optimize Depth System
Dieser Commit ist enthalten in:
Ursprung
59a9a0dcfc
Commit
c0b35c5da7
@ -28,22 +28,26 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Depth {
|
||||
|
||||
private static BukkitTask bukkitTask = null;
|
||||
|
||||
private Region region;
|
||||
private int tntCount = 1;
|
||||
private Vector minVector = null;
|
||||
private Vector maxVector = null;
|
||||
|
||||
private long lastUpdate = TPSUtils.currentTick.get();
|
||||
private BukkitTask bukkitTask;
|
||||
|
||||
public Depth(Region region, List<Block> blocks) {
|
||||
if (blocks.isEmpty()) {
|
||||
throw new SecurityException();
|
||||
}
|
||||
this.region = region;
|
||||
blocks.forEach(block -> {
|
||||
if (minVector == null) {
|
||||
minVector = DepthCounter.blockVector(block.getLocation().toVector());
|
||||
@ -53,29 +57,45 @@ public class Depth {
|
||||
}
|
||||
});
|
||||
|
||||
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (TPSUtils.currentTick.get() - lastUpdate > 10) {
|
||||
bukkitTask.cancel();
|
||||
if (bukkitTask == null) {
|
||||
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
Set<Depth> toRemove = new HashSet<>();
|
||||
for (Set<Depth> value : DepthCounter.depthMap.values()) {
|
||||
value.forEach(depth -> {
|
||||
if (TPSUtils.currentTick.get() - depth.lastUpdate < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector dimensions = maxVector.subtract(minVector);
|
||||
dimensions.setX(Math.abs(dimensions.getX()));
|
||||
dimensions.setY(Math.abs(dimensions.getY()));
|
||||
dimensions.setZ(Math.abs(dimensions.getZ()));
|
||||
Vector dimensions = depth.maxVector.subtract(depth.minVector);
|
||||
dimensions.setX(Math.abs(dimensions.getX()));
|
||||
dimensions.setY(Math.abs(dimensions.getY()));
|
||||
dimensions.setZ(Math.abs(dimensions.getZ()));
|
||||
|
||||
if (tntCount > 4 && dimensions.getX() != 0 && dimensions.getY() != 0 && dimensions.getZ() != 0) {
|
||||
RegionUtils.message(region, player -> DepthCounter.getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount));
|
||||
}
|
||||
if (depth.tntCount > 4 && dimensions.getX() != 0 && dimensions.getY() != 0 && dimensions.getZ() != 0) {
|
||||
RegionUtils.message(depth.region, player -> DepthCounter.getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, depth.tntCount));
|
||||
}
|
||||
|
||||
Set<Depth> depthSet = DepthCounter.depthMap.get(region);
|
||||
if (depthSet == null) {
|
||||
return;
|
||||
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
|
||||
if (depthSet == null) {
|
||||
return;
|
||||
}
|
||||
toRemove.add(depth);
|
||||
});
|
||||
}
|
||||
depthSet.remove(this);
|
||||
if (depthSet.isEmpty()) {
|
||||
DepthCounter.depthMap.remove(region);
|
||||
toRemove.forEach(depth -> {
|
||||
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
|
||||
depthSet.remove(depth);
|
||||
if (depthSet.isEmpty()) {
|
||||
DepthCounter.depthMap.remove(depth.region);
|
||||
}
|
||||
});
|
||||
|
||||
if (DepthCounter.depthMap.isEmpty()) {
|
||||
bukkitTask.cancel();
|
||||
bukkitTask = null;
|
||||
}
|
||||
}
|
||||
}, 1, 1);
|
||||
}, 2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean update(List<Block> blocks) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren