diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java index 94dc43d..1816f31 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TNTTracer_12.java @@ -22,14 +22,15 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class TNTTracer_12 { - public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { - return new TraceEntity_12(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { + return new TraceEntity_12(world, tntPosition, player, exploded); } - public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { return new UpdateEntity_12(world, tntPosition, player); } diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java index 14c2565..f3189ae 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/TraceEntity_12.java @@ -24,21 +24,22 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - private TNTPosition position; - - public TraceEntity_12(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + private Vector position; + + public TraceEntity_12(World world, Vector position, Player player, boolean exploded) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); - if (position.isExploded()) { - this.setCustomName("Exploded"); + if (exploded) { + this.setCustomName("Bum"); } display(player); @@ -52,9 +53,9 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); diff --git a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java index 2cd3272..76ca075 100644 --- a/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java +++ b/BauSystem_12/src/de/steamwar/bausystem/tracer/UpdateEntity_12.java @@ -26,13 +26,14 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { - private TNTPosition position; + private Vector position; - public UpdateEntity_12(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.STAINED_GLASS.getBlockData()); + public UpdateEntity_12(World world, Vector position, Player player) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.STAINED_GLASS.getBlockData()); this.position = position; this.setNoGravity(true); @@ -51,9 +52,9 @@ class UpdateEntity_12 extends EntityFallingBlock implements AbstractTraceEntity @Override public AbstractTraceEntity display(Player player) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0); - ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getLocation().getX()); - ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getLocation().getY()); - ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getLocation().getZ()); + ReflectionUtils.setValue("c", packetPlayOutSpawnEntity, position.getX()); + ReflectionUtils.setValue("d", packetPlayOutSpawnEntity, position.getY()); + ReflectionUtils.setValue("e", packetPlayOutSpawnEntity, position.getZ()); ReflectionUtils.setValue("f", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("g", packetPlayOutSpawnEntity, 0); ReflectionUtils.setValue("h", packetPlayOutSpawnEntity, 0); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java index 823ea7a..1c541e8 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TNTTracer_15.java @@ -22,14 +22,15 @@ package de.steamwar.bausystem.tracer; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class TNTTracer_15 { - public static AbstractTraceEntity createTNT(World world, TNTPosition tntPosition, Player player) { - return new TraceEntity_15(world, tntPosition, player); + public static AbstractTraceEntity createTNT(World world, Vector tntPosition, Player player, boolean exploded) { + return new TraceEntity_15(world, tntPosition, player, exploded); } - public static AbstractTraceEntity createUpdatePoint(World world, TNTPosition tntPosition, Player player) { + public static AbstractTraceEntity createUpdatePoint(World world, Vector tntPosition, Player player) { return new UpdateEntity_15(world, tntPosition, player); } diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java index 738f5dd..ec58a28 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/TraceEntity_15.java @@ -24,22 +24,23 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private TNTPosition position; + private Vector position; - public TraceEntity_15(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public TraceEntity_15(World world, Vector position, Player player, boolean exploded) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); this.ticksLived = -12000; this.dropItem = false; this.setCustomNameVisible(true); - if (position.isExploded()) { - this.setCustomName(new ChatComponentText("Exploded")); + if (exploded) { + this.setCustomName(new ChatComponentText("Bum")); } display(player); @@ -52,7 +53,7 @@ class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.TNT.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); diff --git a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java index 8fa1f70..7cabccd 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/tracer/UpdateEntity_15.java @@ -26,14 +26,15 @@ import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { private static final Vec3D ZERO = new Vec3D(0, 0, 0); - private TNTPosition position; + private Vector position; - public UpdateEntity_15(World world, TNTPosition position, Player player) { - super(((CraftWorld) world).getHandle(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), Blocks.TNT.getBlockData()); + public UpdateEntity_15(World world, Vector position, Player player) { + super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), Blocks.TNT.getBlockData()); this.position = position; this.setNoGravity(true); @@ -51,7 +52,7 @@ class UpdateEntity_15 extends EntityFallingBlock implements AbstractTraceEntity @Override public AbstractTraceEntity display(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntity); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); diff --git a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java index 8922696..d877ae5 100644 --- a/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java +++ b/BauSystem_API/src/de/steamwar/bausystem/tracer/TNTPosition.java @@ -25,18 +25,17 @@ import org.bukkit.util.Vector; public class TNTPosition { private Vector location; - private Vector velocity; + private Vector previousLocation = null; private boolean exploded; - public TNTPosition(Entity entity, boolean exploded) { + public TNTPosition(Entity entity, Vector previousLocation, boolean exploded) { location = entity.getLocation().toVector(); - velocity = entity.getVelocity(); + this.previousLocation = previousLocation; this.exploded = exploded; } public TNTPosition(Vector vector) { location = vector; - this.velocity = null; this.exploded = false; } @@ -44,8 +43,8 @@ public class TNTPosition { return location; } - public Vector getVelocity() { - return velocity; + public Vector getPreviousLocation() { + return previousLocation; } public boolean isExploded() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java index a9ea8c1..44a240c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandTrace.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.tracer.record.RecordStateMachine; +import de.steamwar.bausystem.tracer.record.RecordStatus; import de.steamwar.bausystem.tracer.show.StoredRecords; import de.steamwar.bausystem.tracer.show.TraceShowManager; import de.steamwar.bausystem.world.Welt; @@ -76,7 +77,17 @@ public class CommandTrace implements CommandExecutor { case "toggleauto": case "auto": RecordStateMachine.commandAuto(); - player.sendMessage(BauSystem.PREFIX + "§eTNT-Tracer auf Auto gestellt"); + switch (RecordStateMachine.getRecordStatus()) { + case RECORD_AUTO: + player.sendMessage(BauSystem.PREFIX + "§aAuto-Tracer gestartet"); + break; + case IDLE_AUTO: + player.sendMessage(BauSystem.PREFIX + "§cAuto-Tracer gestoppt"); + break; + case RECORD: + player.sendMessage(BauSystem.PREFIX + "§cTNT-Tracer muss gestoppt werden"); + break; + } break; case "clear": case "delete": diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java index 8f72dcd..8f97814 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/Record.java @@ -57,7 +57,6 @@ public class Record { public static class TNTRecord { private final List positions = new ArrayList<>(41); - private boolean exploded = false; public void showAll(ShowMode mode) { for (TNTPosition position : positions) @@ -66,14 +65,22 @@ public class Record { /* The following methods should only be called by a recorder */ public void add(TNTPrimed tntPrimed) { - TNTPosition position = new TNTPosition(tntPrimed, exploded); + add(tntPrimed, false); + } + + private void add(TNTPrimed tntPrimed, boolean exploded) { + TNTPosition position; + if (positions.isEmpty()) { + position = new TNTPosition(tntPrimed, null, exploded); + } else { + position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded); + } positions.add(position); TraceShowManager.show(position); } public void explode(TNTPrimed tntPrimed) { - exploded = true; - add(tntPrimed); + add(tntPrimed, true); } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java index 15c7ba9..0969fd9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/TraceShowManager.java @@ -37,9 +37,6 @@ public class TraceShowManager implements Listener { case "advancednowater": showMode = new AdvancedNoWater(player); break; - case "experimental": - showMode = new Experimental(player); - break; case "basic": case "default": default: diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java index 02ec875..5a83ae6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Advanced.java @@ -44,16 +44,15 @@ public class Advanced extends Basic { public void show(TNTPosition position) { super.show(position); - if (position.isExploded()) return; - if (position.getVelocity() == null) return; - Vector nextLocation = position.getLocation().clone().add(position.getVelocity()); + if (position.getPreviousLocation() == null) return; + Vector previousLocation = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointY = position.getLocation().clone().setY(nextLocation.getY()); + Vector updatePointY = previousLocation.clone().setY(position.getLocation().getY()); Vector updatePointXZ; - if (Math.abs(position.getVelocity().getX()) > Math.abs(position.getVelocity().getZ())) { - updatePointXZ = updatePointY.clone().setX(nextLocation.getX()); + if (Math.abs(position.getPreviousLocation().getX()) > Math.abs(position.getPreviousLocation().getZ())) { + updatePointXZ = updatePointY.clone().setX(position.getLocation().getX()); } else { - updatePointXZ = updatePointY.clone().setZ(nextLocation.getZ()); + updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ()); } if (!position.getLocation().equals(updatePointY)) { @@ -64,10 +63,10 @@ public class Advanced extends Basic { switch (Core.getVersion()) { case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); break; default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointY).getLocation(), player)); break; } } @@ -79,10 +78,10 @@ public class Advanced extends Basic { switch (Core.getVersion()) { case 12: - updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); break; default: - updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ), player)); + updateEntityMap.put(updatePointPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), new TNTPosition(updatePointXZ).getLocation(), player)); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java index e72d2ab..8326b6e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Basic.java @@ -27,10 +27,10 @@ public class Basic implements ShowMode { switch (Core.getVersion()) { case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); + tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); break; default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); + tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position.getLocation(), player, position.isExploded())); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java b/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java deleted file mode 100644 index 65ebda8..0000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/tracer/show/mode/Experimental.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 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.tracer.show.mode; - -import de.steamwar.bausystem.tracer.*; -import de.steamwar.bausystem.tracer.show.ShowMode; -import de.steamwar.core.Core; -import net.minecraft.server.v1_15_R1.EntityTNTPrimed; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; - -public class Experimental implements ShowMode { - - private final Player player; - - private Map tntEntityMap = new HashMap<>(); - - public Experimental(Player player) { - this.player = player; - } - - @Override - public void show(TNTPosition position) { - RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); - if (tntEntityMap.containsKey(roundedTNTPosition)) { - return; - } - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createTNT(player.getWorld(), position, player)); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createTNT(player.getWorld(), position, player)); - break; - } - - position = new TNTPosition(position.getLocation().clone().subtract(position.getVelocity().clone().multiply(0.98D / 20))); - - switch (Core.getVersion()) { - case 12: - tntEntityMap.put(roundedTNTPosition, TNTTracer_12.createUpdatePoint(player.getWorld(), position, player)); - break; - default: - tntEntityMap.put(roundedTNTPosition, TNTTracer_15.createUpdatePoint(player.getWorld(), position, player)); - break; - } - } - - @Override - public void hide() { - tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { - abstractTraceEntity.hide(player); - abstractTraceEntity.remove(); - }); - tntEntityMap.clear(); - } - -}