SteamWar/BauSystem2.0
Archiviert
12
0

Fixing code duplication

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-05-27 22:52:42 +02:00
Ursprung 8f26a96baa
Commit b7ad176e51

Datei anzeigen

@ -80,39 +80,27 @@ public class Loadtimer implements Listener {
String sec = new DecimalFormat("#.#").format(timeSec); String sec = new DecimalFormat("#.#").format(timeSec);
AtomicInteger tnt = new AtomicInteger(); AtomicInteger tnt = new AtomicInteger();
tntPlaced.forEach((player, integer) -> tnt.addAndGet(integer)); tntPlaced.forEach((player, integer) -> tnt.addAndGet(integer));
Bukkit.getOnlinePlayers().forEach(player -> { sendBarToRegion(BarStyle.SEGMENTED_20, "LOADTIMER_BOSSBAR", BarColor.GREEN, (timeSinceStart % 20d) / 20, timeSinceStart, timeSinceHalf, sec, tnt);
if (Region.getRegion(player.getLocation()).equals(region)) {
BossBar bar = getOrDefault(player);
bar.setTitle(BauSystem.MESSAGE.parse("LOADTIMER_BOSSBAR", player, timeSinceStart, timeSinceHalf, sec, tnt));
bar.setProgress((timeSinceStart % 20d) / 20);
bar.setColor(BarColor.GREEN);
bar.setStyle(BarStyle.SEGMENTED_20);
}
});
} else if (stage == Stage.WAITING) { } else if (stage == Stage.WAITING) {
Bukkit.getOnlinePlayers().forEach(player -> { sendBarToRegion(BarStyle.SOLID, "LOADTIMER_WAITING", BarColor.GREEN, 1);
if (Region.getRegion(player.getLocation()).equals(region)) {
BossBar bar = getOrDefault(player);
bar.setStyle(BarStyle.SOLID);
bar.setTitle(BauSystem.MESSAGE.parse("LOADTIMER_WAITING", player));
bar.setColor(BarColor.GREEN);
bar.setProgress(1);
}
});
} else if (stage == Stage.ACTIVATED || stage == Stage.IGNITION) { } else if (stage == Stage.ACTIVATED || stage == Stage.IGNITION) {
Bukkit.getOnlinePlayers().forEach(player -> { sendBarToRegion(BarStyle.SOLID, stage == Stage.ACTIVATED ? "LOADTIMER_ACTIVATED" : "LOADTIMER_IGNITION", BarColor.YELLOW, 1);
if (Region.getRegion(player.getLocation()).equals(region)) {
BossBar bar = getOrDefault(player);
bar.setStyle(BarStyle.SOLID);
bar.setTitle(BauSystem.MESSAGE.parse(stage == Stage.ACTIVATED ? "LOADTIMER_ACTIVATED" : "LOADTIMER_IGNITION", player));
bar.setColor(BarColor.YELLOW);
bar.setProgress(1);
}
});
} }
}, 1, 1); }, 1, 1);
} }
private void sendBarToRegion(BarStyle style, String message, BarColor color, double progress, Object... objects) {
Bukkit.getOnlinePlayers().forEach(player -> {
if (Region.getRegion(player.getLocation()).equals(region)) {
BossBar bar = getOrDefault(player);
bar.setStyle(style);
bar.setTitle(BauSystem.MESSAGE.parse(message, player, objects));
bar.setColor(color);
bar.setProgress(progress);
}
});
}
public static boolean hasTimer(Region r) { public static boolean hasTimer(Region r) {
return timers.containsKey(r); return timers.containsKey(r);
} }