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 bc6f5abf..bf385f06 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.tracer.gui.TraceGui; import de.steamwar.bausystem.features.tracer.record.*; +import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; import de.steamwar.bausystem.features.tracer.show.ShowModeParameterType; import de.steamwar.bausystem.features.tracer.show.StoredRecords; @@ -107,6 +108,7 @@ public class TraceCommand extends SWCommand { @Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE") public void hideCommand(@Validator Player p) { TraceShowManager.hide(p); + StoredRecords.hideIsolated(Region.getRegion(p.getLocation()), p); BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p); } @@ -115,6 +117,7 @@ public class TraceCommand extends SWCommand { public void deleteCommand(@Validator Player p) { Region region = Region.getRegion(p.getLocation()); StoredRecords.clear(region); + StoredRecords.hideIsolated(region); BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p); } @@ -123,6 +126,17 @@ public class TraceCommand extends SWCommand { TraceGui.openGui(p); } + @Register(value = "isolate", noTabComplete = true) + public void isolate(Player p, String s) { + try { + UUID uuid = UUID.fromString(s); + Record.TNTRecord tntRecord = StoredRecords.getRecord(uuid); + StoredRecords.toggleIsolate(p, tntRecord); + } catch (Exception e) { + // Ignore + } + } + @AllArgsConstructor private enum ShowModeType { ENTITY(TraceEntityShowMode::new, new ShowModeParameterType[]{}), 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 9938565b..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; @@ -58,7 +59,7 @@ 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() + ""); - // 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())); + 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); 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 58758114..fc4500af 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,23 +62,17 @@ public class TraceGui { Region region = Region.getRegion(player.getLocation()); 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()), new ArrayList<>(), false, clickType -> { + SWItem swItem = new SWItem(Material.TNT_MINECART, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_ITEM", player, tntRecord.getPositions().size()), new ArrayList<>(), StoredRecords.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) -> { - /* if (clickType.isShiftClick()) { - if (TraceShowManager.isIsolated(player, tntRecord)) { - TraceShowManager.unisolate(player, tntRecord); - } else { - TraceShowManager.isolate(player, tntRecord); - } + StoredRecords.toggleIsolate(player, tntRecord); openRecordGui(player, record); } else { + openTntGui(player, record, tntRecord); } - */ - openTntGui(player, record, tntRecord); }); tntRecordSWListInv.setItem(48, new SWItem(Material.BUCKET, BauSystem.MESSAGE.parse("TRACE_GUI_RECORD_CLEAR", player), clickType -> { StoredRecords.remove(region, record); 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 d4ad77f9..13a8e0af 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 @@ -29,6 +29,7 @@ import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; +import java.util.UUID; @RequiredArgsConstructor public class Record { @@ -57,9 +58,15 @@ public class Record { public static class TNTRecord { + @Getter + private final UUID id = UUID.randomUUID(); + @Getter private final long offset; + + @Getter private final Region region; + @Getter private final List positions = new ArrayList<>(82); 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 be1aab51..f56acb7b 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 @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.tracer.record.Recorder; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; import lombok.experimental.UtilityClass; +import org.bukkit.entity.Player; import java.util.*; import java.util.stream.Collectors; @@ -31,6 +32,7 @@ import java.util.stream.Collectors; @UtilityClass public class StoredRecords { + private static final Map>> isolatedTNT = new HashMap<>(); private static final Map> records = new HashMap<>(); public static void add(Region region, Record record) { @@ -57,7 +59,51 @@ public class StoredRecords { return records.getOrDefault(region, Collections.emptyList()); } - static void show(Region region, ShowMode traceShowMode) { - records.getOrDefault(region, new ArrayList<>()).forEach(record -> record.showAll(traceShowMode)); + public Record.TNTRecord getRecord(UUID id) { + return records.values().stream() + .flatMap(Collection::stream) + .map(Record::getTnt) + .flatMap(Collection::stream) + .filter(tntRecord -> tntRecord.getId().equals(id)) + .findFirst() + .orElse(null); + } + + public static boolean isIsolated(Player p, Record.TNTRecord tntRecord) { + return isolatedTNT.values() + .stream() + .filter(map -> map.containsKey(p)) + .anyMatch(map -> map.get(p).contains(tntRecord)); + } + + public static void toggleIsolate(Player p, Record.TNTRecord tntRecord) { + List tntRecords = isolatedTNT.computeIfAbsent(tntRecord.getRegion(), k -> new HashMap<>()) + .computeIfAbsent(p, k -> new ArrayList<>()); + if (tntRecords.contains(tntRecord)) { + tntRecords.remove(tntRecord); + } else { + tntRecords.add(tntRecord); + } + TraceShowManager.reshow(tntRecord.getRegion(), p); + } + + public static void hideIsolated(Region region) { + isolatedTNT.remove(region); + } + + public static void hideIsolated(Region region, Player player) { + Map> regionalIsolatedTNT = isolatedTNT.get(region); + if (regionalIsolatedTNT == null) { + return; + } + regionalIsolatedTNT.remove(player); + } + + static void show(Region region, Player player, ShowMode traceShowMode) { + if (isolatedTNT.containsKey(region) && isolatedTNT.get(region).containsKey(player)) { + isolatedTNT.get(region).get(player).forEach(record -> record.getPositions().forEach(traceShowMode::show)); + } else { + records.getOrDefault(region, new ArrayList<>()).forEach(record -> record.showAll(traceShowMode)); + } } } 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 2d0cac98..0de6aaba 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 @@ -50,7 +50,7 @@ public class TraceShowManager implements Listener { } Map> regionalShowModes = showModes.computeIfAbsent(region, __ -> new HashMap<>()); regionalShowModes.put(player, traceShowMode); - StoredRecords.show(region, traceShowMode); + StoredRecords.show(region, player, traceShowMode); } public static void hide(Player player) { @@ -107,6 +107,19 @@ public class TraceShowManager implements Listener { return null; } + public static void reshow(Region region, Player p) { + Map> regionalShowModes = showModes.get(region); + if (regionalShowModes == null) { + return; + } + ShowMode showMode = regionalShowModes.get(p); + if (showMode == null) { + return; + } + showMode.hide(); + StoredRecords.show(region, p, showMode); + } + public static void reshow(Region region) { Map> regionalShowModes = showModes.get(region); if (regionalShowModes == null) { @@ -114,7 +127,7 @@ public class TraceShowManager implements Listener { } for (Map.Entry> entry : regionalShowModes.entrySet()) { entry.getValue().hide(); - StoredRecords.show(region, entry.getValue()); + StoredRecords.show(region, entry.getKey(), entry.getValue()); } }