From 106a1a8fb0fc3ef2c1267ec9e1fa380c0e315654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 6 Mar 2023 21:17:42 +0100 Subject: [PATCH 01/33] Hotfix TNTElement alignment Author: PSIRobot Signed-off-by: yoyosource --- .../features/simulator/gui/TNTElementGUI.java | 8 ++--- .../features/simulator/tnt/TNTElement.java | 31 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java index e87640d0..93181f90 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/TNTElementGUI.java @@ -136,22 +136,22 @@ public class TNTElementGUI { // Alignment inv.setItem(23, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_Z", player), clickType -> { // Z negative if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.5, 0, 0.49)); + tntElement.align(new Vector(0, 0, 0.49)); tntElement.change(); })); inv.setItem(25, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_Z", player), clickType -> { // Z positive if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.5, 0, 0.51)); + tntElement.align(new Vector(0, 0, 0.51)); tntElement.change(); })); inv.setItem(15, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_POSITIVE_X", player), clickType -> { // X positive if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.51, 0, 0.5)); + tntElement.align(new Vector(0.51, 0, 0)); tntElement.change(); })); inv.setItem(33, new SWItem(Material.OAK_BUTTON, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_NEGATIVE_X", player), clickType -> { // X negative if (clickType == ClickType.DOUBLE_CLICK) return; - tntElement.align(new Vector(0.49, 0, 0.5)); + tntElement.align(new Vector(0.49, 0, 0)); tntElement.change(); })); inv.setItem(24, new SWItem(Material.SUNFLOWER, BauSystem.MESSAGE.parse("SIMULATOR_ALIGNMENT_CENTER", player), clickType -> { // CENTER diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java index af6e3045..666c3359 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/tnt/TNTElement.java @@ -293,22 +293,25 @@ public class TNTElement implements SimulatorElement { parentVector = tntGroup.getPosition(); } - if (vector.getX() - (int) vector.getX() == 0.49) { - vector.setX(vector.getX() + 0.02); - } - if (vector.getX() - (int) vector.getX() == -0.49) { - vector.setX(vector.getX() - 0.02); - } - if (vector.getZ() - (int) vector.getZ() == 0.49) { - vector.setZ(vector.getZ() + 0.02); - } - if (vector.getZ() - (int) vector.getZ() == -0.49) { - vector.setZ(vector.getZ() - 0.02); + if (offset.getX() != 0) { + if (vector.getX() - (int) vector.getX() == 0.49) { + vector.setX(vector.getX() + 0.02); + } + if (vector.getX() - (int) vector.getX() == -0.49) { + vector.setX(vector.getX() - 0.02); + } + vector.setX(vector.getBlockX() + offset.getX()); } - vector.setX(vector.getBlockX() + offset.getX()); - vector.setY(vector.getBlockY() + offset.getY()); - vector.setZ(vector.getBlockZ() + offset.getZ()); + if (offset.getZ() != 0) { + if (vector.getZ() - (int) vector.getZ() == 0.49) { + vector.setZ(vector.getZ() + 0.02); + } + if (vector.getZ() - (int) vector.getZ() == -0.49) { + vector.setZ(vector.getZ() - 0.02); + } + vector.setZ(vector.getBlockZ() + offset.getZ()); + } setPosition(vector.subtract(parentVector)); } From d4727d5ed94a1a7dd0b4c9c5fe4382e64dc72ee2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 07:43:22 +0100 Subject: [PATCH 02/33] 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++) { From 22b3da59e8d0e0ada094f14904d056d2ee682273 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 19:04:54 +0100 Subject: [PATCH 03/33] 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; From 4b3b8691b5495fe0067eb410de8024a475a4eec1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:02:32 +0100 Subject: [PATCH 04/33] 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); From 3e3415e9ca3053cb44f72c1eeaaf55e2ade714c9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Mar 2023 21:56:25 +0100 Subject: [PATCH 05/33] 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); From e7d5cee75a47b816f562a3eab9a527b028a03046 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Mar 2023 21:20:52 +0100 Subject: [PATCH 06/33] 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); From 519c832c9dcbd3066f42b5e6525561a8a2306147 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 17:04:22 +0100 Subject: [PATCH 07/33] Hotfix NMSWrapper19 --- .../src/de/steamwar/bausystem/utils/NMSWrapper19.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index 24edeb9a..d6c7df29 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -28,6 +28,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.network.syncher.DataWatcher; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.phys.Vec3D; @@ -44,7 +45,6 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; -import java.util.Objects; import java.util.function.LongSupplier; public class NMSWrapper19 implements NMSWrapper { @@ -91,7 +91,9 @@ public class NMSWrapper19 implements NMSWrapper { if (entity instanceof TNTPrimed) { net.minecraft.world.entity.Entity serverEntity = ((CraftEntity) entity).getHandle(); - packets.add(new PacketPlayOutEntityMetadata(serverEntity.ah(), Objects.requireNonNull(serverEntity.al().c()))); + List> list = serverEntity.al().c(); + if(list != null) + packets.add(new PacketPlayOutEntityMetadata(serverEntity.ah(), list)); } }); } From 69b31483f49edac7246e41977f7221b32922a70a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 12 Mar 2023 21:04:56 +0100 Subject: [PATCH 08/33] Fix -builddestroyonly Trace option Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/region/TNTListener.java | 3 ++- .../bausystem/features/tracer/record/Recorder.java | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 6bb5b15b..958471e2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -35,6 +35,7 @@ import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent; @@ -83,7 +84,7 @@ public class TNTListener implements Listener { explode(event.blockList(), event.getBlock().getLocation(), null, null); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index 2d74492d..fe941f5f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -32,6 +32,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; @@ -180,7 +181,7 @@ public class Recorder implements Listener { }); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof TNTPrimed)) { @@ -188,7 +189,9 @@ public class Recorder implements Listener { } TraceRecorder traceRecorder = get((TNTPrimed) entity); Region region = tntTraceRecorderMap.get((TNTPrimed) entity); - traceRecorder.explode((TNTPrimed) entity, !event.blockList().isEmpty() && region.inRegion(event.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); + boolean inBuildRegion = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); + System.out.println(event.blockList() + " " + inBuildRegion); + traceRecorder.explode((TNTPrimed) entity, inBuildRegion); tntTraceRecorderMap.remove(entity); tick(); } From 8e133f08328eac647a96cb76297fc73390f80ffd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Mar 2023 20:58:53 +0100 Subject: [PATCH 09/33] Probable fix for SelfJoin Event Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/script/ScriptListener.java | 2 +- .../bausystem/features/script/custom/event/EventListener.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index fbdbf0f2..ef9abe06 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -47,7 +47,7 @@ public class ScriptListener implements Listener { new ScriptExecutor((BookMeta) item.getItemMeta(), event.getPlayer(), null); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { GLOBAL_CONTEXT.put(event.getPlayer(), new Context()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java index f8913e28..4ee1a97d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/custom/event/EventListener.java @@ -30,6 +30,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; @@ -58,7 +59,7 @@ public class EventListener implements Listener { }, 2, 2); } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { manager.callEvent(EventType.SelfJoin, event.getPlayer(), event); } From ca338699faee167e78b94b249f641d1d3a6d0784 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Mar 2023 18:23:52 +0100 Subject: [PATCH 10/33] Hotfix If Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/script/command/If.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index e2a2ac44..47d92f25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -46,7 +46,7 @@ public class If implements SpecialCommand { BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_NO_BOOLEAN", scriptExecutor.getPlayer()); return false; } - if (v.asBoolean()) { + if (v.asBoolean() && command.length > 2) { jumpToIndex(scriptExecutor, command[2]); } else if (command.length > 3) { jumpToIndex(scriptExecutor, command[3]); From b75d7c278aee73c532a45eb6cb5012b8312f2c95 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:09:13 +0100 Subject: [PATCH 11/33] 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); + } +} From b902fffb7669aa0a47df11027eac1a2df4e0d41f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 18:36:36 +0100 Subject: [PATCH 12/33] 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())); } From ca730f7b8fd411d3b4fff8d46df68bceb8562ad2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 20:59:34 +0100 Subject: [PATCH 13/33] 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; From 0061bf77073ff418665fdefc4f09ba058c713ae0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Mar 2023 21:05:33 +0100 Subject: [PATCH 14/33] 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") From fa906f7f4f11b78779831b34b765d2e6adce5c7a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:11:09 +0100 Subject: [PATCH 15/33] Hotfix Xray Signed-off-by: yoyosource --- .../utils/PlayerMovementWrapper19.java | 32 +++++++++++++++++++ .../bausystem/features/xray/XrayCommand.java | 1 + .../utils/PlayerMovementWrapper.java | 2 ++ 3 files changed, 35 insertions(+) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index fd9a892e..a3531e5e 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -21,19 +21,51 @@ package de.steamwar.bausystem.utils; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; +import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + public class PlayerMovementWrapper19 implements PlayerMovementWrapper { + private static class Position { + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + } + + private Map playerLocationMap = new HashMap<>(); + @Override public void setPosition(Player player, Object object) { + Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> new Position()); PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object); EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); if (packetPlayInFlying.h) { entityPlayer.b(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c, packetPlayInFlying.d, packetPlayInFlying.e); + position.x = packetPlayInFlying.a; + position.y = packetPlayInFlying.b; + position.z = packetPlayInFlying.c; + position.yaw = packetPlayInFlying.d; + position.pitch = packetPlayInFlying.e; } else { entityPlayer.e(packetPlayInFlying.a, packetPlayInFlying.b, packetPlayInFlying.c); + position.x = packetPlayInFlying.a; + position.y = packetPlayInFlying.b; + position.z = packetPlayInFlying.c; + } + } + + @Override + public void disable(Player player) { + Position position = playerLocationMap.remove(player.getUniqueId()); + if (position != null) { + player.teleport(new Location(player.getWorld(), position.x, position.y, position.z, position.yaw, position.pitch)); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 22c19b67..f1232760 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -97,6 +97,7 @@ public class XrayCommand extends SWCommand implements Listener { techHiderCommand.disable(region, player); if (hidden.get(region).contains(player)) { hidden.get(region).remove(player); + PlayerMovementWrapper.impl.disable(player); BauSystem.MESSAGE.sendPrefixless("XRAY_OFF", player, ChatMessageType.ACTION_BAR); } else { hidden.get(region).add(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java index f8aa209d..4a6a6447 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java @@ -27,4 +27,6 @@ public interface PlayerMovementWrapper { PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); void setPosition(Player player, Object object); + default void disable(Player player) { + } } From d6c9e8f827eb32569c95e4c606b199adf21294c4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:14:08 +0100 Subject: [PATCH 16/33] Hotfix Xray Signed-off-by: yoyosource --- .../bausystem/utils/PlayerMovementWrapper19.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index a3531e5e..afc51ded 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -43,7 +43,16 @@ public class PlayerMovementWrapper19 implements PlayerMovementWrapper { @Override public void setPosition(Player player, Object object) { - Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> new Position()); + Position position = playerLocationMap.computeIfAbsent(player.getUniqueId(), uuid -> { + Position pos = new Position(); + Location location = player.getLocation(); + pos.x = location.getX(); + pos.y = location.getY(); + pos.z = location.getZ(); + pos.yaw = location.getYaw(); + pos.pitch = location.getPitch(); + return pos; + }); PacketPlayInFlying packetPlayInFlying = ((PacketPlayInFlying) object); EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); if (packetPlayInFlying.h) { From e2a2344c890e538fd6c27aeee0c228c5bf0f8b2d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:19:28 +0100 Subject: [PATCH 17/33] Add DragonEggCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + BauSystem_Main/src/BauSystem_de.properties | 2 + .../features/util/DragonEggCommand.java | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 695fe723..892091c3 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -920,6 +920,8 @@ SKULL_GUI_ITEM_NAME = §ePlayer Heads ANVIL_INV_NAME=Player name # StructureVoid STRUCTURE_VOID_COMMAND_HELP=§8/§estructureVoid §8-§7 Receive a StructureVoid +# Dragon Egg +DRAGON_EGG_COMMAND_HELP=§8/§edragonegg §8-§7 Receive a Dragon Egg # NightVision NIGHT_VISION_HELP=§8/§enightvision §8-§7 Toggel nightvision. NIGHT_VISION_OFF=§eNightvision deactivated diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 6dd8044b..d08d7d41 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -891,6 +891,8 @@ SKULL_GUI_ITEM_NAME = §eSpieler Köpfe ANVIL_INV_NAME=Spieler name # StructureVoid STRUCTURE_VOID_COMMAND_HELP=§8/§estructureVoid §8-§7 Erhalte ein StructureVoid +# Dragon Egg +DRAGON_EGG_COMMAND_HELP=§8/§edragonegg §8-§7 Erhalte ein Drachenei # NightVision NIGHT_VISION_HELP=§8/§enightvision §8-§7 Schalte Nightvision an oder aus. NIGHT_VISION_OFF=§eNightvision deaktiviert diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java new file mode 100644 index 00000000..b9cc7442 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/DragonEggCommand.java @@ -0,0 +1,40 @@ +/* + * 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.util; + +import de.steamwar.bausystem.SWUtils; +import de.steamwar.command.SWCommand; +import de.steamwar.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +@Linked +public class DragonEggCommand extends SWCommand { + + public DragonEggCommand() { + super("dragonegg", "enderdragon", "dragon", "egg", "enderei", "ender"); + } + + @Register(description = "DRAGON_EGG_COMMAND_HELP") + public void genericCommand(Player p) { + SWUtils.giveItemToPlayer(p, new ItemStack(Material.DRAGON_EGG, 1)); + } +} From 66b601bbfd0172f43480d674419eb9809820a9b7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:22:43 +0100 Subject: [PATCH 18/33] Fix SIOOBE for Substring Signed-off-by: yoyosource --- .../bausystem/features/script/command/string/Substring.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java index 74202855..8624cae1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/Substring.java @@ -80,7 +80,7 @@ public class Substring implements SpecialCommand { } else { result = new Value.StringValue(v1.asString().substring((int) v2.asLong())); } - } catch (ArrayIndexOutOfBoundsException e) { + } catch (ArrayIndexOutOfBoundsException | StringIndexOutOfBoundsException e) { result = new Value.StringValue(""); } scriptExecutor.getLocalVariables().putValue(resultName, result); From 36532ccd5dad67b1af3afe43e56d1d257658969b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 19 Mar 2023 14:24:42 +0100 Subject: [PATCH 19/33] Fix divide by Zero Signed-off-by: yoyosource --- .../script/expression/operator/math/DivideOperator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java index 679c69de..a4ab1c8c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/expression/operator/math/DivideOperator.java @@ -41,6 +41,9 @@ public class DivideOperator implements Operator { if (is(value, Value.StringValue.class, Value.BooleanValue.class) || is(value2, Value.StringValue.class, Value.BooleanValue.class)) { throw new IllegalArgumentException("SCRIPT_COMMAND_ARITHMETIC_DIV_ERROR"); } + if (value2.asDouble() == 0) { + return new Value.DoubleValue(Double.NaN); + } return new Value.DoubleValue(value.asDouble() / value2.asDouble()); } } From b8a27294fce996108dccdf4364b4a281a0d1121c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 4 Apr 2023 18:33:36 +0200 Subject: [PATCH 20/33] Possibly fix ScriptExecutor Signed-off-by: yoyosource --- .../features/script/ScriptExecutor.java | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 785c042b..25b29147 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -191,30 +191,6 @@ public final class ScriptExecutor { private String[] replaceExpressions(String s) { s = s.replaceAll(" +", " "); - // TODO: Remove this code as the Expression System below will replace it! - Set variables = new HashSet<>(localVariables.allVariables()); - variables.addAll(Constants.allVariables()); - variables.addAll(globalVariables.allVariables()); - - for (int i = 0; i < 3; i++) { - for (String variable : variables) { - s = s.replace("<" + variable + ">", getValue(variable)); - s = s.replace("<" + variable + ".type>", getOrItselfValue(variable).type()); - } - for (String constVariable : Constants.allVariables()) { - s = s.replace("", getConstant(constVariable)); - s = s.replace("", Constants.getConstant(constVariable, player).type()); - } - for (String localVariable : localVariables.allVariables()) { - s = s.replace("", getLocal(localVariable)); - s = s.replace("", getLocalVariables().getValue(localVariable).type()); - } - for (String globalVariable : globalVariables.allVariables()) { - s = s.replace("", getGlobal(globalVariable)); - s = s.replace("", globalVariables.getValue(globalVariable).type()); - } - } - StringBuilder result = new StringBuilder(); int depth = 0; StringBuilder st = new StringBuilder(); From cfd625c6f097fedaef90fc9750eef07e9ae81a0a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 Apr 2023 19:52:56 +0200 Subject: [PATCH 21/33] Remove sout Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tracer/record/Recorder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java index fe941f5f..8b3fcea0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/Recorder.java @@ -190,7 +190,6 @@ public class Recorder implements Listener { TraceRecorder traceRecorder = get((TNTPrimed) entity); Region region = tntTraceRecorderMap.get((TNTPrimed) entity); boolean inBuildRegion = event.blockList().stream().anyMatch(block -> region.inRegion(block.getLocation(), RegionType.BUILD, RegionExtensionType.EXTENSION)); - System.out.println(event.blockList() + " " + inBuildRegion); traceRecorder.explode((TNTPrimed) entity, inBuildRegion); tntTraceRecorderMap.remove(entity); tick(); From e60ae56b67e1c6522192816afdf51ec45d5fee1d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 Apr 2023 18:43:59 +0200 Subject: [PATCH 22/33] Fix TPSLimit 0 Signed-off-by: yoyosource --- .../features/tpslimit/FreezeUtils.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index b9a24ad1..c3c12fa9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -20,13 +20,27 @@ package de.steamwar.bausystem.features.tpslimit; import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.ChatWrapper; import lombok.Getter; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import yapion.utils.ReflectionsUtils; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; @UtilityClass public class FreezeUtils { @@ -64,10 +78,84 @@ public class FreezeUtils { if (freezeEnabled) { try { field.set(getWorldHandle.invoke(world), state); + cacheEntityPackets(state); frozen = state; } catch (IllegalAccessException e) { // Ignored; } } } + + private List packets = new ArrayList<>(); + private Set entities = new HashSet<>(); + private BukkitTask task = null; + + private Class vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); + private Reflection.FieldAccessor zeroVec3d = (Reflection.FieldAccessor) Reflection.getField(vec3dClass, vec3dClass, 0); + private Object ZERO_VEC3D = zeroVec3d.get(null); + private Class velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); + private Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); + + private Class teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); + private Class entityClass = Reflection.getClass("{nms.world.entity}.Entity"); + private Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); + + private Class craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); + private Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); + + private Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); + private Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); + + private void cacheEntityPackets(boolean state) { + if (state) { + createPackets(); + + if (task == null) { + task = new BukkitRunnable() { + @Override + public void run() { + createPackets(); + + for (Player player : Bukkit.getOnlinePlayers()) { + for (Object packet : packets) { + TinyProtocol.instance.sendPacket(player, packet); + } + } + } + }.runTaskTimer(BauSystem.getInstance(), 1, 1); + } + } else { + packets.clear(); + entities.clear(); + + if (task != null) { + task.cancel(); + task = null; + } + } + } + + private void createPackets() { + List entities = Bukkit.getWorlds().get(0).getEntities().stream() + .filter(e -> !(e instanceof Player)) + .filter(e -> !FreezeUtils.entities.contains(e)) + .collect(Collectors.toList()); + + for (Entity entity : entities) { + packets.add(teleportPacketConstructor.invoke(getHandle.invoke(entity))); + } + for (Entity entity : entities) { + packets.add(velocityPacketConstructor.invoke(entity.getEntityId(), ZERO_VEC3D)); + } + for (Entity entity : entities) { + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), noGravityDataWatcher, true)); + } + for (Entity entity : entities) { + if (!(entity instanceof TNTPrimed)) continue; + TNTPrimed tnt = (TNTPrimed) entity; + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, tnt.getFuseTicks())); + } + + FreezeUtils.entities.addAll(entities); + } } From 3c1275393fd4644e532bb7efbf8faf3eb81af41a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 14 Apr 2023 18:45:00 +0200 Subject: [PATCH 23/33] Hotfix Memory Leak Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/FreezeUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index c3c12fa9..bdb00e1a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -136,6 +136,10 @@ public class FreezeUtils { } private void createPackets() { + if (FreezeUtils.entities.stream().anyMatch(Entity::isDead)) { + entities.clear(); + packets.clear(); + } List entities = Bukkit.getWorlds().get(0).getEntities().stream() .filter(e -> !(e instanceof Player)) .filter(e -> !FreezeUtils.entities.contains(e)) From 3f5f4d7b80c26d71d19b2df3374fd3874b835505 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 11:26:09 +0200 Subject: [PATCH 24/33] Remove tnt flicker Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/FreezeUtils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index bdb00e1a..294cffd0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -157,7 +157,8 @@ public class FreezeUtils { for (Entity entity : entities) { if (!(entity instanceof TNTPrimed)) continue; TNTPrimed tnt = (TNTPrimed) entity; - packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, tnt.getFuseTicks())); + int fuse = tnt.getFuseTicks(); + packets.add(ChatWrapper.impl.getDataWatcherPacket(entity.getEntityId(), fuseDataWatcher, fuse - (fuse % 5) + 1)); } FreezeUtils.entities.addAll(entities); From e9d7c8211f78d9898cb9bc04dee8ee6b3596aa91 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 12:11:43 +0200 Subject: [PATCH 25/33] Add ShieldPrinting Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 10 ++ BauSystem_Main/src/BauSystem_de.properties | 10 ++ .../shieldprinting/ShieldPrinting.java | 101 ++++++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 110 ++++++++++++++++++ .../shieldprinting/ShieldPrintingState.java | 27 +++++ 5 files changed, 258 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 892091c3..27f1c19d 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -509,6 +509,16 @@ SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 of the server SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server +# Shield Printing +SHIELD_PRINTING_NO_REGION = §cYou are not in a region. +SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. +SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. + +SHIELD_PRINTING_START = §aThe shield printing has been started. +SHIELD_PRINTING_COPY = §aThe shield has been copied. +SHIELD_PRINTING_APPLY = §aThe shield has been applied. +SHIELD_PRINTING_STOP = §aThe shield printing has been stopped. + # Unsign Book UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index d08d7d41..a1461a99 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -502,6 +502,16 @@ SCRIPT_GUI_CONSTANT_TPS_LORE = §etps§7 vom Server SCRIPT_GUI_CONSTANT_TPS_LIMIT_NAME = §7Constant §etps_limit SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server +# Shield Printing +SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. +SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. +SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. + +SHIELD_PRINTING_START = §aShield printing wurde gestartet. +SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. +SHIELD_PRINTING_APPLY = §aSchilde wurden angewendet. +SHIELD_PRINTING_STOP = §aShield printing wurde gestoppt. + # Unsign Book UNSIGN_HELP=§8/§eunsign §8- §7Mache ein Buch beschreibbar diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java new file mode 100644 index 00000000..9cf829b5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -0,0 +1,101 @@ +/* + * 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.shieldprinting; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPistonExtendEvent; +import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.util.Vector; + +import java.util.*; + +public class ShieldPrinting implements Listener { + + private static final World WORLD = Bukkit.getWorlds().get(0); + + /** + * Vector of current position, Vector of origin + */ + private Map shieldMap = new HashMap<>(); + private Map shieldData = new HashMap<>(); + + private final Region region; + + public ShieldPrinting(Region region) { + this.region = region; + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + + public void copy() { + for (Map.Entry entry : shieldMap.entrySet()) { + shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData()); + } + } + + public void apply() { + for (Map.Entry entry : shieldData.entrySet()) { + entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue()); + } + } + + public void disable() { + BlockPistonExtendEvent.getHandlerList().unregister(this); + BlockPistonRetractEvent.getHandlerList().unregister(this); + shieldMap.clear(); + shieldData.clear(); + } + + @EventHandler + public void onBlockPistonExtend(BlockPistonExtendEvent event) { + update(event.getDirection(), event.getBlocks()); + } + + @EventHandler + public void onBlockPistonRetract(BlockPistonRetractEvent event) { + update(event.getDirection(), event.getBlocks()); + } + + private void update(BlockFace direction, List blockList) { + Set toRemove = new HashSet<>(); + Map temp = new HashMap<>(); + for (Block block : blockList) { + if (Region.getRegion(block.getLocation()) != region) continue; + Vector vector = block.getLocation().toVector(); + Vector origin = vector.clone(); + vector = vector.add(direction.getDirection()); + if (shieldMap.containsKey(origin)) { + toRemove.add(origin); + temp.put(vector, shieldMap.get(origin)); + } else { + temp.put(vector, origin); + } + } + shieldMap.keySet().removeAll(toRemove); + shieldMap.putAll(temp); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java new file mode 100644 index 00000000..a789c748 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -0,0 +1,110 @@ +/* + * 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.shieldprinting; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.region.Region; +import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeValidator; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +@Linked +public class ShieldPrintingCommand extends SWCommand { + + public ShieldPrintingCommand() { + super("shieldprinting"); + } + + private Map shieldMap = new HashMap<>(); + + @Register + public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + // BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + return; + } + ShieldPrinting shieldPrinting; + switch (shieldPrintingState) { + case START: + shieldPrinting = shieldMap.put(region, new ShieldPrinting(region)); + if (shieldPrinting != null) { + shieldPrinting.disable(); + } + BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player); + break; + case COPY: + shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.copy(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player); + break; + case APPLY: + shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.apply(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_APPLY", player); + break; + } + } + + @Register("stop") + public void stopCommand(@Validator Player player) { + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + return; + } + ShieldPrinting shieldPrinting = shieldMap.remove(region); + if (shieldPrinting == null) { + BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); + return; + } + shieldPrinting.disable(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_STOP", player); + } + + @ClassValidator(value = Player.class, local = true) + public TypeValidator validator() { + return (commandSender, player, messageSender) -> { + if (!Permission.hasPermission(player, Permission.WORLD)) { + messageSender.send("SHIELD_PRINTING_DISALLOWED", player); + return false; + } + Region region = Region.getRegion(player.getLocation()); + if (region.isGlobal()) { + messageSender.send("SHIELD_PRINTING_NO_REGION", player); + return false; + } + return true; + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java new file mode 100644 index 00000000..0f782f67 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingState.java @@ -0,0 +1,27 @@ +/* + * 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.shieldprinting; + +public enum ShieldPrintingState { + + START, + COPY, + APPLY +} From 48b2a87c96edabf4ee721ba18087c8ea47adc4a8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:53:58 +0200 Subject: [PATCH 26/33] Fix ShieldPrinting Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 + BauSystem_Main/src/BauSystem_de.properties | 2 + .../shieldprinting/ShieldPrinting.java | 46 ++++++++++++++++++- .../shieldprinting/ShieldPrintingCommand.java | 23 +++++++++- .../utils/bossbar/BossBarService.java | 6 +++ 5 files changed, 75 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 27f1c19d..a3860e34 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -513,6 +513,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 of the server SHIELD_PRINTING_NO_REGION = §cYou are not in a region. SHIELD_PRINTING_NOT_RUNNING = §cThe shield printing is not running. SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. +SHIELD_PRINTING_BOSSBAR = §fMovements: {0} +SHIELD_PRINTING_BOSSBAR_COPIED = §fMovements: {0} Copied: {1} SHIELD_PRINTING_START = §aThe shield printing has been started. SHIELD_PRINTING_COPY = §aThe shield has been copied. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a1461a99..9689be29 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -506,6 +506,8 @@ SCRIPT_GUI_CONSTANT_TPS_LIMIT_LORE = §etps_limit§7 vom Server SHIELD_PRINTING_NO_REGION = §cDu bist in keiner Region. SHIELD_PRINTING_NOT_RUNNING = §cShield printing ist nicht aktiv. SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. +SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0} +SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1} SHIELD_PRINTING_START = §aShield printing wurde gestartet. SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 9cf829b5..3ddefdc2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -21,15 +21,24 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; +import de.steamwar.bausystem.utils.bossbar.BossBarService; +import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; +import org.bukkit.boss.BarColor; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; import java.util.*; @@ -49,12 +58,14 @@ public class ShieldPrinting implements Listener { public ShieldPrinting(Region region) { this.region = region; Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + updateBossbars(); } public void copy() { for (Map.Entry entry : shieldMap.entrySet()) { shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData()); } + updateBossbars(); } public void apply() { @@ -64,10 +75,13 @@ public class ShieldPrinting implements Listener { } public void disable() { - BlockPistonExtendEvent.getHandlerList().unregister(this); - BlockPistonRetractEvent.getHandlerList().unregister(this); + HandlerList.unregisterAll(this); shieldMap.clear(); shieldData.clear(); + + for (Player player : Bukkit.getOnlinePlayers()) { + BossBarService.instance.remove(player, region, "shieldprinting"); + } } @EventHandler @@ -97,5 +111,33 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + updateBossbars(); + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) return; + if (event.getItem() == null) return; + if (Region.getRegion(event.getClickedBlock().getLocation()) != region) return; + Vector vector = event.getClickedBlock().getLocation().toVector(); + if (!shieldMap.containsKey(vector)) return; + event.getClickedBlock().setType(Material.AIR); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + updateBossbar(event.getPlayer()); + } + + private void updateBossbars() { + for (Player player : Bukkit.getOnlinePlayers()) { + updateBossbar(player); + } + } + + private void updateBossbar(Player player) { + BauSystemBossbar bossbar = BossBarService.instance.get(player, region, "shieldprinting"); + bossbar.setColor(BarColor.YELLOW); + bossbar.setTitle(BauSystem.MESSAGE.parse(shieldData.isEmpty() ? "SHIELD_PRINTING_BOSSBAR" : "SHIELD_PRINTING_BOSSBAR_COPIED", player, shieldMap.size(), shieldData.size())); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index a789c748..b2f31dbd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -26,12 +26,15 @@ import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEvent; import java.util.HashMap; import java.util.Map; @Linked -public class ShieldPrintingCommand extends SWCommand { +public class ShieldPrintingCommand extends SWCommand implements Listener { public ShieldPrintingCommand() { super("shieldprinting"); @@ -43,7 +46,7 @@ public class ShieldPrintingCommand extends SWCommand { public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { Region region = Region.getRegion(player.getLocation()); if (region.isGlobal()) { - // BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); + BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } ShieldPrinting shieldPrinting; @@ -107,4 +110,20 @@ public class ShieldPrintingCommand extends SWCommand { return true; }; } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getClickedBlock() == null) { + return; + } + Region region = Region.getRegion(event.getClickedBlock().getLocation()); + if (region.isGlobal()) { + return; + } + ShieldPrinting shieldPrinting = shieldMap.get(region); + if (shieldPrinting == null) { + return; + } + shieldPrinting.onPlayerInteract(event); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java index 6c7d636d..e6ea2c16 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/BossBarService.java @@ -37,6 +37,12 @@ import java.util.Map; @Linked public class BossBarService implements Listener { + public static BossBarService instance; + + public BossBarService() { + instance = this; + } + private final Map>> playerBossBars = new HashMap<>(); public synchronized BauSystemBossbar get(Player player, Region region, String key) { From 61895377d1f1ed09016993e778be21c18ac18dac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 16:56:05 +0200 Subject: [PATCH 27/33] Hotfix RegionedBossbar Signed-off-by: yoyosource --- .../steamwar/bausystem/utils/bossbar/RegionedBossbar.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java index 4d922143..5fb1cc99 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/bossbar/RegionedBossbar.java @@ -135,8 +135,10 @@ public class RegionedBossbar implements BauSystemBossbar, Listener { @Override public void cleanup() { - bossBar.removeAll(); - bossBar = null; + if (bossBar != null) { + bossBar.removeAll(); + bossBar = null; + } region = null; player = null; From a15e5aaf50cdb67281c6fc6162f1d005e867db9c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:07:40 +0200 Subject: [PATCH 28/33] Remove some memory Signed-off-by: yoyosource --- .../features/shieldprinting/ShieldPrinting.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 3ddefdc2..0ad8d710 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -111,6 +111,15 @@ public class ShieldPrinting implements Listener { } shieldMap.keySet().removeAll(toRemove); shieldMap.putAll(temp); + + toRemove.clear(); + for (Map.Entry entry : shieldMap.entrySet()) { + if (entry.getKey().equals(entry.getValue())) { + toRemove.add(entry.getKey()); + } + } + shieldMap.keySet().removeAll(toRemove); + updateBossbars(); } From f9919925283b9da1dd9054e43fb69534f42dbc26 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 16 Apr 2023 17:39:51 +0200 Subject: [PATCH 29/33] Fix stoplag for ShieldPrinting.apply Signed-off-by: yoyosource --- .../bausystem/features/shieldprinting/ShieldPrinting.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 0ad8d710..e1585fbb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -70,7 +70,7 @@ public class ShieldPrinting implements Listener { public void apply() { for (Map.Entry entry : shieldData.entrySet()) { - entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue()); + entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue(), false); } } From ad4a054a6385bfefd05ed1cfcb0c540028b60fdb Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:46:58 +0200 Subject: [PATCH 30/33] Added new Buttons to Loader Detonator not nescessary since detection works differently --- .../steamwar/bausystem/features/loader/LoaderButton.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index e5e74171..6825a247 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -46,6 +46,9 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; + case CRIMSON_BUTTON: + case MANGROVE_BUTTON: + case WARPED_BUTTON: case ACACIA_BUTTON: case BIRCH_BUTTON: case DARK_OAK_BUTTON: @@ -53,8 +56,13 @@ public enum LoaderButton { case OAK_BUTTON: case SPRUCE_BUTTON: return LoaderButton.WOOD_BUTTON; + case POLISHED_BLACKSTONE_BUTTON: case STONE_BUTTON: return LoaderButton.STONE_BUTTON; + case CRIMSON_PRESSURE_PLATE: + case MANGROVE_PRESSURE_PLATE: + case WARPED_PRESSURE_PLATE: + // case POLISHED_BLACKSTONE_PRESSURE_PLATE: case ACACIA_PRESSURE_PLATE: case BIRCH_PRESSURE_PLATE: case DARK_OAK_PRESSURE_PLATE: From 377bcb92fb845a29f9ce9698064c86bdbd4e97b0 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Tue, 18 Apr 2023 11:55:30 +0200 Subject: [PATCH 31/33] Generalized LoaderButton assignment --- .../features/loader/LoaderButton.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java index 6825a247..4a1d5159 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderButton.java @@ -24,6 +24,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import org.bukkit.block.Block; + @AllArgsConstructor @RequiredArgsConstructor @Getter @@ -46,42 +47,25 @@ public enum LoaderButton { switch (block.getType()) { case LEVER: return LoaderButton.SWITCH; - case CRIMSON_BUTTON: - case MANGROVE_BUTTON: - case WARPED_BUTTON: - case ACACIA_BUTTON: - case BIRCH_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case OAK_BUTTON: - case SPRUCE_BUTTON: - return LoaderButton.WOOD_BUTTON; - case POLISHED_BLACKSTONE_BUTTON: - case STONE_BUTTON: - return LoaderButton.STONE_BUTTON; - case CRIMSON_PRESSURE_PLATE: - case MANGROVE_PRESSURE_PLATE: - case WARPED_PRESSURE_PLATE: - // case POLISHED_BLACKSTONE_PRESSURE_PLATE: - case ACACIA_PRESSURE_PLATE: - case BIRCH_PRESSURE_PLATE: - case DARK_OAK_PRESSURE_PLATE: - case JUNGLE_PRESSURE_PLATE: - case OAK_PRESSURE_PLATE: - case SPRUCE_PRESSURE_PLATE: - case STONE_PRESSURE_PLATE: - return LoaderButton.PRESSURE_PLATE; - case HEAVY_WEIGHTED_PRESSURE_PLATE: - case LIGHT_WEIGHTED_PRESSURE_PLATE: - return LoaderButton.WEIGHTED_PRESSURE_PLATE; case TRIPWIRE: return LoaderButton.TRIPWIRE; case NOTE_BLOCK: return LoaderButton.NOTEBLOCK; case DAYLIGHT_DETECTOR: return LoaderButton.DAYLIGHTSENSOR; + case HEAVY_WEIGHTED_PRESSURE_PLATE: + case LIGHT_WEIGHTED_PRESSURE_PLATE: + return LoaderButton.WEIGHTED_PRESSURE_PLATE; default: - return LoaderButton.INVALID; + if (block.getType().name().contains("STONE_BUTTON")) { + return LoaderButton.STONE_BUTTON; + } else if (block.getType().name().contains("BUTTON")) { + return LoaderButton.WOOD_BUTTON; + } else if (block.getType().name().contains("PRESSURE_PLATE")) { + return LoaderButton.PRESSURE_PLATE; + } else { + return LoaderButton.INVALID; + } } } } From 3786f1e2bb7e5d03a09d3d97d171eaa7fc1c83dc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 13:38:00 +0200 Subject: [PATCH 32/33] Add sand shield printing tracking Signed-off-by: yoyosource --- .../shieldprinting/ShieldPrinting.java | 43 +++++++++++++++++++ .../shieldprinting/ShieldPrintingCommand.java | 12 +++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index e1585fbb..ea3b0fbc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -25,18 +25,27 @@ import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.bausystem.utils.bossbar.RegionedBossbar; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.boss.BarColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.EntityBlockFormEvent; +import org.bukkit.event.entity.EntityAirChangeEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; @@ -47,6 +56,17 @@ public class ShieldPrinting implements Listener { private static final World WORLD = Bukkit.getWorlds().get(0); + static { + Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> { + shieldPrinting.fallingBlocks.replaceAll((entity, location) -> { + if (entity.isDead()) return null; + return location; + }); + }); + }, 1, 1); + } + /** * Vector of current position, Vector of origin */ @@ -123,6 +143,29 @@ public class ShieldPrinting implements Listener { updateBossbars(); } + private Map fallingBlocks = new HashMap<>(); + + @EventHandler + public void onEntitySpawn(EntitySpawnEvent event) { + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getLocation()) != region) return; + fallingBlocks.put(event.getEntity(), event.getLocation().getBlock().getLocation()); + } + + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + if (!event.getBlock().getType().isAir()) return; + if (event.getEntityType() != EntityType.FALLING_BLOCK) return; + if (Region.getRegion(event.getBlock().getLocation()) != region) return; + Location origin = fallingBlocks.remove(event.getEntity()); + if (origin == null) return; + Location destination = event.getBlock().getLocation(); + Vector originOrigin = shieldMap.remove(origin.toVector()); + shieldMap.put(destination.toVector(), originOrigin != null ? originOrigin : origin.toVector()); + + updateBossbars(); + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getClickedBlock() == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index b2f31dbd..a72443f5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -40,7 +40,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { super("shieldprinting"); } - private Map shieldMap = new HashMap<>(); + static final Map SHIELD_PRINTING_MAP = new HashMap<>(); @Register public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) { @@ -52,14 +52,14 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { ShieldPrinting shieldPrinting; switch (shieldPrintingState) { case START: - shieldPrinting = shieldMap.put(region, new ShieldPrinting(region)); + shieldPrinting = SHIELD_PRINTING_MAP.put(region, new ShieldPrinting(region)); if (shieldPrinting != null) { shieldPrinting.disable(); } BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player); break; case COPY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -68,7 +68,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player); break; case APPLY: - shieldPrinting = shieldMap.get(region); + shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -86,7 +86,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player); return; } - ShieldPrinting shieldPrinting = shieldMap.remove(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.remove(region); if (shieldPrinting == null) { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; @@ -120,7 +120,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { if (region.isGlobal()) { return; } - ShieldPrinting shieldPrinting = shieldMap.get(region); + ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.get(region); if (shieldPrinting == null) { return; } From 37b76eff30ae157924c4b03fa4b2c23795faaa3c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 19 Apr 2023 18:08:36 +0200 Subject: [PATCH 33/33] Add ShowModeParameterType.TICKS_SINCE_START Signed-off-by: yoyosource --- .../bausystem/features/tracer/show/EntityShowMode.java | 2 ++ .../bausystem/features/tracer/show/ShowModeParameter.java | 5 +++++ .../features/tracer/show/ShowModeParameterType.java | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java index bfcd15e5..6f61a08e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -202,6 +202,8 @@ public class EntityShowMode implements ShowMode { entity.setDisplayName(fuseTicks + ""); } else if (showModeParameter.isCount()) { entity.setDisplayName(new HashSet<>(records).size() + ""); + } else if (showModeParameter.isTicksSinceStart()) { + entity.setDisplayName((80 - fuseTicks) + tntPosition.getRecord().getOffset() + ""); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java index d8e3a75f..4babe506 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameter.java @@ -31,6 +31,7 @@ public class ShowModeParameter { private boolean ticks = false; private boolean count = false; private boolean buildDestroyOnly = false; + private boolean ticksSinceStart = false; public void enableWater() { this.water = true; @@ -63,4 +64,8 @@ public class ShowModeParameter { public void enableBuildDestroyOnly() { this.buildDestroyOnly = true; } + + public void enableTicksSinceStart() { + this.ticksSinceStart = true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java index 3d28237d..a80a3633 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/ShowModeParameterType.java @@ -38,9 +38,10 @@ public enum ShowModeParameterType { }, Arrays.asList("-advanced", "-a"), "INTERPOLATE_Y", "INTERPOLATE_XZ"), SOURCE(ShowModeParameter::enableSourceOnly, Arrays.asList("-source", "-sourceonly", "-ignite"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), EXPLODE(ShowModeParameter::enableExplodeOnly, Arrays.asList("-explode", "-explodeonly"), "TICKS", "ADVANCED", "INTERPOLATE_Y", "INTERPOLATE_XZ", "WATER"), - TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT"), - COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "COUNT"), - BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"); + TICKS(ShowModeParameter::enableTicks, Arrays.asList("-ticks", "-t"), "EXPLODE", "SOURCE", "COUNT", "TICKS_SINCE_START"), + COUNT(ShowModeParameter::enableCount, Arrays.asList("-count", "-c"), "TICKS", "TICKS_SINCE_START"), + BUILD_DESTROY_ONLY(ShowModeParameter::enableBuildDestroyOnly, Arrays.asList("-builddestroy", "-builddestoryonly"), "WATER"), + TICKS_SINCE_START(ShowModeParameter::enableTicksSinceStart, Arrays.asList("-tickssincestart", "-tss"), "TICKS", "COUNT"); @Getter private final Consumer showModeParameterConsumer;