SteamWar/BauSystem
Archiviert
13
0

Merge pull request 'Dont show tnt exploded in water without -water option' (#160) from tracerWaterExploded into master

Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
YoyoNow 2021-01-15 17:21:54 +01:00
Commit 675363b545
9 geänderte Dateien mit 118 neuen und 101 gelöschten Zeilen

Datei anzeigen

@ -21,14 +21,12 @@ package de.steamwar.bausystem.tracer;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class TNTTracer_12 { public class TNTTracer_12 {
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) { public static AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) {
return new TraceEntity_12(world, tntPosition, player, exploded, tnt); return new TraceEntity_12(world, tntPosition, tnt);
} }
public static boolean inWater(World world, Vector tntPosition) { public static boolean inWater(World world, Vector tntPosition) {

Datei anzeigen

@ -28,24 +28,27 @@ import org.bukkit.util.Vector;
class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity { class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
private boolean tnt; private boolean exploded;
private int references;
public TraceEntity_12(World world, Vector position, Player player, boolean exploded, boolean tnt) { public TraceEntity_12(World world, Vector position, boolean tnt) {
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData()); super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.STAINED_GLASS.getBlockData());
this.tnt = tnt;
this.setNoGravity(true); this.setNoGravity(true);
this.ticksLived = -12000; this.ticksLived = -12000;
if (exploded) {
this.setCustomNameVisible(true);
this.setCustomName("Bumm");
}
display(player);
} }
@Override @Override
public AbstractTraceEntity display(Player player) { public void display(Player player, boolean exploded) {
if (!this.exploded && exploded) {
this.setCustomNameVisible(true);
this.setCustomName("Bumm");
this.exploded = true;
if(references++ > 0)
sendDestroy(player);
}else if(references++ > 0)
return;
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0); PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(this, 0, 0);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity); playerConnection.sendPacket(packetPlayOutSpawnEntity);
@ -53,15 +56,21 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
playerConnection.sendPacket(packetPlayOutEntityMetadata); playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this;
} }
@Override @Override
public AbstractTraceEntity hide(Player player) { public boolean hide(Player player, boolean force) {
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); if(!force && --references > 0)
return false;
sendDestroy(player);
die();
return true;
}
private void sendDestroy(Player player){
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
return this;
} }
} }

Datei anzeigen

@ -24,13 +24,12 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class TNTTracer_15 { public class TNTTracer_15 {
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) { public static AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) {
return new TraceEntity_15(world, tntPosition, player, exploded, tnt); return new TraceEntity_15(world, tntPosition, tnt);
} }
public static boolean inWater(World world, Vector tntPosition) { public static boolean inWater(World world, Vector tntPosition) {

Datei anzeigen

@ -29,42 +29,52 @@ import org.bukkit.util.Vector;
class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity { class TraceEntity_15 extends EntityFallingBlock implements AbstractTraceEntity {
private static final Vec3D ZERO = new Vec3D(0, 0, 0); private static final Vec3D ZERO = new Vec3D(0, 0, 0);
private Vector position; private final Vector position;
private boolean tnt; private final boolean tnt;
public TraceEntity_15(World world, Vector position, Player player, boolean exploded, boolean tnt) { private boolean exploded = false;
private int references = 0;
public TraceEntity_15(World world, Vector position, boolean tnt) {
super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData()); super(((CraftWorld) world).getHandle(), position.getX(), position.getY(), position.getZ(), tnt ? Blocks.TNT.getBlockData() : Blocks.WHITE_STAINED_GLASS.getBlockData());
this.position = position; this.position = position;
this.tnt = tnt; this.tnt = tnt;
this.setNoGravity(true); this.setNoGravity(true);
this.ticksLived = -12000; this.ticksLived = -12000;
if (exploded) {
this.setCustomNameVisible(true);
this.setCustomName(new ChatComponentText("Bumm"));
}
display(player);
} }
@Override @Override
public AbstractTraceEntity display(Player player) { public void display(Player player, boolean exploded) {
if (!this.exploded && exploded) {
this.setCustomNameVisible(true);
this.setCustomName(new ChatComponentText("Bumm"));
this.exploded = true;
if(references++ > 0)
sendDestroy(player);
}else if(references++ > 0)
return;
PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(getId(), getUniqueID(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.FALLING_BLOCK, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : 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, tnt ? Block.getCombinedId(Blocks.TNT.getBlockData()) : Block.getCombinedId(Blocks.WHITE_STAINED_GLASS.getBlockData()), ZERO);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity); playerConnection.sendPacket(packetPlayOutSpawnEntity);
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true); PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
playerConnection.sendPacket(packetPlayOutEntityMetadata); playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this;
} }
@Override @Override
public AbstractTraceEntity hide(Player player) { public boolean hide(Player player, boolean force) {
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()}); if(!force && --references > 0)
return false;
sendDestroy(player);
die();
return true;
}
private void sendDestroy(Player player){
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy); ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
return this;
} }
} }

Datei anzeigen

@ -23,10 +23,8 @@ import org.bukkit.entity.Player;
public interface AbstractTraceEntity { public interface AbstractTraceEntity {
AbstractTraceEntity display(Player player); void display(Player player, boolean exploded);
AbstractTraceEntity hide(Player player); boolean hide(Player player, boolean always);
void killEntity();
} }

Datei anzeigen

@ -19,26 +19,24 @@
package de.steamwar.bausystem.tracer; package de.steamwar.bausystem.tracer;
import de.steamwar.bausystem.tracer.show.Record;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
public class TNTPosition { public class TNTPosition {
private Vector location; private final Record.TNTRecord record;
private Vector previousLocation = null; private final Vector location;
private boolean exploded; private final Vector previousLocation;
private final boolean exploded;
public TNTPosition(Entity entity, Vector previousLocation, boolean exploded) { public TNTPosition(Record.TNTRecord record, Entity entity, Vector previousLocation, boolean exploded) {
location = entity.getLocation().toVector(); this.location = entity.getLocation().toVector();
this.record = record;
this.previousLocation = previousLocation; this.previousLocation = previousLocation;
this.exploded = exploded; this.exploded = exploded;
} }
public TNTPosition(Vector vector) {
location = vector;
this.exploded = false;
}
public Vector getLocation() { public Vector getLocation() {
return location; return location;
} }
@ -51,6 +49,10 @@ public class TNTPosition {
return exploded; return exploded;
} }
public Record.TNTRecord getRecord(){
return record;
}
@Override @Override
public String toString() { public String toString() {
return "Position{" + return "Position{" +

Datei anzeigen

@ -75,9 +75,9 @@ public class Record {
private void add(TNTPrimed tntPrimed, boolean exploded) { private void add(TNTPrimed tntPrimed, boolean exploded) {
TNTPosition position; TNTPosition position;
if (positions.isEmpty()) { if (positions.isEmpty()) {
position = new TNTPosition(tntPrimed, null, exploded); position = new TNTPosition(this, tntPrimed, null, exploded);
} else { } else {
position = new TNTPosition(tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded); position = new TNTPosition(this, tntPrimed, positions.get(positions.size() - 1).getLocation(), exploded);
} }
positions.add(position); positions.add(position);
TraceShowManager.show(position); TraceShowManager.show(position);
@ -86,5 +86,9 @@ public class Record {
public void explode(TNTPrimed tntPrimed) { public void explode(TNTPrimed tntPrimed) {
add(tntPrimed, true); add(tntPrimed, true);
} }
public List<TNTPosition> getPositions(){
return positions;
}
} }
} }

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bausystem.tracer.RoundedTNTPosition;
import de.steamwar.bausystem.tracer.TNTPosition; import de.steamwar.bausystem.tracer.TNTPosition;
import de.steamwar.bausystem.tracer.show.ShowModeParameter; import de.steamwar.bausystem.tracer.show.ShowModeParameter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.HashMap; import java.util.HashMap;
@ -33,7 +34,7 @@ import java.util.Map;
public class Advanced extends Basic { public class Advanced extends Basic {
private Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>(); private final Map<RoundedTNTPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
public Advanced(Player player, ShowModeParameter showModeParameter) { public Advanced(Player player, ShowModeParameter showModeParameter) {
super(player, showModeParameter); super(player, showModeParameter);
@ -43,40 +44,42 @@ public class Advanced extends Basic {
public void show(TNTPosition position) { public void show(TNTPosition position) {
super.show(position); super.show(position);
if (position.getPreviousLocation() == null) return; if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation()); for(TNTPosition pos : position.getRecord().getPositions()){
applyOnPosition(pos, updatePointPosition ->
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); updateEntityMap.computeIfPresent(updatePointPosition, (p, point) -> point.hide(player, false) ? null : point));
Vector updatePointXZ; }
if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) { return;
updatePointXZ = updatePointY.clone().setX(position.getLocation().getX());
} else {
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
} }
if (showModeParameter.isInterpolate_Y() && !position.getLocation().equals(updatePointY)) { applyOnPosition(position, updatePointPosition ->
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY); updateEntityMap.computeIfAbsent(updatePointPosition, pos -> createEntity(position.getLocation(), false))
if (!updateEntityMap.containsKey(updatePointPosition)) { .display(player, position.isExploded()));
updateEntityMap.put(updatePointPosition, createEntity(updatePointY, false, false));
}
}
if (showModeParameter.isInterpolate_XZ() && !position.getLocation().equals(updatePointXZ)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointXZ);
if (!updateEntityMap.containsKey(updatePointPosition)) {
updateEntityMap.put(updatePointPosition, createEntity(updatePointXZ, false, false));
}
}
} }
@Override @Override
public void hide() { public void hide() {
super.hide(); super.hide();
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.killEntity();
});
updateEntityMap.clear(); updateEntityMap.clear();
} }
private void applyOnPosition(TNTPosition position, Consumer<RoundedTNTPosition> function){
if (position.getPreviousLocation() == null) return;
if (showModeParameter.isInterpolate_Y()) {
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
if(!position.getLocation().equals(updatePointY))
function.accept(new RoundedTNTPosition(updatePointY));
}
if (showModeParameter.isInterpolate_XZ()){
Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation());
Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ())
? position.getLocation().clone().setZ(position.getPreviousLocation().getZ())
: position.getLocation().clone().setX(position.getPreviousLocation().getX());
if(!position.getLocation().equals(updatePointXZ))
function.accept(new RoundedTNTPosition(updatePointXZ));
}
}
} }

Datei anzeigen

@ -15,7 +15,7 @@ public class Basic implements ShowMode {
protected final Player player; protected final Player player;
protected final ShowModeParameter showModeParameter; protected final ShowModeParameter showModeParameter;
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>(); private final Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
public Basic(Player player, ShowModeParameter showModeParameter) { public Basic(Player player, ShowModeParameter showModeParameter) {
this.player = player; this.player = player;
@ -24,37 +24,31 @@ public class Basic implements ShowMode {
@Override @Override
public void show(TNTPosition position) { public void show(TNTPosition position) {
if (showModeParameter.isWater() && checkWater(position.getLocation())) { if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
for(TNTPosition pos : position.getRecord().getPositions()){
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(pos);
tntEntityMap.computeIfPresent(roundedTNTPosition, (p, tnt) -> tnt.hide(player, false) ? null : tnt);
}
return; return;
} }
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position); RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position);
if (tntEntityMap.containsKey(roundedTNTPosition)) { AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(position.getLocation(), true));
if (!position.isExploded()) { entity.display(player, position.isExploded());
return;
} else {
tntEntityMap.remove(roundedTNTPosition).hide(player).killEntity();
}
}
tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true));
} }
protected boolean checkWater(Vector position) { protected boolean checkWater(Vector position) {
return (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8), return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8),
new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14))); new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14));
} }
protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) { protected AbstractTraceEntity createEntity(Vector position, boolean tnt) {
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8), return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, tnt), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14)); new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 14));
} }
@Override @Override
public void hide() { public void hide() {
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> { tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
abstractTraceEntity.hide(player);
abstractTraceEntity.killEntity();
});
tntEntityMap.clear(); tntEntityMap.clear();
} }
} }