From d437b450e5ce826b9559a0fd6605e3308dcf969a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 5 Oct 2021 11:38:49 +0200 Subject: [PATCH] Optimize Panzern Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- .../bausystem/features/panzern/Panzern.java | 11 ++++++----- .../bausystem/features/panzern/PanzernCommand.java | 13 +++++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 39e56d5d..d35f51de 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -527,5 +527,5 @@ PANZERN_PREPARE3 = §73. Schildtechnik sollte explizit eingeschlossen sein. PANZERN_PREPARE4 = §74. Innerhalb der zu panzernden Region zu stehen, beim Befehlausführen kann das Panzern verbessern. PANZERN_NO_PERM = §cDu darfst hier nicht das Panzern System verwenden PANZERN_NO_WORLDEDIT = §cDu hast keine WorldEdit Selection -PANZERN_PROGRESS = §e{0} §7Blöcke übrig +PANZERN_PROGRESS = §e{0} §7Blöcke übrig, §e{1} §7Blöcke pro Sekunde, §e{2} §7Block Delta PANZERN_DONE = §aZuende gepanzert \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/Panzern.java b/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/Panzern.java index 9ce1abe7..57c93263 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/Panzern.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/Panzern.java @@ -24,6 +24,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.util.Vector; import java.util.*; @@ -37,8 +38,8 @@ public class Panzern { private static final BlockFace[] BLOCK_FACES = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}; - private Set current = new HashSet<>(); - private Set emptyBlocks = new HashSet<>(); + private Set current = new HashSet<>(); // Potenzielle geschwindigkeit durch `LinkedHashSet<>();` möchte aber lieber ein HashSet nehmen, weil dieses besser für mein Anwendungsfall ist + private Set emptyBlocks = new HashSet<>(); private World world; private Location pos1; @@ -91,7 +92,7 @@ public class Panzern { switch (panzernResult) { case EMPTY: - emptyBlocks.add(currentBlock.getLocation()); + emptyBlocks.add(currentBlock.getLocation().toVector()); return; case SLAB: currentBlock.setType(slabMaterial); @@ -104,12 +105,12 @@ public class Panzern { currentBlock.setType(Material.JUKEBOX); break; default: - emptyBlocks.add(currentBlock.getLocation()); + emptyBlocks.add(currentBlock.getLocation().toVector()); break; } adjacent.forEach((blockFace, temp) -> { - if (temp.getType().isAir() && !emptyBlocks.contains(temp.getLocation())) { + if (temp.getType().isAir() && !emptyBlocks.contains(temp.getLocation().toVector())) { current.add(temp.getLocation()); } }); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/PanzernCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/PanzernCommand.java index e961aedd..b5e74915 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/PanzernCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/panzern/PanzernCommand.java @@ -76,15 +76,24 @@ public class PanzernCommand extends SWCommand { new BukkitRunnable() { @Override public void run() { - SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("PANZERN_PROGRESS", player, panzern.blocksLeft())); - for (int i = 0; i < 1000; i++) { + int blockLeft = panzern.blocksLeft(); + long totalTime = 0; + long blocks = 0; + while (true) { if (!panzern.hasNext()) { BauSystem.MESSAGE.send("PANZERN_DONE", player); cancel(); return; } + long time = System.currentTimeMillis(); panzern.next(); + totalTime += System.currentTimeMillis() - time; + blocks++; + if (totalTime > 40) { + break; + } } + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("PANZERN_PROGRESS", player, panzern.blocksLeft(), blocks * 20, panzern.blocksLeft() - blockLeft)); } }.runTaskTimer(BauSystem.getInstance(), 1, 1); }