From d4727d5ed94a1a7dd0b4c9c5fe4382e64dc72ee2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 07:43:22 +0100 Subject: [PATCH 1/9] Add CuboidColorization filter option Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerCommand.java | 8 +++++++- .../features/killchecker/KillcheckerVisualizer.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index fee15416..a6442669 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -48,9 +48,10 @@ public class KillcheckerCommand extends SWCommand implements Listener { } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") - public void genericCommand(Player player) { + public void genericCommand(Player player, @OptionalValue("ALL_CUBOIDS") ColorizedCuboidsOnly colorizedCuboidsOnly) { 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); BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); @@ -99,4 +100,9 @@ public class KillcheckerCommand extends SWCommand implements Listener { recalc(event.getBlock()); }, 1); } + + public enum ColorizedCuboidsOnly { + ONLY_COLORIZED_CUBOIDS, + ALL_CUBOIDS + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index e97f4a30..638cc955 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -27,6 +27,7 @@ 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; @@ -55,6 +56,9 @@ public class KillcheckerVisualizer { private REntityServer rEntityServer = new REntityServer(); + @Setter + private boolean onlyColorizedBlocks = false; + private Map killCount = new HashMap<>(); private Map rEntities = new HashMap<>(); @@ -67,6 +71,10 @@ public class KillcheckerVisualizer { 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; + } Cuboid cuboid = create(block.getType(), x, y, z); cuboids.add(cuboid); for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { -- 2.39.5 From 22b3da59e8d0e0ada094f14904d056d2ee682273 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 19:04:54 +0100 Subject: [PATCH 2/9] Update Killchecker Signed-off-by: yoyosource --- .../killchecker/KillcheckerCommand.java | 10 +- .../killchecker/KillcheckerVisualizer.java | 211 +++++++++++++++--- 2 files changed, 185 insertions(+), 36 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index a6442669..6a0fe5b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -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 - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 638cc955..b66dff69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -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 players = new HashSet<>(); + private Set 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 killCount = new HashMap<>(); + private Set outlinePointsCache = new HashSet<>(); private Map rEntities = new HashMap<>(); + private Map bossBars = new HashMap<>(); + + private double percent = 0; + private int kills = 0; + private int cannonCount = 0; public void recalc() { Set cuboids = new HashSet<>(); Set 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; - } + String name = block.getType().name(); + 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 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 yPoints = new HashSet<>(); + for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) { + for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) { Set 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 xPoints = new HashSet<>(); + for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) { + for (int z = minPoint.getZ(); z <= maxPoint.getZ(); z++) { Set 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 zPoints = new HashSet<>(); + for (int x = minPoint.getX(); x <= maxPoint.getX(); x++) { + for (int y = minPoint.getY(); y <= maxPoint.getY(); y++) { Set 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 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 entry : bossBars.entrySet()) { + updateBossBar(entry.getKey(), entry.getValue()); + } + Set pointSet = new HashSet<>(killCount.keySet()); + Set 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 checked = new HashSet<>(); Set 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; -- 2.39.5 From 4b3b8691b5495fe0067eb410de8024a475a4eec1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:02:32 +0100 Subject: [PATCH 3/9] Finalize everything Add Cuboid for killchecker Signed-off-by: yoyosource --- .../features/killchecker/Cuboid.java | 34 +++++++++++++++++++ .../killchecker/KillcheckerVisualizer.java | 32 ++++++++--------- 2 files changed, 50 insertions(+), 16 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java new file mode 100644 index 00000000..08632a9c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/Cuboid.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.killchecker; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Cuboid { + private double x; + private double y; + private double z; + private double dx; + private double dy; + private double dz; +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index b66dff69..2edf614d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.killchecker; -import de.steamwar.bausystem.features.slaves.laufbau.Cuboid; +import de.steamwar.bausystem.features.killchecker.Cuboid; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; @@ -43,20 +43,20 @@ import java.util.Set; 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 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 final Point minPoint; + private final Point maxPoint; - private int yArea; - private int zArea; - private int xArea; + private final int yArea; + private final int zArea; + private final int xArea; - private Set players = new HashSet<>(); - private Set areaPlayers = new HashSet<>(); + private final Set players = new HashSet<>(); + private final Set areaPlayers = new HashSet<>(); public KillcheckerVisualizer(Region region) { this.minPoint = region.getMinPoint(RegionType.BUILD, RegionExtensionType.NORMAL); @@ -67,13 +67,13 @@ public class KillcheckerVisualizer { xArea = (maxPoint.getY() - minPoint.getY()) * (maxPoint.getZ() - minPoint.getZ()); } - private REntityServer outline = new REntityServer(); - private REntityServer inner = new REntityServer(); + private final REntityServer outline = new REntityServer(); + private final REntityServer inner = new REntityServer(); - private Map killCount = new HashMap<>(); - private Set outlinePointsCache = new HashSet<>(); - private Map rEntities = new HashMap<>(); - private Map bossBars = new HashMap<>(); + private final Map killCount = new HashMap<>(); + private final Set outlinePointsCache = new HashSet<>(); + private final Map rEntities = new HashMap<>(); + private final Map bossBars = new HashMap<>(); private double percent = 0; private int kills = 0; @@ -272,7 +272,7 @@ public class KillcheckerVisualizer { if (killCount.get(point) == count && outlinePoints.contains(point) == outlinePointsCacheLast.contains(point)) return; rEntities.get(point).die(); } - 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]); + 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); -- 2.39.5 From 3e3415e9ca3053cb44f72c1eeaaf55e2ade714c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:56:25 +0100 Subject: [PATCH 4/9] Update some visuals, still needs to be multilingualed Signed-off-by: yoyosource --- .../bausystem/features/killchecker/KillcheckerVisualizer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 2edf614d..3b66aae6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -285,7 +285,7 @@ public class KillcheckerVisualizer { } private void updateBossBar(Player player, BossBar bossBar) { - bossBar.setTitle("§c§l" + kills + " §7(" + ((int) (percent * 1000) / 10.0) + "%) §e§l" + cannonCount + "§7 Kanonen"); + bossBar.setTitle("§e§l" + kills + " §7(§e" + ((int) (percent * 1000) / 10.0) + "%§7) §e§l" + cannonCount + "§7 Kanonen"); bossBar.setProgress(percent); if (percent >= 0.35) { bossBar.setColor(BarColor.RED); -- 2.39.5 From e7d5cee75a47b816f562a3eab9a527b028a03046 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Mar 2023 21:20:52 +0100 Subject: [PATCH 5/9] Hotfix NPE Signed-off-by: yoyosource --- .../bausystem/features/killchecker/KillcheckerVisualizer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 3b66aae6..2d876ebe 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -369,7 +369,9 @@ public class KillcheckerVisualizer { public boolean hide(Player player) { outline.removePlayer(player); - inner.removePlayer(player); + if (areaPlayers.contains(player)) { + inner.removePlayer(player); + } players.remove(player); areaPlayers.remove(player); bossBars.remove(player).removePlayer(player); -- 2.39.5 From b75d7c278aee73c532a45eb6cb5012b8312f2c95 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:09:13 +0100 Subject: [PATCH 6/9] Finalize Killchecker and include BauSystem Bossbar API for better Bossbar usage Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../killchecker/KillcheckerCommand.java | 7 +- .../killchecker/KillcheckerVisualizer.java | 43 +++--- .../utils/bossbar/BauSystemBossbar.java | 51 ++++++ .../utils/bossbar/BossBarService.java | 90 +++++++++++ .../utils/bossbar/GlobalBossbar.java | 112 ++++++++++++++ .../utils/bossbar/RegionedBossbar.java | 146 ++++++++++++++++++ 8 files changed, 429 insertions(+), 22 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 8d03d0ca..4ad71e2f 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -657,6 +657,7 @@ KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Disables Killcheck KILLCHECKER_INFO = §7Shows the overlaps of cannon kills in your build area. KILLCHECKER_ENABLE = §aKillchecker activated KILLCHECKER_DISABLE = §cKillchecker deactivated +KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Toggle on/off diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index f49f1fc6..89c05696 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -630,6 +630,7 @@ KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Deaktiviert Killch KILLCHECKER_INFO = §7Zeigt Überlappungen der Kanonen Kills im Baubereich an. KILLCHECKER_ENABLE = §aKillchecker aktiviert KILLCHECKER_DISABLE = §cKillchecker deaktiviert +KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen # BlockCounter BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 6a0fe5b9..7148b0f9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -21,8 +21,10 @@ package de.steamwar.bausystem.features.killchecker; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -42,6 +44,9 @@ public class KillcheckerCommand extends SWCommand implements Listener { private Map visualizers = new HashMap<>(); + @LinkedInstance + public BossBarService bossBarService; + public KillcheckerCommand() { super("killchecker"); addDefaultHelpMessage("KILLCHECKER_INFO"); @@ -50,7 +55,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") 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 killcheckerVisualizer = visualizers.computeIfAbsent(region, region1 -> new KillcheckerVisualizer(region1, bossBarService)); killcheckerVisualizer.recalc(); killcheckerVisualizer.show(player, onlyOutline); BauSystem.MESSAGE.send("KILLCHECKER_ENABLE", player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 2d876ebe..161a44b2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -19,11 +19,13 @@ package de.steamwar.bausystem.features.killchecker; -import de.steamwar.bausystem.features.killchecker.Cuboid; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; @@ -58,13 +60,19 @@ public class KillcheckerVisualizer { private final Set players = new HashSet<>(); private final Set areaPlayers = new HashSet<>(); - public KillcheckerVisualizer(Region region) { + private final Region region; + private final BossBarService bossBarService; + + public KillcheckerVisualizer(Region region, BossBarService bossBarService) { + this.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()); + + this.bossBarService = bossBarService; } private final REntityServer outline = new REntityServer(); @@ -73,7 +81,6 @@ public class KillcheckerVisualizer { private final Map killCount = new HashMap<>(); private final Set outlinePointsCache = new HashSet<>(); private final Map rEntities = new HashMap<>(); - private final Map bossBars = new HashMap<>(); private double percent = 0; private int kills = 0; @@ -253,9 +260,7 @@ public class KillcheckerVisualizer { double zPercent = xCount / (double) zArea; percent = (xPercent + yPercent + zPercent) / 3; kills = zKills + yKills + xKills; - for (Map.Entry entry : bossBars.entrySet()) { - updateBossBar(entry.getKey(), entry.getValue()); - } + players.forEach(this::updateBossBar); Set pointSet = new HashSet<>(killCount.keySet()); Set outlinePointsCacheLast = new HashSet<>(outlinePointsCache); @@ -284,17 +289,19 @@ public class KillcheckerVisualizer { return kills * (kills - 1) / 2; } - private void updateBossBar(Player player, BossBar bossBar) { - bossBar.setTitle("§e§l" + kills + " §7(§e" + ((int) (percent * 1000) / 10.0) + "%§7) §e§l" + cannonCount + "§7 Kanonen"); - bossBar.setProgress(percent); + private void updateBossBar(Player player) { + BauSystemBossbar bossbar = bossBarService.get(player, region, "killchecker"); + bossbar.setTitle(BauSystem.MESSAGE.parse("KILLCHECKER_BOSSBAR", player, kills, ((int) (percent * 1000) / 10.0), cannonCount)); + bossbar.setProgress(percent); + if (percent >= 0.35) { - bossBar.setColor(BarColor.RED); + bossbar.setColor(BarColor.RED); } else if (percent >= 0.25) { - bossBar.setColor(BarColor.PURPLE); + bossbar.setColor(BarColor.PURPLE); } else if (percent >= 0.15) { - bossBar.setColor(BarColor.YELLOW); + bossbar.setColor(BarColor.YELLOW); } else { - bossBar.setColor(BarColor.GREEN); + bossbar.setColor(BarColor.GREEN); } } @@ -357,13 +364,7 @@ public class KillcheckerVisualizer { 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; - }); + updateBossBar(player); return players.add(player); } @@ -374,7 +375,7 @@ public class KillcheckerVisualizer { } players.remove(player); areaPlayers.remove(player); - bossBars.remove(player).removePlayer(player); + bossBarService.remove(player, region, "killchecker"); if (players.isEmpty()) { outline.close(); return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java new file mode 100644 index 00000000..e72e0b53 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BauSystemBossbar.java @@ -0,0 +1,51 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils.bossbar; + +import de.steamwar.bausystem.region.Region; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; + +public interface BauSystemBossbar { + + String getTitle(); + void setTitle(String title); + + double getProgress(); + void setProgress(double progress); + + BarColor getColor(); + void setColor(BarColor color); + + BarStyle getStyle(); + void setStyle(BarStyle style); + + boolean hasFlag(BarFlag flag); + void addFlag(BarFlag flag); + void removeFlag(BarFlag flag); + + boolean isVisible(); + void setVisible(boolean visible); + + Region getRegion(); + + void cleanup(); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java new file mode 100644 index 00000000..6c7d636d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java @@ -0,0 +1,90 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils.bossbar; + +import de.steamwar.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class BossBarService implements Listener { + + private final Map>> playerBossBars = new HashMap<>(); + + public synchronized BauSystemBossbar get(Player player, Region region, String key) { + return playerBossBars.computeIfAbsent(player, p -> new HashMap<>()) + .computeIfAbsent(region, r -> new HashMap<>()) + .computeIfAbsent(key, k -> { + BossBar bossBar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID); + bossBar.addPlayer(player); + if (region.isGlobal()) { + return new GlobalBossbar(bossBar); + } else { + return new RegionedBossbar(bossBar, region, player); + } + }); + } + + public synchronized void removeAll(Player player, String key) { + Map> regionMap = playerBossBars.get(player); + if (regionMap == null) return; + for (Map bossBarMap : regionMap.values()) { + BauSystemBossbar bossBar = bossBarMap.remove(key); + if (bossBar == null) continue; + bossBar.cleanup(); + } + } + + public synchronized void removeAll(Player player) { + Map> regionMap = playerBossBars.remove(player); + if (regionMap == null) return; + for (Map bossBarMap : regionMap.values()) { + for (BauSystemBossbar bossBar : bossBarMap.values()) { + bossBar.cleanup(); + } + } + } + + public synchronized void remove(Player player, Region region, String key) { + Map> regionMap = playerBossBars.get(player); + if (regionMap == null) return; + Map bossBarMap = regionMap.get(region); + if (bossBarMap == null) return; + BauSystemBossbar bossBar = bossBarMap.remove(key); + if (bossBar == null) return; + bossBar.cleanup(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + removeAll(event.getPlayer()); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java new file mode 100644 index 00000000..a5aaf9fe --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/GlobalBossbar.java @@ -0,0 +1,112 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils.bossbar; + +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; + +public class GlobalBossbar implements BauSystemBossbar { + + private BossBar bossBar; + + public GlobalBossbar(BossBar bossBar) { + this.bossBar = bossBar; + } + + @Override + public String getTitle() { + return bossBar.getTitle(); + } + + @Override + public void setTitle(String title) { + bossBar.setTitle(title); + } + + @Override + public double getProgress() { + return bossBar.getProgress(); + } + + @Override + public void setProgress(double progress) { + bossBar.setProgress(progress); + } + + @Override + public BarColor getColor() { + return bossBar.getColor(); + } + + @Override + public void setColor(BarColor color) { + bossBar.setColor(color); + } + + @Override + public BarStyle getStyle() { + return bossBar.getStyle(); + } + + @Override + public void setStyle(BarStyle style) { + bossBar.setStyle(style); + } + + @Override + public boolean hasFlag(BarFlag flag) { + return bossBar.hasFlag(flag); + } + + @Override + public void addFlag(BarFlag flag) { + bossBar.addFlag(flag); + } + + @Override + public void removeFlag(BarFlag flag) { + bossBar.removeFlag(flag); + } + + @Override + public boolean isVisible() { + return bossBar.isVisible(); + } + + @Override + public void setVisible(boolean visible) { + bossBar.setVisible(visible); + } + + @Override + public Region getRegion() { + return GlobalRegion.getInstance(); + } + + @Override + public void cleanup() { + bossBar.removeAll(); + bossBar = null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java new file mode 100644 index 00000000..4d922143 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java @@ -0,0 +1,146 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils.bossbar; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import org.bukkit.Bukkit; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class RegionedBossbar implements BauSystemBossbar, Listener { + + private BossBar bossBar; + private Region region; + private Player player; + + public RegionedBossbar(BossBar bossBar, Region region, Player player) { + this.bossBar = bossBar; + this.region = region; + this.player = player; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + @Override + public String getTitle() { + return bossBar.getTitle(); + } + + @Override + public void setTitle(String title) { + bossBar.setTitle(title); + } + + @Override + public double getProgress() { + return bossBar.getProgress(); + } + + @Override + public void setProgress(double progress) { + bossBar.setProgress(progress); + } + + @Override + public BarColor getColor() { + return bossBar.getColor(); + } + + @Override + public void setColor(BarColor color) { + bossBar.setColor(color); + } + + @Override + public BarStyle getStyle() { + return bossBar.getStyle(); + } + + @Override + public void setStyle(BarStyle style) { + bossBar.setStyle(style); + } + + @Override + public boolean hasFlag(BarFlag flag) { + return bossBar.hasFlag(flag); + } + + @Override + public void addFlag(BarFlag flag) { + bossBar.addFlag(flag); + } + + @Override + public void removeFlag(BarFlag flag) { + bossBar.removeFlag(flag); + } + + @Override + public boolean isVisible() { + return bossBar.isVisible(); + } + + @Override + public void setVisible(boolean visible) { + bossBar.setVisible(visible); + } + + @Override + public Region getRegion() { + return region; + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + if (event.getPlayer() != player) return; + if (region.inRegion(event.getTo(), RegionType.NORMAL, RegionExtensionType.NORMAL)) { + bossBar.addPlayer(player); + } else { + bossBar.removePlayer(player); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + if (event.getPlayer() != player) return; + cleanup(); + } + + @Override + public void cleanup() { + bossBar.removeAll(); + bossBar = null; + region = null; + player = null; + + PlayerMoveEvent.getHandlerList().unregister(this); + PlayerQuitEvent.getHandlerList().unregister(this); + } +} -- 2.39.5 From b902fffb7669aa0a47df11027eac1a2df4e0d41f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:36:36 +0100 Subject: [PATCH 7/9] Move visualization outside of build area Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerVisualizer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index 161a44b2..d83f4b64 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -126,7 +126,7 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { yCount++; yKills += splitIntoDoubleKills(cuboidSet.size()); - Point p2 = new Point(x, maxPoint.getY(), z); + Point p2 = new Point(x, maxPoint.getY() + 1, z); yPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } @@ -147,10 +147,10 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { xCount++; xKills += splitIntoDoubleKills(cuboidSet.size()); - Point p1 = new Point(minPoint.getX(), y, z); + Point p1 = new Point(minPoint.getX() - 1, y, z); xPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); - Point p2 = new Point(maxPoint.getX(), y, z); + Point p2 = new Point(maxPoint.getX() + 1, y, z); xPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } @@ -171,10 +171,10 @@ public class KillcheckerVisualizer { if (cuboidSet.size() > 1) { zCount++; zKills += splitIntoDoubleKills(cuboidSet.size()); - Point p1 = new Point(x, y, minPoint.getZ()); + Point p1 = new Point(x, y, minPoint.getZ() - 1); zPoints.add(p1); kill.put(p1, Math.max(kill.getOrDefault(p1, 0), cuboidSet.size())); - Point p2 = new Point(x, y, maxPoint.getZ()); + Point p2 = new Point(x, y, maxPoint.getZ() + 1); zPoints.add(p2); kill.put(p2, Math.max(kill.getOrDefault(p2, 0), cuboidSet.size())); } -- 2.39.5 From ca730f7b8fd411d3b4fff8d46df68bceb8562ad2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 20:59:34 +0100 Subject: [PATCH 8/9] Fix NPE of KillcheckerVisualizer.hide Signed-off-by: yoyosource --- .../features/killchecker/KillcheckerCommand.java | 2 +- .../killchecker/KillcheckerVisualizer.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 7148b0f9..74fc72c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -78,7 +78,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { Player player = event.getPlayer(); Set regions = new HashSet<>(); visualizers.forEach((region, visualizer) -> { - if (visualizer.hide(player)) { + if (visualizer.disconnect(player)) { regions.add(region); } }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index d83f4b64..ff21d13b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -97,6 +97,7 @@ public class KillcheckerVisualizer { if (block.getType().isAir()) continue; String name = block.getType().name(); if (!name.endsWith("_WOOL") && !name.endsWith("_STAINED_GLASS") && !name.endsWith("_CONCRETE") && !name.endsWith("_TERRACOTTA")) continue; + if (name.equals("_GLAZED_TERRACOTTA")) continue; Cuboid cuboid = create(block.getType(), x, y, z); cuboids.add(cuboid); for (int dx = (int) cuboid.getX(); dx <= cuboid.getDx(); dx++) { @@ -378,6 +379,19 @@ public class KillcheckerVisualizer { bossBarService.remove(player, region, "killchecker"); if (players.isEmpty()) { outline.close(); + inner.close(); + return true; + } + return false; + } + + public boolean disconnect(Player player) { + players.remove(player); + areaPlayers.remove(player); + bossBarService.remove(player, region, "killchecker"); + if (players.isEmpty()) { + outline.close(); + inner.close(); return true; } return false; -- 2.39.5 From 0061bf77073ff418665fdefc4f09ba058c713ae0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 21:05:33 +0100 Subject: [PATCH 9/9] Add another help message Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + BauSystem_Main/src/BauSystem_de.properties | 1 + .../bausystem/features/killchecker/KillcheckerCommand.java | 1 + 3 files changed, 3 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4ad71e2f..695fe723 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -655,6 +655,7 @@ INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Enables Killchecker / Recalculates kills KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Disables Killchecker KILLCHECKER_INFO = §7Shows the overlaps of cannon kills in your build area. +KILLCHECKER_INFO2 = §7Only colorable blocks like Wool, Terractotta, Stained Glass and Concrete are counted. KILLCHECKER_ENABLE = §aKillchecker activated KILLCHECKER_DISABLE = §cKillchecker deactivated KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 cannons diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 89c05696..6dd8044b 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -628,6 +628,7 @@ INVENTORY_FILL_DISABLE = §cInventoryFiller deactivated KILLCHECKER_HELP_ENABLE = §8/§ekillchecker enable §8- §7Aktiviert Killchecker / Berechnet kills neu KILLCHECKER_HELP_DISABLE = §8/§ekillchecker disable §8- §7Deaktiviert Killchecker KILLCHECKER_INFO = §7Zeigt Überlappungen der Kanonen Kills im Baubereich an. +KILLCHECKER_INFO2 = §7Nur farbige Blöcke wie Wolle, Terracotta, Stained Glass und Concrete wird gezählt. KILLCHECKER_ENABLE = §aKillchecker aktiviert KILLCHECKER_DISABLE = §cKillchecker deaktiviert KILLCHECKER_BOSSBAR = §e§l{0} §7(§e{1}%§7) §e§l{2}§7 Kanonnen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index 74fc72c3..1340f1c1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -50,6 +50,7 @@ public class KillcheckerCommand extends SWCommand implements Listener { public KillcheckerCommand() { super("killchecker"); addDefaultHelpMessage("KILLCHECKER_INFO"); + addDefaultHelpMessage("KILLCHECKER_INFO2"); } @Register(value = "enable", description = "KILLCHECKER_HELP_ENABLE") -- 2.39.5