From 7a1cb2a865094bcd44c0946830c990f7a6e6cf0a Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 1 May 2021 18:20:56 +0200 Subject: [PATCH] DepthCounter now Highlights --- .../testblock/depthcounter/CountMode.java | 4 +- .../testblock/depthcounter/DepthCounter.java | 60 +++++++++++++++++++ .../depthcounter/DepthCounterCommand.java | 2 +- .../depthcounter/DepthCounterListener.java | 10 +--- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java index 7971b63a..1dfb795b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/CountMode.java @@ -30,5 +30,7 @@ public enum CountMode { Y, Z; - public static final Set ALL = new HashSet<>(Arrays.asList(values())); + public static Set ALL() { + return new HashSet<>(Arrays.asList(values())); + } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java index 8b65a849..40470d0a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.testblock.depthcounter; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Region; @@ -101,6 +102,65 @@ public class DepthCounter { return !getModes(p).isEmpty(); } + public int getMax(int... values) { + return Arrays.stream(values).max().orElse(0); + } + + public int getMax(Set values) { + return values.stream().max(Integer::compare).orElse(0); + } + + public String getMessage(Player player, int x, int y, int z) { + final boolean xActive = DepthCounter.isActive(player, CountMode.X); + final boolean yActive = DepthCounter.isActive(player, CountMode.Y); + final boolean zActive = DepthCounter.isActive(player, CountMode.Z); + + if (!xActive && !yActive && !zActive) { + return null; + } + + final StringBuilder result = new StringBuilder(BauSystem.PREFIX); + + final Set dimensions = new HashSet<>(); + if (xActive) { + dimensions.add(x); + } + if (yActive) { + dimensions.add(y); + } + if (zActive) { + dimensions.add(z); + } + + int max = getMax(dimensions); + + if (xActive) { + if (x == max) { + result.append(ColorConfig.HIGHLIGHT).append("X: ").append(x).append(ColorConfig.BASE).append(" "); + } else { + result.append("X: ").append(x).append(" "); + } + } + + if (yActive) { + if (y == max) { + result.append(ColorConfig.HIGHLIGHT).append("Y: ").append(y).append(ColorConfig.BASE).append(" "); + } else { + result.append("Y: ").append(y).append(" "); + } + } + + if (zActive) { + if (z == max) { + result.append(ColorConfig.HIGHLIGHT).append("Z: ").append(z).append(ColorConfig.BASE).append(" "); + } else { + result.append("Z: ").append(z).append(" "); + } + } + + return result.toString(); + } + public void compute(Vector v1, Vector v2, DoubleBinaryOperator function) { v1.setX(function.applyAsDouble(v1.getX(), v2.getX())); v1.setY(function.applyAsDouble(v1.getY(), v2.getY())); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java index 1775657a..d1d9abd7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterCommand.java @@ -47,7 +47,7 @@ public class DepthCounterCommand extends SWCommand { @Register("enable") public void enableCommand(Player p) { - DepthCounter.setModes(p, CountMode.ALL); + DepthCounter.setModes(p, CountMode.ALL()); p.sendMessage(BauSystem.PREFIX + "Du hast den Tiefenzähler aktiviert."); p.sendMessage(BauSystem.PREFIX + "Aktive Zählmodi: " + ColorConfig.HIGHLIGHT + DepthCounter.getModes(p) + ColorConfig.BASE + "."); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java index 284cad75..c6276fd4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounterListener.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.features.testblock.depthcounter; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Region; @@ -76,12 +75,9 @@ public class DepthCounterListener implements Listener { dimensions.setY(Math.abs(dimensions.getY())); dimensions.setZ(Math.abs(dimensions.getZ())); - RegionUtils.message(region, player -> !DepthCounter.hasModes(player) ? null : (BauSystem.PREFIX - + (DepthCounter.isActive(player, CountMode.X) ? "X: " + dimensions.getBlockX() + " " : "") - + (DepthCounter.isActive(player, CountMode.Y) ? "Y: " + dimensions.getBlockY() + " " : "") - + (DepthCounter.isActive(player, CountMode.Z) ? "Z: " + dimensions.getBlockZ() + " " : ""))); + RegionUtils.message(region, player -> DepthCounter.getMessage(player, dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ())); DepthCounter.current.remove(region); - }, 10); + }, 20); } } @@ -92,6 +88,6 @@ public class DepthCounterListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { - DepthCounter.setModes(event.getPlayer(), CountMode.ALL); + DepthCounter.setModes(event.getPlayer(), CountMode.ALL()); } } \ No newline at end of file