Merge pull request 'BetterScoreboard' (#174) from BetterScoreboard into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Reviewed-on: #174
Dieser Commit ist enthalten in:
Commit
7fae86d2d4
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 + ");");
|
||||
}
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -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,18 @@ 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) {
|
||||
return "§e" + BauSystem.MESSAGE.parse(Flag.FIRE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FIRE).getChatValue(), p);
|
||||
}
|
||||
}
|
||||
|
@ -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,19 @@ 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) {
|
||||
return "§e" + BauSystem.MESSAGE.parse(Flag.FREEZE.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.FREEZE).getChatValue(), p);
|
||||
}
|
||||
}
|
||||
|
@ -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<Block> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -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,19 @@ 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) {
|
||||
return "§e" + BauSystem.MESSAGE.parse(Flag.TNT.getChatValue(), p) + "§8: " + BauSystem.MESSAGE.parse(region.get(Flag.TNT).getChatValue(), p);
|
||||
}
|
||||
}
|
||||
|
@ -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<Region, Optional<TechHider>> techHiders = new HashMap<>();
|
||||
private Map<Region, Set<Player>> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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<ScoreboardElement> ELEMENTS = new ArrayList<>();
|
||||
|
||||
@EventHandler
|
||||
public void handlePlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Map<ScoreboardElement.ScoreboardGroup, List<ScoreboardElement>> 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<String, Integer> getData() {
|
||||
return sidebar(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
// ■
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
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 + "■";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private HashMap<String, Integer> sidebar(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
List<String> 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);
|
||||
|
||||
List<String> 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();
|
||||
int i = elements.size();
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
for (String s : strings) {
|
||||
if (s.isEmpty()) {
|
||||
s = getRandomColorCode();
|
||||
}
|
||||
for (String s : elements) {
|
||||
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";
|
||||
private void calcGroup(List<String> elements, String separator, Region region, ScoreboardElement.ScoreboardGroup group) {
|
||||
if (map.containsKey(group)) {
|
||||
List<String> 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);
|
||||
}
|
||||
if (tps > TPSLimitUtils.getCurrentTPSLimit() * 0.5) {
|
||||
return "§e";
|
||||
}
|
||||
return "§c";
|
||||
}
|
||||
|
||||
private String tpsLimit() {
|
||||
if (TPSLimitUtils.getCurrentTPSLimit() == 20) {
|
||||
return "";
|
||||
@Override
|
||||
public String getTitle() {
|
||||
Region region = Region.getRegion(player.getLocation());
|
||||
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 "§8/§7" + TPSLimitUtils.getCurrentTPSLimit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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<Region, Set<Material>> xrayedBlocks = new HashMap<>();
|
||||
private Map<Region, Set<Player>> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Flag> flags;
|
||||
@ -48,14 +46,12 @@ public enum Flag implements EnumDisplay {
|
||||
private final Class<? extends Value<?>> valueType;
|
||||
private final Flag.Value<?> defaultValue;
|
||||
private final Value<?>[] values;
|
||||
private final Predicate<Region> regionPredicate;
|
||||
|
||||
<T extends Enum<T> & Value<T>> Flag(String chatValue, final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue, Predicate<Region> regionPredicate) {
|
||||
<T extends Enum<T> & Value<T>> Flag(String chatValue, final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue) {
|
||||
this.chatValue = chatValue;
|
||||
this.valueType = valueType;
|
||||
this.defaultValue = defaultValue;
|
||||
this.values = defaultValue.getValues();
|
||||
this.regionPredicate = regionPredicate;
|
||||
}
|
||||
|
||||
public Value<?> getFlagValueOf(final String name) {
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren