From 6a3f53a1c1499111512a70dae1f01f5444c47d9f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 24 Sep 2022 20:04:26 +0200 Subject: [PATCH] Add eta to laufbau states Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- BauSystem_Main/src/BauSystem_de.properties | 2 +- .../bausystem/features/slaves/laufbau/Laufbau.java | 2 +- .../laufbau/states/CreatingInnerBlocksState.java | 13 +++++++------ .../laufbau/states/CreatingOuterBlocksState.java | 4 +++- .../slaves/laufbau/states/ExpandingTracesState.java | 4 +++- .../slaves/laufbau/states/FilteringTracesState.java | 4 +++- .../slaves/laufbau/states/LaufbauState.java | 9 +++++++++ .../laufbau/states/ProcessingTracesState.java | 4 +++- .../laufbau/states/ShrinkingOuterPointsState.java | 4 +++- .../slaves/laufbau/states/SplittingPointsState.java | 4 +++- 11 files changed, 37 insertions(+), 15 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 31f3136e..cb099247 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -1116,7 +1116,7 @@ LAUFBAU_STATE_SPLITTING_POINTS = Splitting points LAUFBAU_STATE_SHRINKING_POINTS = Shrinking points LAUFBAU_STATE_CREATING_INNER_BLOCKS = Creating inner blocks LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Creating outer blocks -LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} +LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} §7Time left§8: §e{3} LAUFBAU_DONE = §aDone LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 612ebd7c..5382d787 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -1095,7 +1095,7 @@ LAUFBAU_STATE_SPLITTING_POINTS = Punkte trennen LAUFBAU_STATE_SHRINKING_POINTS = Punkte ausdünnen LAUFBAU_STATE_CREATING_INNER_BLOCKS = Innenraum füllen LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Mantel bauen -LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} +LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} §7Übrige Zeit §8: §e{3} LAUFBAU_DONE = §aZuende gebaut LAUFBAU_SETTINGS_GUI_NAME = §eLaufbau diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java index 5a535c4c..6c22c4aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/Laufbau.java @@ -116,7 +116,7 @@ public class Laufbau { return; } if (shrinkingOuterPointsState != null) { - creatingInnerBlocksState = new CreatingInnerBlocksState(splittingPointsState.getInnerPoints(), world, processingTracesState.getCuboidList(), splittingPointsState.getIntersectedCuboid(), editSession, elements, preferingBlastResistance); + creatingInnerBlocksState = new CreatingInnerBlocksState(splittingPointsState.getInnerPoints(), world, splittingPointsState.getIntersectedCuboid(), editSession, elements); return; } if (splittingPointsState != null) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java index 67a1fb9b..6e6b3be1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingInnerBlocksState.java @@ -30,36 +30,37 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; +import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class CreatingInnerBlocksState implements LaufbauState { + private long start = System.currentTimeMillis(); + private List innerBlocks; private int index = 0; private World world; - private List cuboidList; private Map> intersectedCuboid; private EditSession editSession; private List elements; - private boolean preferingBlastResistance; - public CreatingInnerBlocksState(List innerBlocks, World world, List cuboidList, Map> intersectedCuboid, EditSession editSession, List elements, boolean preferingBlastResistance) { + public CreatingInnerBlocksState(List innerBlocks, World world, Map> intersectedCuboid, EditSession editSession, List elements) { this.innerBlocks = innerBlocks; this.world = world; - this.cuboidList = cuboidList; this.intersectedCuboid = intersectedCuboid; this.editSession = editSession; this.elements = elements; - this.preferingBlastResistance = preferingBlastResistance; } @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_INNER_BLOCKS", p), index, innerBlocks.size()); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_INNER_BLOCKS", p), index, innerBlocks.size(), eta(p, start, index, innerBlocks.size())); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingOuterBlocksState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingOuterBlocksState.java index 6c97b5f8..991ca014 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingOuterBlocksState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/CreatingOuterBlocksState.java @@ -41,6 +41,8 @@ public class CreatingOuterBlocksState implements LaufbauState { SHELL = BlockTypes.get("minecraft:end_stone").getDefaultState().toBaseBlock(); } + private long start = System.currentTimeMillis(); + private List outerBlocks; private int index = 0; @@ -55,7 +57,7 @@ public class CreatingOuterBlocksState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_OUTER_BLOCKS", p), index, outerBlocks.size()); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_OUTER_BLOCKS", p), index, outerBlocks.size(), eta(p, start, index, outerBlocks.size())); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java index 595b828b..33a9004d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ExpandingTracesState.java @@ -36,6 +36,8 @@ import java.util.function.BiPredicate; public class ExpandingTracesState implements LaufbauState { + private long start = System.currentTimeMillis(); + private List cuboidList; private int totalCuboids; @@ -54,7 +56,7 @@ public class ExpandingTracesState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_EXPANDING_TRACES", p), totalCuboids - cuboidList.size(), totalCuboids); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_EXPANDING_TRACES", p), totalCuboids - cuboidList.size(), totalCuboids, eta(p, start, totalCuboids - cuboidList.size(), totalCuboids)); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/FilteringTracesState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/FilteringTracesState.java index ac4e8de6..55e4a0fa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/FilteringTracesState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/FilteringTracesState.java @@ -35,6 +35,8 @@ import java.util.function.BiPredicate; public class FilteringTracesState implements LaufbauState { + private long start = System.currentTimeMillis(); + private World world; private BiPredicate inRegionCheck; @@ -55,7 +57,7 @@ public class FilteringTracesState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_FILTERING_TRACES", p), totalRecord - recordList.size(), totalRecord); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_FILTERING_TRACES", p), totalRecord - recordList.size(), totalRecord, eta(p, start, totalRecord - recordList.size(), totalRecord)); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java index 4d6b6e89..3401914d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/LaufbauState.java @@ -19,8 +19,13 @@ package de.steamwar.bausystem.features.slaves.laufbau.states; +import de.steamwar.bausystem.BauSystem; import org.bukkit.entity.Player; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.Date; + public interface LaufbauState { String actionBarMessage(Player p); @@ -28,4 +33,8 @@ public interface LaufbauState { boolean hasNext(); void next(); + + default String eta(Player p, long start, int done, int total) { + return new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Date.from(Instant.ofEpochMilli((System.currentTimeMillis() - start) / done * total))); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java index 5748907c..ead42c62 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ProcessingTracesState.java @@ -31,6 +31,8 @@ import java.util.List; public class ProcessingTracesState implements LaufbauState { + private long start = System.currentTimeMillis(); + private int totalTNTPositions; private List tntPositionList; @@ -44,7 +46,7 @@ public class ProcessingTracesState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTNTPositions - tntPositionList.size(), totalTNTPositions); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTNTPositions - tntPositionList.size(), totalTNTPositions, eta(p, start, totalTNTPositions - tntPositionList.size(), totalTNTPositions)); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ShrinkingOuterPointsState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ShrinkingOuterPointsState.java index 8ee9ed0a..487b9991 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ShrinkingOuterPointsState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/ShrinkingOuterPointsState.java @@ -29,6 +29,8 @@ import java.util.List; public class ShrinkingOuterPointsState implements LaufbauState { + private long start = System.currentTimeMillis(); + private List outerPoints; private List innerPoints; private int index = 0; @@ -43,7 +45,7 @@ public class ShrinkingOuterPointsState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SHRINKING_POINTS", p), index, outerPoints.size()); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SHRINKING_POINTS", p), index, outerPoints.size(), eta(p, start, index, outerPoints.size())); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/SplittingPointsState.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/SplittingPointsState.java index ae60172b..2a61dd44 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/SplittingPointsState.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/laufbau/states/SplittingPointsState.java @@ -32,6 +32,8 @@ public class SplittingPointsState implements LaufbauState { private static final Cuboid ONE = new Cuboid(0, 0, 0, 1, 1, 1); private static final Cuboid ABOVE_HALF = new Cuboid(0, 1, 0, 1, 0.5, 1); + private long start = System.currentTimeMillis(); + private List blocks; private int totalBlocks; private List cuboidList; @@ -53,7 +55,7 @@ public class SplittingPointsState implements LaufbauState { @Override public String actionBarMessage(Player p) { - return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SPLITTING_POINTS", p), totalBlocks - blocks.size(), totalBlocks); + return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SPLITTING_POINTS", p), totalBlocks - blocks.size(), totalBlocks, eta(p, start, totalBlocks - blocks.size(), totalBlocks)); } @Override