SteamWar/BauSystem
Archiviert
13
0

Simplify TNTTracer_12 and TNTTracer_15

Simplify TraceEntity_12 and TraceEntity_15
Simplify UpdateEntity_12 and UpdateEntity_15
Add TNTPosition.previousLocation
Fix CommandTrace messages for argument 'auto'
Remove Experimental
Dieser Commit ist enthalten in:
jojo 2020-12-25 23:01:08 +01:00
Ursprung 2a796d710f
Commit 8f35724d72
13 geänderte Dateien mit 77 neuen und 138 gelöschten Zeilen

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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;
private Vector 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());
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);

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);

Datei anzeigen

@ -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() {

Datei anzeigen

@ -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":

Datei anzeigen

@ -57,7 +57,6 @@ public class Record {
public static class TNTRecord {
private final List<TNTPosition> 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);
}
}
}

Datei anzeigen

@ -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:

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
* /
*/
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<RoundedTNTPosition, AbstractTraceEntity> 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();
}
}