DepthCounter now Highlights
Dieser Commit ist enthalten in:
Ursprung
2a0dbaa049
Commit
7a1cb2a865
@ -30,5 +30,7 @@ public enum CountMode {
|
||||
Y,
|
||||
Z;
|
||||
|
||||
public static final Set<CountMode> ALL = new HashSet<>(Arrays.asList(values()));
|
||||
public static Set<CountMode> ALL() {
|
||||
return new HashSet<>(Arrays.asList(values()));
|
||||
}
|
||||
}
|
@ -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<Integer> 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<Integer> 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()));
|
||||
|
@ -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 + ".");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren