From 043b3860a0a350066dcdc450289894876bc30a97 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 14:30:29 +0200 Subject: [PATCH 1/2] Add better Scoreboard building Signed-off-by: yoyosource --- .../types/ScoreboardElement_GENERIC.java | 40 +++++ .../loader/LoaderScoreboardElement.java | 47 ++++++ .../features/region/FireListener.java | 20 ++- .../features/region/FreezeListener.java | 20 ++- .../features/region/ProtectListener.java | 21 ++- .../region/RegionScoreboardElement.java | 47 ++++++ .../features/region/TNTListener.java | 20 ++- .../features/techhider/TechHiderCommand.java | 29 ++-- .../tpslimit/TPSScoreboardElement.java | 68 ++++++++ .../tracer/TraceScoreboardElement.java | 53 ++++++ .../features/world/BauScoreboard.java | 153 +++++------------- .../bausystem/features/xray/XrayCommand.java | 29 ++-- .../steamwar/bausystem/region/flags/Flag.java | 16 +- .../bausystem/utils/ScoreboardElement.java | 37 +++++ .../utils/TimeScoreboardElement.java | 47 ++++++ 15 files changed, 498 insertions(+), 149 deletions(-) create mode 100644 BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java diff --git a/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java new file mode 100644 index 00000000..01e29833 --- /dev/null +++ b/BauSystem_Linkage/src/de/steamwar/linkage/types/ScoreboardElement_GENERIC.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.linkage.types; + +import de.steamwar.linkage.LinkageType; +import de.steamwar.linkage.plan.BuildPlan; +import de.steamwar.linkage.plan.MethodBuilder; + +import javax.lang.model.element.TypeElement; + +public class ScoreboardElement_GENERIC implements LinkageType { + + @Override + public String method() { + return "link"; + } + + @Override + public void generateCode(BuildPlan buildPlan, MethodBuilder methodBuilder, String s, TypeElement typeElement) { + buildPlan.addImport("de.steamwar.bausystem.features.world.BauScoreboard"); + methodBuilder.addLine("BauScoreboard.ELEMENTS.add(" + s + ");"); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java new file mode 100644 index 00000000..847ed59b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.loader; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class LoaderScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + Loader loader = Loader.getLoader(p); + if (loader == null) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 43aaf626..56fd3232 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -1,16 +1,19 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FireMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockSpreadEvent; @Linked -public class FireListener implements Listener { +public class FireListener implements Listener, ScoreboardElement { @EventHandler public void onFireDamage(BlockBurnEvent e) { @@ -22,4 +25,19 @@ public class FireListener implements Listener { if (Region.getRegion(e.getBlock().getLocation()).getPlain(Flag.FIRE, FireMode.class) == FireMode.DENY) e.setCancelled(true); } + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index f8e811aa..17e7dd43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -4,6 +4,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.core.Core; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; @@ -11,6 +12,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.data.type.Switch; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,7 +23,7 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; @Linked -public class FreezeListener implements Listener { +public class FreezeListener implements Listener, ScoreboardElement { @EventHandler public void onEntitySpawn(EntitySpawnEvent e) { @@ -182,4 +184,20 @@ public class FreezeListener implements Listener { event.setCancelled(true); } } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java index e52d1ebb..9b173359 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ProtectListener.java @@ -1,11 +1,14 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.ProtectMode; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockExplodeEvent; @@ -14,7 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import java.util.List; @Linked -public class ProtectListener implements Listener { +public class ProtectListener implements Listener, ScoreboardElement { private void explode(List blockList, Location location) { Region region = Region.getRegion(location); @@ -36,4 +39,20 @@ public class ProtectListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation()); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 2; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.PROTECT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.PROTECT).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java new file mode 100644 index 00000000..246b9a01 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.region; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.GlobalRegion; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class RegionScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + if (GlobalRegion.getInstance() == region) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 958471e2..945858f6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.region; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.script.CustomScriptManager; import de.steamwar.bausystem.features.script.custom.event.EventType; import de.steamwar.bausystem.region.Region; @@ -27,6 +28,7 @@ import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; import de.steamwar.linkage.LinkedInstance; import org.bukkit.Bukkit; @@ -44,7 +46,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @Linked -public class TNTListener implements Listener { +public class TNTListener implements Listener, ScoreboardElement { @LinkedInstance public CustomScriptManager customScriptManager; @@ -88,4 +90,20 @@ public class TNTListener implements Listener { public void onExplode(EntityExplodeEvent event) { explode(event.blockList(), event.getLocation(), EventType.TNTExplodeInBuild, event); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.REGION; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (region.getFloorLevel() == 0) return null; + return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java index e06724ba..b6c6975e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/techhider/TechHiderCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.techhider; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -41,7 +42,7 @@ import java.util.*; import java.util.stream.Collectors; @Linked -public class TechHiderCommand extends SWCommand implements Listener { +public class TechHiderCommand extends SWCommand implements Listener, ScoreboardElement { public TechHiderCommand() { super("techhider", "hider", "obfuscate", "hide", "hide-tech"); @@ -50,16 +51,6 @@ public class TechHiderCommand extends SWCommand implements Listener { private Map> techHiders = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static TechHiderCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public XrayCommand xrayCommand; @@ -124,4 +115,20 @@ public class TechHiderCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java new file mode 100644 index 00000000..f22660dc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSScoreboardElement.java @@ -0,0 +1,68 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tpslimit; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.core.TPSWatcher; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TPSScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.FOOTER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (FreezeUtils.frozen()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p); + } else { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit(); + } + } + + private String tpsColor() { + double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { + return "§a"; + } + if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { + return "§e"; + } + return "§c"; + } + + private String tpsLimit() { + if (TPSLimitUtils.getCurrentTPSLimit() == 20) { + return ""; + } + return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java new file mode 100644 index 00000000..5e955824 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceScoreboardElement.java @@ -0,0 +1,53 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.tracer; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tracer.record.Recorder; +import de.steamwar.bausystem.features.tracer.show.StoredRecords; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.ScoreboardElement; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +@Linked +public class TraceScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 1; + } + + @Override + public String get(Region region, Player p) { + String traceScore = Recorder.INSTANCE.get(region).scoreboard(p); + if (traceScore != null) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore; + } else if (!(Recorder.INSTANCE.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p); + } + return null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index eaebc5ed..6efda09f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -1,21 +1,11 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.loader.Loader; -import de.steamwar.bausystem.features.script.CustomScriptManager; -import de.steamwar.bausystem.features.techhider.TechHiderCommand; -import de.steamwar.bausystem.features.tpslimit.FreezeUtils; -import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; -import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; -import de.steamwar.bausystem.features.tracer.record.Recorder; -import de.steamwar.bausystem.features.tracer.show.StoredRecords; -import de.steamwar.bausystem.features.xray.XrayCommand; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.Flag; -import de.steamwar.core.TPSWatcher; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.linkage.Linked; -import de.steamwar.linkage.LinkedInstance; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.entity.Player; @@ -23,128 +13,65 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.text.SimpleDateFormat; import java.util.*; @Linked public class BauScoreboard implements Listener { - private static final Random RANDOM = new Random(); - private static final String ALL = "0123456789abcdef"; - - private static String getRandomColorCode() { - StringBuilder st = new StringBuilder(); - for (int i = 0; i < 6; i++) { - st.append("§" + ALL.charAt(RANDOM.nextInt(ALL.length()))); - } - return st.toString(); - } - - @LinkedInstance - public Recorder recorder; - - @LinkedInstance - public CustomScriptManager customScriptManager; + public static final List ELEMENTS = new ArrayList<>(); @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + Map> map = new HashMap<>(); + for (ScoreboardElement element : ELEMENTS) { + map.computeIfAbsent(element.getGroup(), scoreboardGroup -> new ArrayList<>()).add(element); + } + map.forEach((scoreboardGroup, scoreboardElements) -> { + scoreboardElements.sort(Comparator.comparingInt(ScoreboardElement::order)); + }); + SWScoreboard.createScoreboard(player, new ScoreboardCallback() { @Override public HashMap getData() { - return sidebar(player); + Region region = Region.getRegion(player.getLocation()); + + List elements = new ArrayList<>(); + calcGroup(elements, "§0", region, ScoreboardElement.ScoreboardGroup.HEADER); + calcGroup(elements, "§1", region, ScoreboardElement.ScoreboardGroup.REGION); + calcGroup(elements, "§2", region, ScoreboardElement.ScoreboardGroup.OTHER); + calcGroup(elements, "§3", region, ScoreboardElement.ScoreboardGroup.FOOTER); + + int i = elements.size(); + HashMap result = new HashMap<>(); + for (String s : elements) { + result.put(s, i--); + } + return result; + } + + private void calcGroup(List elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) { + if (map.containsKey(group)) { + List groupElements = new ArrayList<>(); + for (ScoreboardElement element : map.get(group)) { + groupElements.add(element.get(region, player)); + } + groupElements.removeIf(Objects::isNull); + if (!groupElements.isEmpty()) { + elements.add(separator); + elements.addAll(groupElements); + } + } } @Override public String getTitle() { - // ■ Region region = Region.getRegion(player.getLocation()); - if (GlobalRegion.getInstance() == region) { - return "§eSteam§8War"; - } + if (GlobalRegion.getInstance() == region) return "§eSteam§8War"; String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), player).substring(0, 2); - return colorCode + "■ §eSteam§8War " + colorCode + "■"; + return colorCode + "■ §eSteam§8War " + colorCode + "■"; // ■ } }); } - - private HashMap sidebar(Player p) { - Region region = Region.getRegion(p.getLocation()); - - List strings = new ArrayList<>(); - if (!customScriptManager.callScoreboard(p, new HashMap<>(), strings::add)) { - // String colorCode = BauSystem.MESSAGE.parse(region.get(Flag.COLOR).getChatValue(), p).substring(0, 2); - String colorCode = "§e"; - strings.add("§1"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime())); - if (GlobalRegion.getInstance() != region) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_REGION", p) + "§8: §7" + region.getDisplayName()); - } - - strings.add("§2"); - for (Flag flag : Flag.getFlags()) { - if (!flag.getRegionPredicate().test(region)) { - continue; - } - strings.add(colorCode + BauSystem.MESSAGE.parse(flag.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(flag).getChatValue(), p).replace("§e", colorCode)); - } - strings.add("§3"); - - if (TechHiderCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TECHHIDER", p)); - } else if (XrayCommand.isHidden(region, p)) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p)); - } - - String traceScore = recorder.get(region).scoreboard(p); - if (traceScore != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + traceScore); - } else if (!(recorder.get(region) instanceof Recorder.NoopTraceRecorder) && !StoredRecords.getRecords(region).isEmpty()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TRACE", p) + "§8: " + BauSystem.MESSAGE.parse("TRACE_HAS_TRACES", p)); - } - - Loader loader = Loader.getLoader(p); - if (loader != null) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p)); - } - - if (!strings.get(strings.size() - 1).equals("§3")) { - strings.add("§5"); - } - if (FreezeUtils.frozen()) { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); - } else { - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8: " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); - } - } - - int i = strings.size(); - HashMap result = new HashMap<>(); - for (String s : strings) { - if (s.isEmpty()) { - s = getRandomColorCode(); - } - result.put(s, i--); - } - return result; - } - - private String tpsColor() { - double tps = TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND); - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.9) { - return "§a"; - } - if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) { - return "§e"; - } - return "§c"; - } - - private String tpsLimit() { - if (TPSLimitUtils.getCurrentTPSLimit() == 20) { - return ""; - } - return "§8/§7" + TPSLimitUtils.getCurrentTPSLimit(); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 9418a7e1..1a9387c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.techhider.TechHiderCommand; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.bausystem.utils.ScoreboardElement; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; import de.steamwar.linkage.Linked; @@ -47,7 +48,7 @@ import java.util.*; import java.util.function.BiFunction; @Linked -public class XrayCommand extends SWCommand implements Listener { +public class XrayCommand extends SWCommand implements Listener, ScoreboardElement { public XrayCommand() { super("xray"); @@ -57,16 +58,6 @@ public class XrayCommand extends SWCommand implements Listener { private Map> xrayedBlocks = new HashMap<>(); private Map> hidden = new HashMap<>(); - private static XrayCommand INSTANCE; - - { - INSTANCE = this; - } - - public static boolean isHidden(Region region, Player player) { - return INSTANCE.hidden.getOrDefault(region, Collections.emptySet()).contains(player); - } - @LinkedInstance public TechHiderCommand techHiderCommand; @@ -176,4 +167,20 @@ public class XrayCommand extends SWCommand implements Listener { return set; }); } + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.OTHER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + if (!hidden.getOrDefault(region, Collections.emptySet()).contains(p)) return null; + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_XRAY", p); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 800c7a77..0c45d1ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -19,23 +19,21 @@ package de.steamwar.bausystem.region.flags; -import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; import java.util.EnumSet; import java.util.Set; -import java.util.function.Predicate; @Getter public enum Flag implements EnumDisplay { - COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW, region -> false), - TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB, region -> true), - FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true), - FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, region -> region.getFloorLevel() != 0); + COLOR("FLAG_COLOR", ColorMode.class, ColorMode.YELLOW), + TNT("FLAG_TNT", TNTMode.class, TNTMode.ONLY_TB), + FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW), + FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE), + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE); @Getter private static final Set flags; @@ -48,14 +46,12 @@ public enum Flag implements EnumDisplay { private final Class> valueType; private final Flag.Value defaultValue; private final Value[] values; - private final Predicate regionPredicate; - & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue, Predicate regionPredicate) { + & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue) { this.chatValue = chatValue; this.valueType = valueType; this.defaultValue = defaultValue; this.values = defaultValue.getValues(); - this.regionPredicate = regionPredicate; } public Value getFlagValueOf(final String name) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java new file mode 100644 index 00000000..5f573322 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ScoreboardElement.java @@ -0,0 +1,37 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import de.steamwar.bausystem.region.Region; +import org.bukkit.entity.Player; + +public interface ScoreboardElement { + ScoreboardGroup getGroup(); + int order(); + + String get(Region region, Player p); + + enum ScoreboardGroup { + HEADER, + REGION, + OTHER, + FOOTER + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java new file mode 100644 index 00000000..d3ca0fea --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/TimeScoreboardElement.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.region.Region; +import de.steamwar.linkage.Linked; +import org.bukkit.entity.Player; + +import java.text.SimpleDateFormat; +import java.util.Calendar; + +@Linked +public class TimeScoreboardElement implements ScoreboardElement { + + @Override + public ScoreboardGroup getGroup() { + return ScoreboardGroup.HEADER; + } + + @Override + public int order() { + return 0; + } + + @Override + public String get(Region region, Player p) { + return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_TIME", p) + "§8: §7" + new SimpleDateFormat(BauSystem.MESSAGE.parse("TIME", p)).format(Calendar.getInstance().getTime()); + } +} -- 2.39.2 From d0ab735bbf9049bb6bec30bb165c973595ef2872 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 1 May 2023 15:06:15 +0200 Subject: [PATCH 2/2] Hotfix stuff Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 - BauSystem_Main/src/BauSystem_de.properties | 1 - .../src/de/steamwar/bausystem/features/region/FireListener.java | 1 - .../de/steamwar/bausystem/features/region/FreezeListener.java | 1 - .../src/de/steamwar/bausystem/features/region/TNTListener.java | 1 - 5 files changed, 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 320cd623..d71c6aaf 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -606,7 +606,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_6 = §7z§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Simulator SIMULATOR_GUI_DELETE = §cDelete TNT -SIMULATOR_GUI_START = §eStart SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eMove all diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index a4eae658..9ac07bd8 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -589,7 +589,6 @@ SIMULATOR_GUI_TNT_GROUP_LORE_1 = §7Elementanzahl§8: §e{0} SIMULATOR_GUI_TNT_DISABLED = §cDisabled SIMULATOR_GUI_NAME = Kanonensimulator SIMULATOR_GUI_DELETE = §cTNT löschen -SIMULATOR_GUI_START = §eStarten SIMULATOR_GUI_AUTO_TRACE = §eAutoTrace§8: §7{0} SIMULATOR_GUI_MOVE_ALL = §eAlle Verschieben diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java index 56fd3232..afe30aa1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FireListener.java @@ -37,7 +37,6 @@ public class FireListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java index 17e7dd43..d810ce61 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/FreezeListener.java @@ -197,7 +197,6 @@ public class FreezeListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java index 945858f6..08309eb6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTListener.java @@ -103,7 +103,6 @@ public class TNTListener implements Listener, ScoreboardElement { @Override public String get(Region region, Player p) { - if (region.getFloorLevel() == 0) return null; return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p); } } -- 2.39.2