SteamWar/BauSystem2.0
Archiviert
12
0

Optimize Depth System

Dieser Commit ist enthalten in:
yoyosource 2021-05-02 17:08:27 +02:00
Ursprung 59a9a0dcfc
Commit c0b35c5da7

Datei anzeigen

@ -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 {
}
});
if (bukkitTask == null) {
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
if (TPSUtils.currentTick.get() - lastUpdate > 10) {
bukkitTask.cancel();
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);
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);
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
if (depthSet == null) {
return;
}
depthSet.remove(this);
toRemove.add(depth);
});
}
toRemove.forEach(depth -> {
Set<Depth> depthSet = DepthCounter.depthMap.get(depth.region);
depthSet.remove(depth);
if (depthSet.isEmpty()) {
DepthCounter.depthMap.remove(region);
DepthCounter.depthMap.remove(depth.region);
}
});
if (DepthCounter.depthMap.isEmpty()) {
bukkitTask.cancel();
bukkitTask = null;
}
}, 2, 2);
}
}, 1, 1);
}
public boolean update(List<Block> blocks) {