From 32c78938b6bbfee1b03bdc50dc223d370b4c21a7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 11:19:33 +0100 Subject: [PATCH 01/12] Fix WarpCommand Fix TPSCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 16 +++-- .../bausystem/features/other/TpsCommand.java | 2 +- .../bausystem/features/warp/WarpCommand.java | 38 +++--------- .../bausystem/utils/ListChatView.java | 61 +++++++++++++++++++ 4 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ListChatView.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 9c4ad833..0a317abe 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -22,6 +22,10 @@ TIME = HH:mm:ss DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- +PAGE_LIST=§e Seite ({0}/{1}) »» +LIST_PREVIOUS_PAGE=§eVorherige Seite +LIST_NEXT_PAGE=§eNächste Seite + # Permission PERMISSION_WORLD = Einstellungen vornehmen PERMISSION_WORLD-EDIT = WorldEdit verwenden @@ -194,7 +198,7 @@ HOTBAR_INVENTORY=Standard Hotbar GUI_EDITOR_ITEM-NAME=§eGui Editor GUI_EXPORT_CODE=§eDein Gui-Code: GUI_EXPORT_CODE-HOVER=§eKopieren -GUI_IMPORT_INVALID-CODE=§eInvalieder Gui-Code +GUI_IMPORT_INVALID-CODE=§eInvalider Gui-Code GUI_IMPORT_CODE-SUCCESSFUL=§eGui-Code eingelesen GUI_NAME=Bau GUI GUI_NO_PERMISSION=§cDu hast nicht genug Rechte um dies zu tun @@ -566,6 +570,11 @@ TRACE_GUI_POSITION_Y = §7Y§8: §e{0} TRACE_GUI_POSITION_Z = §7Z§8: §e{0} TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0} +TRACE_RECORD_LIST_ELEMENT = §eTrace §8- §e{0} §7TNT +TRACE_RECORD_LIST_ELEMENT_HOVER = §7Zeige alle §eTNT §7aus diesem Trace +TRACE_RECORD_LIST_ELEMENT_DELETE = §7 §cLöschen +TRACE_RECORD_LIST_ELEMENT_DELETE_HOVER = §7Trace §clöschen + # Loader LOADER_OFF = §caus LOADER_SETUP = §eSetup @@ -696,7 +705,7 @@ OTHER_TIME_NO_PERM=§cDu darfst hier nicht die Zeit ändern OTHER_TIME_INVALID=§cBitte gib eine Zahl zwischen 0 und 24000 an OTHER_TIME_RESULT=§7§oWhooosh OTHER_TPS_HEAD = §7TPS: 1s 10s 1m 5m 10m -OTHER_TPS_MESSAGE = §7 §e{0}§7 §e{1}§7 §e{2}§7 §e{3}§7 §e{4} +OTHER_TPS_MESSAGE = §7 §e{0}§7 §e{1}§7 §e{2}§7 §e{3}§7 §e{4} OTHER_TPS_SINGLE = §8TPS: §e{0} OTHER_WORLDSPAWN_HELP=§8/§eworldspawn §8-§e Teleportiere dich zum Spawn # DebugStick @@ -881,9 +890,6 @@ WARP_GUI_NO=§cHier gibt es noch keine Warps WARP_GUI_DISTANCE=§7Distanz: §e{0} §7Blöcke WARP_GUI_LCLICK=§7Links klicken zum teleportieren WARP_GUI_RCLICK=§7Rechts klicken zum editieren -WARP_LIST_PREVIOUS_PAGE=§eVorherige Seite -WARP_LIST_PAGE=§e Seite ({0}/{1}) »» -WARP_LIST_NEXT_PAGE=§eNächste Seite WARP_INFO_NAME=§7Name: §e{0} WARP_HELP_1=§8/§ewarp add §8[§7Name§8] - §7Erstelle einen neuen Warp Punkt WARP_HELP_2=§8/§ewarp §8[§7Name§8] - §7Teleportiere dich zu einen Warp-Punkt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TpsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TpsCommand.java index f964c156..a81ed03b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TpsCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TpsCommand.java @@ -39,7 +39,7 @@ public class TpsCommand extends SWCommand { @Register(help = true) public void genericCommand(Player p, String... args) { BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_HEAD", p); - BauSystem.MESSAGE.send("OTHER_TPS_MESSAGE", p, + BauSystem.MESSAGE.sendPrefixless("OTHER_TPS_MESSAGE", p, TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND), TPSWarpUtils.getTps(TPSWatcher.TPSType.TEN_SECONDS), TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_MINUTE), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java index 14fd84b3..e18f9940 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/warp/WarpCommand.java @@ -25,6 +25,7 @@ import de.steamwar.bausystem.linkage.Disable; import de.steamwar.bausystem.linkage.Enable; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; @@ -38,7 +39,6 @@ import org.bukkit.entity.Player; import yapion.hierarchy.types.YAPIONObject; import java.util.ArrayList; -import java.util.List; @Linked(LinkageType.COMMAND) @Linked(LinkageType.DISABLE_LINK) @@ -115,38 +115,20 @@ public class WarpCommand extends SWCommand implements Disable, Enable { @Register("list") public void listWarps(Player player, int page) { - List warps = Warp.getWarps(); - int pageCount = (int) Math.ceil(warps.size() / 18d); - for (int i = page * 18; i < warps.size() && i < (page + 1) * 18; i++) { - Warp warp = warps.get(i); + ListChatView.chatView(player, Warp.getWarps(), page, warp -> { TextComponent component = new TextComponent(); component.setText(warp.getName()); component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp " + warp.getName())); component.setColor(ChatColor.YELLOW); component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("WARP_TELEPORT_HOVER", player, warp.getName())))); - player.spigot().sendMessage(component); - } - - TextComponent beforePage = new TextComponent("««"); - if (page > 0) { - beforePage.setColor(ChatColor.YELLOW); - beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("WARP_LIST_PREVIOUS_PAGE", player)).create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page - 1))); - } else { - beforePage.setColor(ChatColor.RED); - } - - TextComponent nextPage = new TextComponent(BauSystem.MESSAGE.parse("WARP_LIST_PAGE", player, page + 1, Math.max(pageCount, 1))); - if (page < pageCount - 1) { - nextPage.setColor(ChatColor.YELLOW); - nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("WARP_LIST_NEXT_PAGE", player)).create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + (page + 1))); - } else { - nextPage.setColor(ChatColor.RED); - } - - beforePage.addExtra(nextPage); - player.spigot().sendMessage(beforePage); + return component; + }, (beforePageComponent, beforePage) -> { + beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", player)).create())); + beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + beforePage)); + }, (afterPageComponent, afterPage) -> { + afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", player)).create())); + afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warp list " + afterPage)); + }); } @Register("info") diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ListChatView.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ListChatView.java new file mode 100644 index 00000000..09791378 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ListChatView.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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 lombok.experimental.UtilityClass; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Function; + +@UtilityClass +public class ListChatView { + + public static void chatView(Player player, List elements, int page, Function elementConverter, BiConsumer beforePageConsumer, BiConsumer afterPageConsumer) { + int pageCount = (int) Math.ceil(elements.size() / 18d); + for (int i = page * 18; i < elements.size() && i < (page + 1) * 18; i++) { + T element = elements.get(i); + player.spigot().sendMessage(elementConverter.apply(element)); + } + + TextComponent beforePage = new TextComponent("««"); + if (page > 0) { + beforePage.setColor(ChatColor.YELLOW); + beforePageConsumer.accept(beforePage, page - 1); + } else { + beforePage.setColor(ChatColor.RED); + } + + TextComponent nextPage = new TextComponent(BauSystem.MESSAGE.parse("PAGE_LIST", player, page + 1, Math.max(pageCount, 1))); + if (page < pageCount - 1) { + nextPage.setColor(ChatColor.YELLOW); + afterPageConsumer.accept(nextPage, page + 1); + } else { + nextPage.setColor(ChatColor.RED); + } + + beforePage.addExtra(nextPage); + player.spigot().sendMessage(beforePage); + } +} From de6779c8c32d955e475536481de8b52783734417 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 15:18:03 +0100 Subject: [PATCH 02/12] Add TraceCommand.recordList Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 16 ++ .../features/tracer/TNTPosition.java | 21 +- .../features/tracer/TraceCommand.java | 196 +++++++++++++++++- .../features/tracer/show/Record.java | 34 ++- .../features/tracer/show/StoredRecords.java | 15 ++ 5 files changed, 248 insertions(+), 34 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 0a317abe..4986e703 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -534,6 +534,7 @@ TRACE_COMMAND_HELP_SHOW_GUI = §8/§etrace show gui §8- §7Zeigt die Trace show TRACE_COMMAND_HELP_SHOW = §8/§etrace show §8- <§e-water§8|§e-interpolate-xz§8|-interpolate-y§8> - §7Zeigt alle TNT-Positionen TRACE_COMMAND_HELP_HIDE = §8/§etrace hide §8- §7Versteckt alle TNT-Positionen TRACE_COMMAND_HELP_DELETE = §8/§etrace delete §8- §7Löscht alle TNT-Positionen +TRACE_COMMAND_HELP_LIST = §8/§etrace list §8- §7Trace GUI nur im Chat TRACE_COMMAND_HELP_GUI = §8/§etrace gui §8- §7Zeigt die Trace Oberfläche an TRACE_GUI_NAME = Tracer Gui @@ -574,6 +575,21 @@ TRACE_RECORD_LIST_ELEMENT = §eTrace §8- §e{0} §7TNT TRACE_RECORD_LIST_ELEMENT_HOVER = §7Zeige alle §eTNT §7aus diesem Trace TRACE_RECORD_LIST_ELEMENT_DELETE = §7 §cLöschen TRACE_RECORD_LIST_ELEMENT_DELETE_HOVER = §7Trace §clöschen +TRACE_RECORD_DELETE = §7Trace gelöscht +TRACE_RECORD_NOT_FOUND = §7Unbekannter Trace +TRACE_RECORD_ELEMENT = §eTNT §8- §e{0} §7Positionen +TRACE_RECORD_ELEMENT_HOVER = §7Zeige alle §ePositionen §7aus diesem TNT +TRACE_RECORD_ELEMENT_DELETE = §7 §cLöschen +TRACE_RECORD_ELEMENT_DELETE_HOVER = §7Trace §clöschen +TRACE_RECORD_TNT_NOT_FOUND = §7Unbekanntes TNT +TRACE_TNT_ELEMENT = §ePosition §8- §e{0} §7FuseTicks +TRACE_TNT_ELEMENT_HOVER = §7Zeige Infos zur §ePosition §7an +TRACE_RECORD_TNT_POSITION_NOT_FOUND = §7Unbekannte TNT Position +TRACE_CHAT_POSITION_HEAD = §ePosition +TRACE_CHAT_POSITION_X = §7X§8: §e{0} +TRACE_CHAT_POSITION_Y = §7Y§8: §e{0} +TRACE_CHAT_POSITION_Z = §7Z§8: §e{0} +TRACE_CHAT_POSITION_EXPLODED = §7Explodiert§8: §e{0} # Loader LOADER_OFF = §caus diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java index 717c2414..4aabdbbb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TNTPosition.java @@ -21,39 +21,30 @@ package de.steamwar.bausystem.features.tracer; import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.shared.Position; -import org.bukkit.entity.Entity; +import lombok.Getter; +import org.bukkit.entity.TNTPrimed; import org.bukkit.util.Vector; +@Getter public class TNTPosition extends Position { private final Record.TNTRecord record; + private final int fuseTicks; private final Vector previousLocation; private final boolean exploded; - public TNTPosition(Record.TNTRecord record, Entity entity, Vector previousLocation, boolean exploded) { + public TNTPosition(Record.TNTRecord record, TNTPrimed entity, Vector previousLocation, boolean exploded) { super(entity.getLocation().toVector()); this.record = record; + this.fuseTicks = entity.getFuseTicks(); this.previousLocation = previousLocation; this.exploded = exploded; } - public Vector getPreviousLocation() { - return previousLocation; - } - - public boolean isExploded() { - return exploded; - } - - public Record.TNTRecord getRecord() { - return record; - } - @Override public String toString() { return "Position{" + "location=" + super.getLocation() + '}'; } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 2bbb6e9e..5ec05b8d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -24,25 +24,25 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.gui.TraceShowGui; import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; -import de.steamwar.bausystem.features.tracer.show.StoredRecords; -import de.steamwar.bausystem.features.tracer.show.TraceShowManager; +import de.steamwar.bausystem.features.tracer.show.*; import de.steamwar.bausystem.features.tracer.show.mode.BlockShowMode; import de.steamwar.bausystem.features.tracer.show.mode.ParticleShowMode; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import lombok.NonNull; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Linked(LinkageType.COMMAND) public class TraceCommand extends SWCommand { @@ -97,9 +97,8 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_SHOW", p); BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_HIDE", p); BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_DELETE", p); - // p.sendMessage("§8/§etrace list §8<§7FRAME-ID§8> §8- §7Listet alle TNT auf"); + BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_LIST", p); BauSystem.MESSAGE.sendPrefixless("TRACE_COMMAND_HELP_GUI", p); - // p.sendMessage("§7Optionale Parameter mit §8<>§7, Benötigte Parameter mit §8[]"); } @Register({"gui"}) @@ -108,6 +107,147 @@ public class TraceCommand extends SWCommand { TraceGui.openGui(p); } + @Register({"record", "list"}) + @Register({"list"}) + public void listCommand(Player p) { + listCommand(p, 0); + } + + @Register({"record", "list"}) + @Register({"list"}) + public void listCommand(Player player, int page) { + if (!permissionCheck(player)) return; + ListChatView.chatView(player, StoredRecords.getRecords(), page, record -> { + TextComponent component = new TextComponent(); + component.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT", player, record.size())); + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId())); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT_HOVER", player)))); + + TextComponent deleteComponent = new TextComponent(); + deleteComponent.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT_DELETE", player)); + deleteComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record delete " + record.getId())); + deleteComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT_DELETE_HOVER", player)))); + component.addExtra(deleteComponent); + return component; + }, (beforePageComponent, beforePage) -> { + beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", player)).create())); + beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record list " + beforePage)); + }, (afterPageComponent, afterPage) -> { + afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", player)).create())); + afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record list " + afterPage)); + }); + } + + @Register({"record", "delete"}) + public void recordDelete(Player p, int id) { + if (!permissionCheck(p)) return; + StoredRecords.remove(id); + BauSystem.MESSAGE.send("TRACE_RECORD_DELETE", p); + } + + @Register("record") + public void recordList(Player p, int record) { + recordList(p, record, 0); + } + + @Register("record") + public void recordList(Player player, int recordID, int page) { + if (!permissionCheck(player)) return; + Record record = StoredRecords.get(recordID); + if (record == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); + return; + } + ListChatView.chatView(player, record.getTnt(), page, tntRecord -> { + TextComponent component = new TextComponent(); + component.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_ELEMENT", player, tntRecord.getPositions().size())); + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " tnt " + tntRecord.getId())); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("TRACE_RECORD_ELEMENT_HOVER", player)))); + + TextComponent deleteComponent = new TextComponent(); + deleteComponent.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_ELEMENT_DELETE", player)); + deleteComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record tnt delete " + record.getId() + " " + tntRecord.getId())); + deleteComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("TRACE_RECORD_ELEMENT_DELETE_HOVER", player)))); + component.addExtra(deleteComponent); + return component; + }, (beforePageComponent, beforePage) -> { + beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", player)).create())); + beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " " + beforePage)); + }, (afterPageComponent, afterPage) -> { + afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", player)).create())); + afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " " + afterPage)); + }); + } + + @Register({"record", "tnt", "delete"}) + public void deleteRecordTNT(Player player, int recordID, int tntID) { + if (!permissionCheck(player)) return; + Record record = StoredRecords.get(recordID); + if (record == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); + return; + } + record.remove(tntID); + } + + @Register("record") + public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID) { + recordTNTPositions(player, recordID, tnt, tntID, 0); + } + + @Register("record") + public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID, int page) { + if (!permissionCheck(player)) return; + Record record = StoredRecords.get(recordID); + if (record == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); + return; + } + Record.TNTRecord tntRecord = record.get(tntID); + if (tntRecord == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_TNT_NOT_FOUND", player); + return; + } + ListChatView.chatView(player, tntRecord.getPositions(), page, tntPosition -> { + TextComponent component = new TextComponent(); + component.setText(BauSystem.MESSAGE.parse("TRACE_TNT_ELEMENT", player, tntPosition.getFuseTicks())); + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " tnt " + tntRecord.getId() + " fuse " + tntPosition.getFuseTicks())); + component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("TRACE_TNT_ELEMENT_HOVER", player)))); + return component; + }, (beforePageComponent, beforePage) -> { + beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", player)).create())); + beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " tnt " + beforePage)); + }, (afterPageComponent, afterPage) -> { + afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", player)).create())); + afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace record " + record.getId() + " tnt " + afterPage)); + }); + } + + @Register("record") + public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID, @Mapper("fuse") String fuse, int fuseTicks) { + if (!permissionCheck(player)) return; + Record record = StoredRecords.get(recordID); + if (record == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); + return; + } + Record.TNTRecord tntRecord = record.get(tntID); + if (tntRecord == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_TNT_NOT_FOUND", player); + return; + } + TNTPosition tntPosition = tntRecord.get(fuseTicks); + if (tntPosition == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_TNT_POSITION_NOT_FOUND", player); + return; + } + BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_HEAD", player); + BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_X", player, tntPosition.getLocation().getX()); + BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_Y", player, tntPosition.getLocation().getY()); + BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_Z", player, tntPosition.getLocation().getZ()); + BauSystem.MESSAGE.sendPrefixless("TRACE_CHAT_POSITION_EXPLODED", player, tntPosition.isExploded()); + } + @Register({"start"}) public void startCommand(Player p) { if (!permissionCheck(p)) return; @@ -219,4 +359,40 @@ public class TraceCommand extends SWCommand { } return true; } + + @Mapper(value = "tnt", local = true) + public TypeMapper tntTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (s.equals("tnt")) { + return "tnt"; + } + return null; + } + + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return Collections.singletonList("tnt"); + } + }; + } + + @Mapper(value = "fuse", local = true) + public TypeMapper fuseTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (s.equals("fuse")) { + return "fuse"; + } + return null; + } + + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return Collections.singletonList("fuse"); + } + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index ae580283..b7ad90ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -28,21 +28,19 @@ import org.bukkit.entity.TNTPrimed; import java.util.ArrayList; import java.util.List; +@Getter public class Record { - private final long startTime; - - @Getter + private static long idNumber = 0; + + private final long id = idNumber++; + private final long startTime = TPSUtils.currentTick.get(); private final List tnt = new ArrayList<>(); public int size() { return tnt.size(); } - public long getStartTime() { - return startTime; - } - public void showAll(ShowMode mode) { for (TNTRecord record : tnt) record.showAll(mode); @@ -50,7 +48,6 @@ public class Record { /* The following methods should only be called by a recorder */ public Record() { - startTime = TPSUtils.currentTick.get(); StoredRecords.add(this); } @@ -64,9 +61,21 @@ public class Record { tnt.clear(); } + public TNTRecord get(int id) { + for (TNTRecord record : tnt) { + if (record.getId() == id) return record; + } + return null; + } + + public void remove(int id) { + tnt.removeIf(record -> record.getId() == id); + } + + @Getter public static class TNTRecord { - @Getter + private final long id = idNumber++; private final List positions = new ArrayList<>(41); public void showAll(ShowMode mode) { @@ -74,6 +83,13 @@ public class Record { mode.show(position); } + public TNTPosition get(int fuseTicks) { + for (TNTPosition position : positions) { + if (position.getFuseTicks() == fuseTicks) return position; + } + return null; + } + /* The following methods should only be called by a recorder */ public void add(TNTPrimed tntPrimed) { add(tntPrimed, false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java index 8fe8fb08..de516128 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java @@ -36,6 +36,21 @@ public class StoredRecords { records.add(record); } + public static void remove(Record record) { + records.remove(record); + } + + public static void remove(int id) { + records.removeIf(record -> record.getId() == id); + } + + public static Record get(int id) { + for (Record record : records) { + if (record.getId() == id) return record; + } + return null; + } + public static void showAll(ShowMode mode) { for (Record record : records) record.showAll(mode); } From d9db7d38baf36d08112e8a7a8a48b3dae8612e72 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 15:21:28 +0100 Subject: [PATCH 03/12] Fix TraceCommand.deleteRecordTNT Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../src/de/steamwar/bausystem/features/tracer/TraceCommand.java | 1 + 2 files changed, 2 insertions(+) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 4986e703..5e5149b8 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -583,6 +583,7 @@ TRACE_RECORD_ELEMENT_DELETE = §7 §cLöschen TRACE_RECORD_ELEMENT_DELETE_HOVER = §7Trace §clöschen TRACE_RECORD_TNT_NOT_FOUND = §7Unbekanntes TNT TRACE_TNT_ELEMENT = §ePosition §8- §e{0} §7FuseTicks +TRACE_TNT_DELETE = §7TNT gelöscht TRACE_TNT_ELEMENT_HOVER = §7Zeige Infos zur §ePosition §7an TRACE_RECORD_TNT_POSITION_NOT_FOUND = §7Unbekannte TNT Position TRACE_CHAT_POSITION_HEAD = §ePosition diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 5ec05b8d..694d19b9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -188,6 +188,7 @@ public class TraceCommand extends SWCommand { return; } record.remove(tntID); + BauSystem.MESSAGE.send("TRACE_TNT_DELETE", player); } @Register("record") From a82fbf9de9ac9d5225f11d5223a47ac914da84a3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 15:27:32 +0100 Subject: [PATCH 04/12] Fix AdjacentHoney and AdjacentSlime Signed-off-by: yoyosource --- .../panzern/algorithms/AdjacentHoney.java | 18 +++++++++--------- .../panzern/algorithms/AdjacentSlime.java | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentHoney.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentHoney.java index cf989623..3992c3a8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentHoney.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentHoney.java @@ -34,19 +34,19 @@ import java.util.Set; public class AdjacentHoney implements PanzernAlgorithm { private PistonLine pistonLine = new PistonLine(); + private SlabOnRedstone slabOnRedstone = new SlabOnRedstone(); + private SlabOnTorch slabOnTorch = new SlabOnTorch(); @Override public PanzernResult check(Block source, Map adjacent, Set adjacentMaterials) { if (adjacentMaterials.contains(Material.HONEY_BLOCK)) { - for (BlockFace face : HORIZONTAL_FACES) { - if (!adjacent.containsKey(face)) continue; - if (adjacent.get(face).getType() == Material.REDSTONE_WIRE) { - PanzernResult panzernResult = pistonLine.check(source, adjacent, adjacentMaterials); - if (panzernResult == PanzernResult.DEFAULT) { - return PanzernResult.UNMOVABLE_SLAB; - } - return panzernResult; - } + PanzernResult result = slabOnRedstone.check(source, adjacent, adjacentMaterials); + if (result == PanzernResult.SLAB) { + return PanzernResult.UNMOVABLE_SLAB; + } + result = slabOnTorch.check(source, adjacent, adjacentMaterials); + if (result == PanzernResult.SLAB) { + return PanzernResult.UNMOVABLE_SLAB; } PanzernResult panzernResult = pistonLine.check(source, adjacent, adjacentMaterials); if (panzernResult == PanzernResult.DEFAULT) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentSlime.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentSlime.java index c3f27eaa..21469412 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentSlime.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/AdjacentSlime.java @@ -34,19 +34,19 @@ import java.util.Set; public class AdjacentSlime implements PanzernAlgorithm { private PistonLine pistonLine = new PistonLine(); + private SlabOnRedstone slabOnRedstone = new SlabOnRedstone(); + private SlabOnTorch slabOnTorch = new SlabOnTorch(); @Override public PanzernResult check(Block source, Map adjacent, Set adjacentMaterials) { if (adjacentMaterials.contains(Material.SLIME_BLOCK)) { - for (BlockFace face : HORIZONTAL_FACES) { - if (!adjacent.containsKey(face)) continue; - if (adjacent.get(face).getType() == Material.REDSTONE_WIRE) { - PanzernResult panzernResult = pistonLine.check(source, adjacent, adjacentMaterials); - if (panzernResult == PanzernResult.DEFAULT) { - return PanzernResult.UNMOVABLE_SLAB; - } - return panzernResult; - } + PanzernResult result = slabOnRedstone.check(source, adjacent, adjacentMaterials); + if (result == PanzernResult.SLAB) { + return PanzernResult.UNMOVABLE_SLAB; + } + result = slabOnTorch.check(source, adjacent, adjacentMaterials); + if (result == PanzernResult.SLAB) { + return PanzernResult.UNMOVABLE_SLAB; } PanzernResult panzernResult = pistonLine.check(source, adjacent, adjacentMaterials); if (panzernResult == PanzernResult.DEFAULT) { From dd77187ad80f28668f6fe9eee41c2a1251d3cdff Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 18:05:09 +0100 Subject: [PATCH 05/12] Add BlockCounter Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 8 ++ .../testblock/blockcounter/BlockCount.java | 74 +++++++++++++++++++ .../testblock/blockcounter/BlockCounter.java | 55 ++++++++++++++ .../blockcounter/BlockCounterCommand.java | 55 ++++++++++++++ .../blockcounter/BlockCounterListener.java | 48 ++++++++++++ .../testblock/depthcounter/Depth.java | 1 - 6 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5e5149b8..ed25a20d 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -510,6 +510,14 @@ SMART_PLACE_INFO = §7Plaziert rotierbare Blöcke beim §esneaken§7 von dir §e SMART_PLACE_ENABLE = §aSmartPlace aktiviert SMART_PLACE_DISABLE = §cSmartPlace deaktiviert +# BlockCounter +BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus +BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an +BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus +BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden am Testblock +BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht +BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht + # Trace TRACE_RECORD=§aan TRACE_RECORD-AUTO=§aan diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java new file mode 100644 index 00000000..503ea661 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -0,0 +1,74 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; +import lombok.ToString; +import org.bukkit.Bukkit; +import org.bukkit.block.Block; +import org.bukkit.scheduler.BukkitTask; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@ToString +public class BlockCount { + + private static BukkitTask bukkitTask = null; + + private Region region; + private int count = 0; + + private long lastUpdate = TPSUtils.currentTick.get(); + + public BlockCount(Region region) { + this.region = region; + + if (bukkitTask == null) { + bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { + Set toRemove = new HashSet<>(); + for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { + if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 20) { + continue; + } + toRemove.add(region); + + if (count > 10) { + RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count)); + } + } + toRemove.forEach(BlockCounter.blockCountMap::remove); + if (BlockCounter.blockCountMap.isEmpty()) { + bukkitTask.cancel(); + bukkitTask = null; + } + }, 2, 2); + } + } + + public void update(List blocks) { + count += blocks.size(); + lastUpdate = TPSUtils.currentTick.get(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java new file mode 100644 index 00000000..b0a7cb0f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -0,0 +1,55 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.region.Region; +import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; +import yapion.hierarchy.types.YAPIONValue; + +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class BlockCounter { + + public final Map blockCountMap = new HashMap<>(); + + public boolean isActive(final Player p) { + return (boolean) Config.getInstance().get(p).getYAPIONValueOrSetDefault("blockCounter", new YAPIONValue<>(false)).get(); + } + + public void enable(final Player p) { + Config.getInstance().get(p).put("blockCounter", true); + } + + public void disable(final Player p) { + Config.getInstance().get(p).put("blockCounter", false); + } + + public String getMessage(Player player, int count) { + if (isActive(player)) { + return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count); + } + return null; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java new file mode 100644 index 00000000..6d997edd --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterCommand.java @@ -0,0 +1,55 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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.testblock.blockcounter; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; + +@Linked(LinkageType.COMMAND) +public class BlockCounterCommand extends SWCommand { + + public BlockCounterCommand() { + super("blockcounter", "blockcount", "bcounter", "bcount"); + } + + @Register(description = "BLOCK_COUNTER_HELP_TOGGLE") + public void defaultCommand(Player p) { + if (BlockCounter.isActive(p)) { + disableCommand(p); + } else { + enableCommand(p); + } + } + + @Register(value = "enable", description = "BLOCK_COUNTER_HELP_ENABLE") + public void enableCommand(Player p) { + BlockCounter.enable(p); + BauSystem.MESSAGE.send("BLOCK_COUNTER_ENABLE", p); + } + + @Register(value = "disable", description = "BLOCK_COUNTER_HELP_DISABLE") + public void disableCommand(Player p) { + BlockCounter.disable(p); + BauSystem.MESSAGE.send("BLOCK_COUNTER_DISABLE", p); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java new file mode 100644 index 00000000..d4ab3412 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java @@ -0,0 +1,48 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 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.testblock.blockcounter; + +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.utils.RegionExtensionType; +import de.steamwar.bausystem.region.utils.RegionType; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import java.util.List; +import java.util.stream.Collectors; + +@Linked(LinkageType.LISTENER) +public class BlockCounterListener implements Listener { + + @EventHandler + public void onEntityExplode(EntityExplodeEvent event) { + Region region = Region.getRegion(event.getLocation()); + List blockList = event.blockList(); + blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList()); + if (blockList.isEmpty()) { + return; + } + BlockCounter.blockCountMap.computeIfAbsent(region, BlockCount::new).update(blockList); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java index 1c6e1514..52999a45 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java @@ -128,5 +128,4 @@ public class Depth { maxVector.setY(Math.max(maxVector.getY(), block.getY())); maxVector.setZ(Math.max(maxVector.getZ(), block.getZ())); } - } From b470cf56bb45084fd380b960c1aee6086e954660 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 18:06:55 +0100 Subject: [PATCH 06/12] Add BlockCounter Signed-off-by: yoyosource --- .../features/testblock/blockcounter/BlockCounter.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java index b0a7cb0f..e9464e95 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -24,7 +24,6 @@ import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.region.Region; import lombok.experimental.UtilityClass; import org.bukkit.entity.Player; -import yapion.hierarchy.types.YAPIONValue; import java.util.HashMap; import java.util.Map; @@ -35,7 +34,10 @@ public class BlockCounter { public final Map blockCountMap = new HashMap<>(); public boolean isActive(final Player p) { - return (boolean) Config.getInstance().get(p).getYAPIONValueOrSetDefault("blockCounter", new YAPIONValue<>(false)).get(); + if (!Config.getInstance().get(p).containsKey("blockCounter")) { + return false; + } + return Config.getInstance().get(p).getPlainValue("blockCounter"); } public void enable(final Player p) { From 46ae6afe3b8a1221a91e28643f5add2300665910 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 20:18:18 +0100 Subject: [PATCH 07/12] Fix Region Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/region/Region.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index c8cc81ba..71a74be5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -129,12 +129,20 @@ public class Region { } }); } + if (regionConfig.containsKey("prototype")) { + prototypes.add(regionConfig.getPlainValue("prototype")); + } + this.flagStorage = flagStorage; Point point = null; if (regionConfig.containsKey("minX", Integer.class) && regionConfig.containsKey("minY", Integer.class) && regionConfig.containsKey("minZ", Integer.class)) { point = new Point(regionConfig.getPlainValue("minX"), regionConfig.getPlainValue("minY"), regionConfig.getPlainValue("minZ")); } - generatePrototypeData(prototype, point); + if (prototype != null && prototypes.contains(prototype.getName())) { + generatePrototypeData(prototype, point); + } else if (regionConfig.containsKey("prototype")) { + generatePrototypeData(Prototype.getByName(regionConfig.getPlainValue("prototype")), point); + } if (!hasType(RegionType.BUILD) || !hasType(RegionType.TESTBLOCK)) { flagStorage.set(Flag.TNT, TNTMode.DENY); @@ -283,7 +291,7 @@ public class Region { } public boolean setPrototype(@NonNull Prototype prototype) { - if (!prototypes.contains(prototype.getName()) && !prototypes.isEmpty()) { + if (!prototypes.contains(prototype.getName())) { return false; } return _setPrototype(prototype); @@ -292,10 +300,6 @@ public class Region { boolean _setPrototype(@NonNull Prototype prototype) { generatePrototypeData(prototype, minPoint); RegionUtils.save(this); - setLinkedRegion(region -> { - region.generatePrototypeData(prototype, region.minPoint); - return true; - }); return true; } From 75f11561b77761a460188a0ff2c2014fafc63897 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 20:26:56 +0100 Subject: [PATCH 08/12] Update BlockCounter Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- .../features/testblock/blockcounter/BlockCount.java | 6 ++++-- .../features/testblock/blockcounter/BlockCounter.java | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index ed25a20d..8c9a45e7 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -514,7 +514,7 @@ SMART_PLACE_DISABLE = §cSmartPlace deaktiviert BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus -BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden am Testblock +BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden §e{1} §7TNT §e{2} §7Blöcke/TNT BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java index 503ea661..5b42ea59 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -39,6 +39,7 @@ public class BlockCount { private Region region; private int count = 0; + private int tntCount = 0; private long lastUpdate = TPSUtils.currentTick.get(); @@ -49,13 +50,13 @@ public class BlockCount { bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Set toRemove = new HashSet<>(); for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { - if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 20) { + if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 40) { continue; } toRemove.add(region); if (count > 10) { - RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count)); + RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, (double) blockCount.count / blockCount.tntCount)); } } toRemove.forEach(BlockCounter.blockCountMap::remove); @@ -69,6 +70,7 @@ public class BlockCount { public void update(List blocks) { count += blocks.size(); + tntCount++; lastUpdate = TPSUtils.currentTick.get(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java index e9464e95..ac2321ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -48,9 +48,9 @@ public class BlockCounter { Config.getInstance().get(p).put("blockCounter", false); } - public String getMessage(Player player, int count) { + public String getMessage(Player player, int count, int tntCount, double countPerTNT) { if (isActive(player)) { - return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count); + return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0); } return null; } From 17d869203d90d38f978fbeb69d8a0e791f58a555 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 20:31:25 +0100 Subject: [PATCH 09/12] Fix BlockCounter message Signed-off-by: yoyosource --- .../bausystem/features/testblock/blockcounter/BlockCounter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java index ac2321ec..5a625faa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -50,7 +50,7 @@ public class BlockCounter { public String getMessage(Player player, int count, int tntCount, double countPerTNT) { if (isActive(player)) { - return BauSystem.MESSAGE.parse("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0); + return BauSystem.MESSAGE.parsePrefixed("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0); } return null; } From 0895757971c0153ef60f0961b956f139f35d9055 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 20:40:21 +0100 Subject: [PATCH 10/12] Update BlockCounter.getMessage Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- .../features/testblock/blockcounter/BlockCount.java | 5 +++-- .../features/testblock/blockcounter/BlockCounter.java | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 8c9a45e7..69ab30c5 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -514,7 +514,7 @@ SMART_PLACE_DISABLE = §cSmartPlace deaktiviert BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus -BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden §e{1} §7TNT §e{2} §7Blöcke/TNT +BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java index 5b42ea59..38c1425a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCount.java @@ -40,6 +40,7 @@ public class BlockCount { private Region region; private int count = 0; private int tntCount = 0; + private final long tick = TPSUtils.currentTick.get(); private long lastUpdate = TPSUtils.currentTick.get(); @@ -50,13 +51,13 @@ public class BlockCount { bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> { Set toRemove = new HashSet<>(); for (BlockCount blockCount : BlockCounter.blockCountMap.values()) { - if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 40) { + if (TPSUtils.currentTick.get() - blockCount.lastUpdate < 60) { continue; } toRemove.add(region); if (count > 10) { - RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, (double) blockCount.count / blockCount.tntCount)); + RegionUtils.message(blockCount.region, player -> BlockCounter.getMessage(player, blockCount.count, blockCount.tntCount, blockCount.tick, blockCount.lastUpdate)); } } toRemove.forEach(BlockCounter.blockCountMap::remove); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java index 5a625faa..0b90666a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounter.java @@ -48,9 +48,11 @@ public class BlockCounter { Config.getInstance().get(p).put("blockCounter", false); } - public String getMessage(Player player, int count, int tntCount, double countPerTNT) { + public String getMessage(Player player, int count, int tntCount, long tick, long lastTick) { + double countPerTNT = (double) count / tntCount; + double countPerTick = (double) count / Math.max((lastTick - tick), 1); if (isActive(player)) { - return BauSystem.MESSAGE.parsePrefixed("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0); + return BauSystem.MESSAGE.parsePrefixed("BLOCK_COUNTER_MESSAGE", player, count, tntCount, (int) (countPerTNT * 10) / 10.0, (int) (countPerTick * 10) / 200.0); } return null; } From 956f2c8e14f4654ceac63193544ca82731a52102 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 1 Dec 2021 20:55:25 +0100 Subject: [PATCH 11/12] Fix Message coloring Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 69ab30c5..af274fa1 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -719,7 +719,7 @@ OTHER_KILLALL_HELP_SELF=§8/§ekillall §8- §7Entferne alle Entities aus deiner OTHER_KILLALL_HELP_ALL=§8/§ekillall §8[§7Global§8/Local§7] §8- §7Entferne alle Entities aus deiner Region oder global OTHER_KILLALL_REGION=§a{0} Entities aus der Region entfernt OTHER_KILLALL_GLOBAL=§a{0} Entities aus der Global entfernt -OTHER_TELEPORT_HELP = §8/§etp §8[§8Player§8] §8-§7 Teleportiere dich zu einem Spieler +OTHER_TELEPORT_HELP = §8/§etp §8[§7Player§8] §8-§7 Teleportiere dich zu einem Spieler OTHER_TELEPORT_SELF_0=§cSei eins mit dir selbst! OTHER_TELEPORT_SELF_1=§cDu brauchst Leute zum spielen? Wir haben auch einen TeamSpeak! OTHER_TELEPORT_SELF_2=§cNoch zu reisende Blöcke: 0; ETA: 0:00 From 3322e884f8b9fb4694016127ac8c327222781e8b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 2 Dec 2021 13:17:50 +0100 Subject: [PATCH 12/12] Fix BauSystem.properties Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index af274fa1..bd612c1c 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -514,7 +514,7 @@ SMART_PLACE_DISABLE = §cSmartPlace deaktiviert BLOCK_COUNTER_HELP_TOGGLE = §8/§eblockcounter §8- §7Wechsel zwischen an und aus BLOCK_COUNTER_HELP_ENABLE = §8/§eblockcounter enable §8- §7Schalte den BlockCounter an BLOCK_COUNTER_HELP_DISABLE = §8/§eblockcounter disable §8- §7Schalte den BlockCounter aus -BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke Schaden §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s +BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT §e{3} §7Blöcke/s BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht