diff --git a/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java index c5e9b714..e70dba55 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/entities/TraceEntity19.java @@ -45,11 +45,11 @@ public class TraceEntity19 extends BaseEntity19 implements AbstractTraceEntity { public void display(Player player, boolean exploded, int ticks) { if (ticks != -1) { this.n(true); - this.a(IChatMutableComponent.a(new LiteralContents(ticks + ""))); + this.b(IChatMutableComponent.a(new LiteralContents(ticks + ""))); } if (!this.exploded && exploded) { this.n(true); - this.a(IChatMutableComponent.a(new LiteralContents("Bumm"))); + this.b(IChatMutableComponent.a(new LiteralContents("Bumm"))); this.exploded = true; if (referenceCounter.increment() > 0) { sendEntityDestroy(player); diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5fe51591..9e8ab478 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -696,6 +696,9 @@ TRACE_MESSAGE_STOP = §cTNT-Tracer stopped TRACE_MESSAGE_DELETE = §cAll TNT-positions deleted TRACE_MESSAGE_SHOW = §aAll TNT-positions shown TRACE_MESSAGE_HIDE = §cAll TNT-positions hidden +TRACE_MESSAGE_ISOLATE = §aTNT-positions isolated +TRACE_MESSAGE_UNISOLATE = §cTNT-positions hidden +TRACE_MESSAGE_CLICK_ISOLATE = §eClick to §aisolate§8/§cunisolate TRACE_MESSAGE_DISALLOWED = §cYou are not allowed to use the TNT-Tracer here TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Starts recording of all TNT-positions @@ -1243,6 +1246,7 @@ TNT_CLICK_VELOCITY_X = §7Velocity §eX§8: §e{0} TNT_CLICK_VELOCITY_Y = §7Velocity §eY§8: §e{0} TNT_CLICK_VELOCITY_Z = §7Velocity §eZ§8: §e{0} TNT_CLICK_COUNT = §7Count §8: §e{0} +TNT_CLICK_ISOLATE = §eIsolate SELECT_ITEM_CHOOSE_EXTENSION = Choose extension SELECT_ITEM_CHOOSE_SELECTION = Choose selection diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 439518b6..42a240d8 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -676,6 +676,9 @@ TRACE_MESSAGE_STOP = §cTNT-Tracer gestoppt TRACE_MESSAGE_DELETE = §cAlle TNT-Positionen gelöscht TRACE_MESSAGE_SHOW = §aAlle TNT-Positionen angezeigt TRACE_MESSAGE_HIDE = §cAlle TNT-Positionen ausgeblendet +TRACE_MESSAGE_ISOLATE = §aTNT-Positionen isoliert +TRACE_MESSAGE_UNISOLATE = §cTNT-Positionen ausgeblendet +TRACE_MESSAGE_CLICK_ISOLATE = §eKlicken zum §aisolieren§8/§causblenden TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen TRACE_COMMAND_HELP_START = §8/§etrace start §8- §7Startet die Aufnahme aller TNT-Positionen 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 40b28177..9a3a2b9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -293,6 +293,22 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p); } + @Register(value = {"isolate"}, noTabComplete = true) + public void isolateCommand(@Validator Player p, long tntRecordId) { + Record.TNTRecord tntRecord = StoredRecords.getRecords().stream().flatMap(record -> record.getTnt().stream()).filter(record -> record.getId() == tntRecordId).findFirst().orElse(null); + if (tntRecord == null) { + BauSystem.MESSAGE.send("TRACE_RECORD_TNT_NOT_FOUND", p); + return; + } + if (TraceShowManager.isIsolated(p, tntRecord)) { + TraceShowManager.unisolate(p, tntRecord); + BauSystem.MESSAGE.send("TRACE_MESSAGE_UNISOLATE", p); + } else { + TraceShowManager.isolate(p, tntRecord); + BauSystem.MESSAGE.send("TRACE_MESSAGE_ISOLATE", p); + } + } + @ClassValidator(value = Player.class, local = true) public TypeValidator validator() { return (commandSender, player, messageSender) -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java index e79454ac..5974d50e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.features.tracer.show.TraceShowManager; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.linkage.Linked; import de.steamwar.linkage.api.Plain; +import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.util.RayTraceResult; @@ -42,8 +43,8 @@ public class TraceTNTClickListener implements Plain { Set playerSet = new HashSet<>(); TinyProtocol.instance.addFilter(useEntity, (player, o) -> { - if (!playerSet.add(player)) return o; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + if (!playerSet.add(player)) return; RayTraceResult rayTraceResult = RayTraceUtils.trace(player, player.getLocation(), TraceShowManager.getEntities(player)); if (rayTraceResult == null) return; if (rayTraceResult.getHitEntity() == null) return; @@ -58,8 +59,11 @@ public class TraceTNTClickListener implements Plain { BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_X", player, tntPosition.getVelocity().getX() + ""); BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Y", player, tntPosition.getVelocity().getY() + ""); BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_VELOCITY_Z", player, tntPosition.getVelocity().getZ() + ""); - playerSet.remove(player); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_ISOLATE", player, BauSystem.MESSAGE.parse("TRACE_MESSAGE_CLICK_ISOLATE", player), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/trace isolate " + tntPosition.getRecord().getId())); }, 1); + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + playerSet.remove(player); + }, 2); return o; }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceGui.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceGui.java index 1b87bbf4..04b52da9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceGui.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/gui/TraceGui.java @@ -62,14 +62,24 @@ public class TraceGui { public static void openRecordGui(Player player, Record record) { List> recordList = new ArrayList<>(); record.getTnt().forEach(tntRecord -> { - SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_ITEM", player, tntRecord.getPositions().size())); + SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_ITEM", player, tntRecord.getPositions().size()), new ArrayList<>(), TraceShowManager.isIsolated(player, tntRecord), clickType -> { + }); recordList.add(new SWListInv.SWListEntry<>(swItem, tntRecord)); }); SWListInv tntRecordSWListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("TRACE_GUI_TITLE", player), false, recordList, (clickType, tntRecord) -> { - openTntGui(player, record, tntRecord); + if (clickType.isShiftClick()) { + if (TraceShowManager.isIsolated(player, tntRecord)) { + TraceShowManager.unisolate(player, tntRecord); + } else { + TraceShowManager.isolate(player, tntRecord); + } + openRecordGui(player, record); + } else { + openTntGui(player, record, tntRecord); + } }); tntRecordSWListInv.setItem(48, new SWItem(Material.BUCKET, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_CLEAR", player), clickType -> { - StoredRecords.getRecords().remove(record); + StoredRecords.remove(record); TraceShowManager.reshow(); openGui(player); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index cdb176cf..01135669 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.tracer.show; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; +import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.shared.ShowMode; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; @@ -10,24 +11,48 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class TraceShowManager implements Listener { private TraceShowManager() { } + private static final Map> playerIsolatedRecords = new HashMap<>(); private static final Map> showModes = new HashMap<>(); + public static void isolate(Player player, Record.TNTRecord tntRecord) { + playerIsolatedRecords.computeIfAbsent(player, p -> new HashSet<>()).add(tntRecord); + show(player, showModes.getOrDefault(player, new TraceEntityShowMode(player, new ShowModeParameter()))); + } + + public static void unisolate(Player player, Record.TNTRecord tntRecord) { + playerIsolatedRecords.computeIfPresent(player, (player1, tntRecords) -> { + tntRecords.remove(tntRecord); + return tntRecords; + }); + show(player, showModes.getOrDefault(player, new TraceEntityShowMode(player, new ShowModeParameter()))); + } + + public static boolean isIsolated(Player player, Record.TNTRecord tntRecord) { + return playerIsolatedRecords.getOrDefault(player, Collections.emptySet()).contains(tntRecord); + } + public static void show(Player player, ShowMode traceShowMode) { + Set isolatedRecords = playerIsolatedRecords.get(player); hide(player); showModes.put(player, traceShowMode); - StoredRecords.showAll(traceShowMode); + if (isolatedRecords != null && !isolatedRecords.isEmpty()) { + playerIsolatedRecords.put(player, isolatedRecords); + for (Record.TNTRecord record : isolatedRecords) { + record.getPositions().forEach(traceShowMode::show); + } + } else { + StoredRecords.showAll(traceShowMode); + } } public static void hide(Player player) { + playerIsolatedRecords.remove(player); ShowMode traceShowMode = showModes.remove(player); if (traceShowMode == null) return; @@ -63,12 +88,15 @@ public class TraceShowManager implements Listener { /* Only to be called by record */ static void show(TNTPosition tnt) { - for (ShowMode mode : showModes.values()) - mode.show(tnt); + for (Map.Entry> entry : showModes.entrySet()) { + if (playerIsolatedRecords.containsKey(entry.getKey())) continue; + entry.getValue().show(tnt); + } } /* Only to be called by StoredRecords */ static void clear() { + playerIsolatedRecords.clear(); for (ShowMode mode : showModes.values()) mode.hide(); }