diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java deleted file mode 100644 index 5974d50e..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceTNTClickListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.features.tracer; - -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.BauSystem; -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; - -import java.util.HashSet; -import java.util.Set; - -@Linked -public class TraceTNTClickListener implements Plain { - - private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); - - { - Set playerSet = new HashSet<>(); - - TinyProtocol.instance.addFilter(useEntity, (player, 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; - TNTPosition tntPosition = TraceShowManager.getTNTPosition(player, rayTraceResult.getHitEntity()); - if (tntPosition == null) return; - - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks()); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + ""); - BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + ""); - 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())); - }, 1); - Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - playerSet.remove(player); - }, 2); - return o; - }); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java index 62eb765d..bfcd15e5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/EntityShowMode.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.tracer.show; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.shared.RoundedPosition; import de.steamwar.bausystem.shared.ShowMode; @@ -26,6 +27,7 @@ import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; +import net.md_5.bungee.api.chat.ClickEvent; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -33,6 +35,7 @@ import org.bukkit.util.Vector; import java.util.*; import java.util.function.BiConsumer; +import java.util.stream.Stream; public class EntityShowMode implements ShowMode { @@ -56,6 +59,25 @@ public class EntityShowMode implements ShowMode { public void show(TNTPosition position) { if (entityServer == null) { entityServer = new REntityServer(); + entityServer.setCallback((player, rEntity, entityAction) -> { + if (entityAction != REntityServer.EntityAction.INTERACT) return; + TNTPosition tntPosition = Stream.concat(tntEntityMap.values().stream(), explodeEntityMap.values().stream()) + .filter(entityStack -> entityStack.entity == rEntity) + .findFirst() + .map(entityStack -> entityStack.tntPosition) + .orElse(null); + if (tntPosition == null) return; + + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_HEADER", player); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_FUSE_TIME", player, tntPosition.getFuseTicks()); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_X", player, tntPosition.getLocation().getX() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Y", player, tntPosition.getLocation().getY() + ""); + BauSystem.MESSAGE.sendPrefixless("TNT_CLICK_POSITION_Z", player, tntPosition.getLocation().getZ() + ""); + 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())); + }); entityServer.addPlayer(player); } @@ -124,11 +146,11 @@ public class EntityShowMode implements ShowMode { RoundedPosition roundedPosition = new RoundedPosition(vector, factor); EntityStack entityStack; if (positionType == PositionType.TNT) { - entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = tntEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } else if (positionType == PositionType.EXPLODE) { - entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = explodeEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } else { - entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(vector, positionType, position.getFuseTicks())); + entityStack = updateEntityMap.computeIfAbsent(roundedPosition, i -> new EntityStack(position, vector, positionType, position.getFuseTicks())); } entityStack.add(position.getRecord()); }); @@ -152,16 +174,9 @@ public class EntityShowMode implements ShowMode { return entity; } - public List getEntities() { - return new ArrayList<>(); - } - - public TNTPosition getTNTPosition(Entity entity) { - return null; - } - private class EntityStack { + private final TNTPosition tntPosition; private final Vector position; private final PositionType positionType; private final int fuseTicks; @@ -170,7 +185,8 @@ public class EntityShowMode implements ShowMode { private int count; private List records = new ArrayList<>(); - public EntityStack(Vector position, PositionType positionType, int fuseTicks) { + public EntityStack(TNTPosition tntPosition, Vector position, PositionType positionType, int fuseTicks) { + this.tntPosition = tntPosition; this.position = position; this.positionType = positionType; this.fuseTicks = fuseTicks; 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 856513ff..44ac27c5 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 @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.entity.REntity; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -70,44 +71,6 @@ public class TraceShowManager implements Listener { showMode.hide(); } - public static List getEntities(Player player) { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return Collections.emptyList(); - } - Map> regionalShowModes = showModes.get(region); - if (regionalShowModes == null) { - return Collections.emptyList(); - } - ShowMode showMode = regionalShowModes.get(player); - if (showMode == null) { - return Collections.emptyList(); - } - if (showMode instanceof EntityShowMode) { - return ((EntityShowMode) showMode).getEntities(); - } - return Collections.emptyList(); - } - - public static TNTPosition getTNTPosition(Player player, Entity entity) { - Region region = Region.getRegion(player.getLocation()); - if (region.isGlobal()) { - return null; - } - Map> regionalShowModes = showModes.get(region); - if (regionalShowModes == null) { - return null; - } - ShowMode showMode = regionalShowModes.get(player); - if (showMode == null) { - return null; - } - if (showMode instanceof EntityShowMode) { - return ((EntityShowMode) showMode).getTNTPosition(entity); - } - return null; - } - public static void reshow(Region region, Player p) { Map> regionalShowModes = showModes.get(region); if (regionalShowModes == null) {