Add CuboidColorization filter option #167
@ -48,12 +48,11 @@ public class KillcheckerCommand extends SWCommand implements Listener {
|
||||
}
|
||||
|
||||
@Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE")
|
||||
public void genericCommand(Player player, @OptionalValue("ALL_CUBOIDS") ColorizedCuboidsOnly colorizedCuboidsOnly) {
|
||||
public void genericCommand(Player player, @OptionalValue("-outline") @StaticValue(value = {"-area", "-outline"}, allowISE = true) boolean onlyOutline) {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
KillcheckerVisualizer killcheckerVisualizer = visualizers.computeIfAbsent(region, KillcheckerVisualizer::new);
|
||||
killcheckerVisualizer.setOnlyColorizedBlocks(colorizedCuboidsOnly == ColorizedCuboidsOnly.ONLY_COLORIZED_CUBOIDS);
|
||||
killcheckerVisualizer.recalc();
|
||||
killcheckerVisualizer.show(player);
|
||||
killcheckerVisualizer.show(player, onlyOutline);
|
||||
BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player);
|
||||
}
|
||||
|
||||
@ -100,9 +99,4 @@ public class KillcheckerCommand extends SWCommand implements Listener {
|
||||
recalc(event.getBlock());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
public enum ColorizedCuboidsOnly {
|
||||
ONLY_COLORIZED_CUBOIDS,
|
||||
ALL_CUBOIDS
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,13 @@ import de.steamwar.bausystem.region.utils.RegionType;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -44,37 +46,50 @@ public class KillcheckerVisualizer {
|
||||
private static final Material[] materials = new Material[] {Material.YELLOW_STAINED_GLASS, Material.ORANGE_STAINED_GLASS, Material.RED_STAINED_GLASS, Material.PURPLE_STAINED_GLASS, Material.BLACK_STAINED_GLASS};
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static final double SURROUND = 4;
|
||||
|
||||
private Point minPoint;
|
||||
private Point maxPoint;
|
||||
|
||||
private int yArea;
|
||||
private int zArea;
|
||||
private int xArea;
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
private Set<Player> areaPlayers = new HashSet<>();
|
||||
|
||||
public KillcheckerVisualizer(Region region) {
|
||||
this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
||||
this.maxPoint = region.getMaxPoint(RegionType.BUILD, RegionExtensionType.NORMAL);
|
||||
|
||||
yArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getZ() - minPoint.getZ());
|
||||
zArea = (maxPoint.getX() - minPoint.getX()) * (maxPoint.getY() - minPoint.getY());
|
||||
xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ());
|
||||
}
|
||||
|
||||
private REntityServer rEntityServer = new REntityServer();
|
||||
|
||||
@Setter
|
||||
private boolean onlyColorizedBlocks = false;
|
||||
private REntityServer outline = new REntityServer();
|
||||
private REntityServer inner = new REntityServer();
|
||||
|
||||
private Map<Point, Integer> killCount = new HashMap<>();
|
||||
private Set<Point> outlinePointsCache = new HashSet<>();
|
||||
private Map<Point, REntity> rEntities = new HashMap<>();
|
||||
private Map<Player, BossBar> bossBars = new HashMap<>();
|
||||
|
||||
private double percent = 0;
|
||||
private int kills = 0;
|
||||
private int cannonCount = 0;
|
||||
|
||||
public void recalc() {
|
||||
Set<Cuboid> cuboids = new HashSet<>();
|
||||
Set<Point> points = new HashSet<>();
|
||||
for (int x = minPoint.getX() + 1; x < maxPoint.getX() - 1; x++) {
|
||||
for (int x = minPoint.getX() + 1; x < maxPoint.getX(); x++) {
|
||||
for (int y = minPoint.getY(); y < maxPoint.getY(); y++) {
|
||||
for (int z = minPoint.getZ() + 1; z < maxPoint.getZ() - 1; z++) {
|
||||
for (int z = minPoint.getZ() + 1; z < maxPoint.getZ(); z++) {
|
||||
if (points.contains(new Point(x, y, z))) continue;
|
||||
Block block = WORLD.getBlockAt(x, y, z);
|
||||
if (block.getType().isAir()) continue;
|
||||
if (onlyColorizedBlocks) {
|
||||
String name = block.getType().name();
|
||||
if (!name.endsWith("_WOOL") && name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue;
|
||||
}
|
||||
if (!name.endsWith("_WOOL") && !name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue;
|
||||
Cuboid cuboid = create(block.getType(), x, y, z);
|
||||
cuboids.add(cuboid);
|
||||
for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) {
|
||||
@ -87,60 +102,164 @@ public class KillcheckerVisualizer {
|
||||
}
|
||||
}
|
||||
}
|
||||
cannonCount = cuboids.size();
|
||||
|
||||
Map<Point, Integer> kill = new HashMap<>();
|
||||
for (int x = minPoint.getX(); x < maxPoint.getX(); x++) {
|
||||
for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) {
|
||||
int yKills = 0;
|
||||
int yCount = 0;
|
||||
Set<Point> yPoints = new HashSet<>();
|
||||
for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) {
|
||||
for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) {
|
||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
||||
for (Cuboid cuboid : cuboids) {
|
||||
if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) {
|
||||
if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) {
|
||||
cuboidSet.add(cuboid);
|
||||
}
|
||||
}
|
||||
if (cuboidSet.size() > 1) {
|
||||
Point p1 = new Point(x, minPoint.getY(), z);
|
||||
kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size()));
|
||||
yCount++;
|
||||
yKills += splitIntoDoubleKills(cuboidSet.size());
|
||||
Point p2 = new Point(x, maxPoint.getY(), z);
|
||||
yPoints.add(p2);
|
||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = minPoint.getY(); y < maxPoint.getY(); y++) {
|
||||
for (int z = minPoint.getZ(); z < maxPoint.getZ(); z++) {
|
||||
int xKills = 0;
|
||||
int xCount = 0;
|
||||
Set<Point> xPoints = new HashSet<>();
|
||||
for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) {
|
||||
for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) {
|
||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
||||
for (Cuboid cuboid : cuboids) {
|
||||
if (y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5 && z >= cuboid.getZ() - 3.5 && z <= cuboid.getDz() + 3.5) {
|
||||
if (y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND && z >= cuboid.getZ() - SURROUND && z < cuboid.getDz() + SURROUND) {
|
||||
cuboidSet.add(cuboid);
|
||||
}
|
||||
}
|
||||
if (cuboidSet.size() > 1) {
|
||||
xCount++;
|
||||
xKills += splitIntoDoubleKills(cuboidSet.size());
|
||||
Point p1 = new Point(minPoint.getX(), y, z);
|
||||
xPoints.add(p1);
|
||||
kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size()));
|
||||
Point p2 = new Point(maxPoint.getX(), y, z);
|
||||
xPoints.add(p2);
|
||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = minPoint.getX(); x < maxPoint.getX(); x++) {
|
||||
for (int y = minPoint.getY(); y < maxPoint.getY(); y++) {
|
||||
int zKills = 0;
|
||||
int zCount = 0;
|
||||
Set<Point> zPoints = new HashSet<>();
|
||||
for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) {
|
||||
for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) {
|
||||
Set<Cuboid> cuboidSet = new HashSet<>();
|
||||
for (Cuboid cuboid : cuboids) {
|
||||
if (x >= cuboid.getX() - 3.5 && x <= cuboid.getDx() + 3.5 && y >= cuboid.getY() - 3.5 && y <= cuboid.getDy() + 3.5) {
|
||||
if (x >= cuboid.getX() - SURROUND && x < cuboid.getDx() + SURROUND && y >= cuboid.getY() - SURROUND && y < cuboid.getDy() + SURROUND) {
|
||||
cuboidSet.add(cuboid);
|
||||
}
|
||||
}
|
||||
if (cuboidSet.size() > 1) {
|
||||
zCount++;
|
||||
zKills += splitIntoDoubleKills(cuboidSet.size());
|
||||
Point p1 = new Point(x, y, minPoint.getZ());
|
||||
zPoints.add(p1);
|
||||
kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size()));
|
||||
Point p2 = new Point(x, y, maxPoint.getZ());
|
||||
zPoints.add(p2);
|
||||
kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<Point> outlinePoints = new HashSet<>();
|
||||
yPoints.forEach(point -> {
|
||||
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
|
||||
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
|
||||
Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1);
|
||||
Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1);
|
||||
|
||||
Point p5 = new Point(point.getX() - 1, point.getY(), point.getZ() - 1);
|
||||
Point p6 = new Point(point.getX() - 1, point.getY(), point.getZ() + 1);
|
||||
Point p7 = new Point(point.getX() + 1, point.getY(), point.getZ() - 1);
|
||||
Point p8 = new Point(point.getX() + 1, point.getY(), point.getZ() + 1);
|
||||
|
||||
int count = kill.get(point);
|
||||
|
||||
int surrounded = 0;
|
||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
||||
if (surrounded != 4) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
||||
});
|
||||
xPoints.forEach(point -> {
|
||||
Point p1 = new Point(point.getX(), point.getY() - 1, point.getZ());
|
||||
Point p2 = new Point(point.getX(), point.getY() + 1, point.getZ());
|
||||
Point p3 = new Point(point.getX(), point.getY(), point.getZ() - 1);
|
||||
Point p4 = new Point(point.getX(), point.getY(), point.getZ() + 1);
|
||||
|
||||
Point p5 = new Point(point.getX(), point.getY() - 1, point.getZ() - 1);
|
||||
Point p6 = new Point(point.getX(), point.getY() - 1, point.getZ() + 1);
|
||||
Point p7 = new Point(point.getX(), point.getY() + 1, point.getZ() - 1);
|
||||
Point p8 = new Point(point.getX(), point.getY() + 1, point.getZ() + 1);
|
||||
|
||||
int count = kill.get(point);
|
||||
|
||||
int surrounded = 0;
|
||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
||||
if (surrounded != 4) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
||||
});
|
||||
zPoints.forEach(point -> {
|
||||
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
|
||||
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
|
||||
Point p3 = new Point(point.getX(), point.getY() - 1, point.getZ());
|
||||
Point p4 = new Point(point.getX(), point.getY() + 1, point.getZ());
|
||||
|
||||
Point p5 = new Point(point.getX() - 1, point.getY() - 1, point.getZ());
|
||||
Point p6 = new Point(point.getX() - 1, point.getY() + 1, point.getZ());
|
||||
Point p7 = new Point(point.getX() + 1, point.getY() - 1, point.getZ());
|
||||
Point p8 = new Point(point.getX() + 1, point.getY() + 1, point.getZ());
|
||||
|
||||
int count = kill.get(point);
|
||||
|
||||
int surrounded = 0;
|
||||
if (kill.getOrDefault(p1, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p2, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p3, 0) == count) surrounded++;
|
||||
if (kill.getOrDefault(p4, 0) == count) surrounded++;
|
||||
if (surrounded != 4) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p5, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p6, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p7, 0) != count) outlinePoints.add(point);
|
||||
if (kill.getOrDefault(p8, 0) != count) outlinePoints.add(point);
|
||||
});
|
||||
|
||||
double xPercent = zCount / (double) xArea;
|
||||
double yPercent = yCount / (double) yArea;
|
||||
double zPercent = xCount / (double) zArea;
|
||||
percent = (xPercent + yPercent + zPercent) / 3;
|
||||
kills = zKills + yKills + xKills;
|
||||
for (Map.Entry<Player, BossBar> entry : bossBars.entrySet()) {
|
||||
updateBossBar(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
Set<Point> pointSet = new HashSet<>(killCount.keySet());
|
||||
Set<Point> outlinePointsCacheLast = new HashSet<>(outlinePointsCache);
|
||||
outlinePointsCache.clear();
|
||||
for (Point point : pointSet) {
|
||||
if (!kill.containsKey(point)) {
|
||||
rEntities.get(point).die();
|
||||
@ -150,16 +269,35 @@ public class KillcheckerVisualizer {
|
||||
}
|
||||
kill.forEach((point, count) -> {
|
||||
if (rEntities.containsKey(point)) {
|
||||
if (killCount.get(point) == count) return;
|
||||
if (killCount.get(point) == count && outlinePoints.contains(point) == outlinePointsCacheLast.contains(point)) return;
|
||||
rEntities.get(point).die();
|
||||
}
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]);
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(outlinePoints.contains(point) ? outline : inner, point.toLocation(WORLD, 0.5, 0, 0.5), materials[Math.min(count - 1, materials.length) - 1]);
|
||||
entity.setNoGravity(true);
|
||||
rEntities.put(point, entity);
|
||||
if (outlinePoints.contains(point)) outlinePointsCache.add(point);
|
||||
killCount.put(point, count);
|
||||
});
|
||||
}
|
||||
|
||||
private int splitIntoDoubleKills(int kills) {
|
||||
return kills * (kills - 1) / 2;
|
||||
}
|
||||
|
||||
private void updateBossBar(Player player, BossBar bossBar) {
|
||||
bossBar.setTitle("§c§l" + kills + " §7(" + ((int) (percent * 1000) / 10.0) + "%) §e§l" + cannonCount + "§7 Kanonen");
|
||||
bossBar.setProgress(percent);
|
||||
if (percent >= 0.35) {
|
||||
bossBar.setColor(BarColor.RED);
|
||||
} else if (percent >= 0.25) {
|
||||
bossBar.setColor(BarColor.PURPLE);
|
||||
} else if (percent >= 0.15) {
|
||||
bossBar.setColor(BarColor.YELLOW);
|
||||
} else {
|
||||
bossBar.setColor(BarColor.GREEN);
|
||||
}
|
||||
}
|
||||
|
||||
private Cuboid create(Material type, int x, int y, int z) {
|
||||
Set<Point> checked = new HashSet<>();
|
||||
Set<Point> points = new HashSet<>();
|
||||
@ -210,16 +348,33 @@ public class KillcheckerVisualizer {
|
||||
return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
public boolean show(Player player) {
|
||||
rEntityServer.addPlayer(player);
|
||||
public boolean show(Player player, boolean onlyOutline) {
|
||||
outline.addPlayer(player);
|
||||
if (!onlyOutline) {
|
||||
inner.addPlayer(player);
|
||||
areaPlayers.add(player);
|
||||
} else if (areaPlayers.contains(player)) {
|
||||
inner.removePlayer(player);
|
||||
areaPlayers.remove(player);
|
||||
}
|
||||
bossBars.computeIfAbsent(player, player1 -> {
|
||||
BossBar bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SOLID);
|
||||
updateBossBar(player1, bossBar);
|
||||
bossBar.addPlayer(player1);
|
||||
bossBar.setVisible(true);
|
||||
return bossBar;
|
||||
});
|
||||
return players.add(player);
|
||||
}
|
||||
|
||||
public boolean hide(Player player) {
|
||||
rEntityServer.removePlayer(player);
|
||||
outline.removePlayer(player);
|
||||
inner.removePlayer(player);
|
||||
players.remove(player);
|
||||
areaPlayers.remove(player);
|
||||
bossBars.remove(player).removePlayer(player);
|
||||
if (players.isEmpty()) {
|
||||
rEntityServer.close();
|
||||
outline.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren