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.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class TNTTracer_12 {
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) {
return new TraceEntity_12(world, tntPosition, player, exploded, tnt);
public static AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) {
return new TraceEntity_12(world, tntPosition, tnt);
}
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 {
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());
this.tnt = tnt;
this.setNoGravity(true);
this.ticksLived = -12000;
if (exploded) {
this.setCustomNameVisible(true);
this.setCustomName("Bumm");
}
display(player);
}
@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);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity);
@ -53,15 +56,21 @@ class TraceEntity_12 extends EntityFallingBlock implements AbstractTraceEntity {
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this;
}
@Override
public AbstractTraceEntity hide(Player player) {
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()});
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
public boolean hide(Player player, boolean force) {
if(!force && --references > 0)
return false;
return this;
sendDestroy(player);
die();
return true;
}
private void sendDestroy(Player player){
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
}
}

Datei anzeigen

@ -24,13 +24,12 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class TNTTracer_15 {
public static AbstractTraceEntity create(World world, Vector tntPosition, Player player, boolean exploded, boolean tnt) {
return new TraceEntity_15(world, tntPosition, player, exploded, tnt);
public static AbstractTraceEntity create(World world, Vector tntPosition, boolean tnt) {
return new TraceEntity_15(world, tntPosition, tnt);
}
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 {
private static final Vec3D ZERO = new Vec3D(0, 0, 0);
private Vector position;
private boolean tnt;
private final Vector position;
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());
this.position = position;
this.tnt = tnt;
this.setNoGravity(true);
this.ticksLived = -12000;
if (exploded) {
this.setCustomNameVisible(true);
this.setCustomName(new ChatComponentText("Bumm"));
}
display(player);
}
@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);
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutSpawnEntity);
PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata(getId(), datawatcher, true);
playerConnection.sendPacket(packetPlayOutEntityMetadata);
return this;
}
@Override
public AbstractTraceEntity hide(Player player) {
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(new int[]{getId()});
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
public boolean hide(Player player, boolean force) {
if(!force && --references > 0)
return false;
return this;
sendDestroy(player);
die();
return true;
}
private void sendDestroy(Player player){
PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(getId());
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -75,9 +75,9 @@ public class Record {
private void add(TNTPrimed tntPrimed, boolean exploded) {
TNTPosition position;
if (positions.isEmpty()) {
position = new TNTPosition(tntPrimed, null, exploded);
position = new TNTPosition(this, tntPrimed, null, exploded);
} 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);
TraceShowManager.show(position);
@ -86,5 +86,9 @@ public class Record {
public void explode(TNTPrimed tntPrimed) {
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.show.ShowModeParameter;
import org.bukkit.entity.Player;
import org.bukkit.util.Consumer;
import org.bukkit.util.Vector;
import java.util.HashMap;
@ -33,7 +34,7 @@ import java.util.Map;
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) {
super(player, showModeParameter);
@ -43,40 +44,42 @@ public class Advanced extends Basic {
public void show(TNTPosition position) {
super.show(position);
if (position.getPreviousLocation() == null) return;
Vector vector = position.getLocation().clone().subtract(position.getPreviousLocation());
Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY());
Vector updatePointXZ;
if (Math.abs(vector.getX()) > Math.abs(vector.getZ())) {
updatePointXZ = updatePointY.clone().setX(position.getLocation().getX());
} else {
updatePointXZ = updatePointY.clone().setZ(position.getLocation().getZ());
if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) {
for(TNTPosition pos : position.getRecord().getPositions()){
applyOnPosition(pos, updatePointPosition ->
updateEntityMap.computeIfPresent(updatePointPosition, (p, point) -> point.hide(player, false) ? null : point));
}
return;
}
if (showModeParameter.isInterpolate_Y() && !position.getLocation().equals(updatePointY)) {
RoundedTNTPosition updatePointPosition = new RoundedTNTPosition(updatePointY);
if (!updateEntityMap.containsKey(updatePointPosition)) {
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));
}
}
applyOnPosition(position, updatePointPosition ->
updateEntityMap.computeIfAbsent(updatePointPosition, pos -> createEntity(position.getLocation(), false))
.display(player, position.isExploded()));
}
@Override
public void hide() {
super.hide();
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.killEntity();
});
updateEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
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 ShowModeParameter showModeParameter;
private Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
private final Map<RoundedTNTPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
public Basic(Player player, ShowModeParameter showModeParameter) {
this.player = player;
@ -24,37 +24,31 @@ public class Basic implements ShowMode {
@Override
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;
}
RoundedTNTPosition roundedTNTPosition = new RoundedTNTPosition(position);
if (tntEntityMap.containsKey(roundedTNTPosition)) {
if (!position.isExploded()) {
return;
} else {
tntEntityMap.remove(roundedTNTPosition).hide(player).killEntity();
}
}
tntEntityMap.put(roundedTNTPosition, createEntity(position.getLocation(), position.isExploded(), true));
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedTNTPosition, pos -> createEntity(position.getLocation(), true));
entity.display(player, position.isExploded());
}
protected boolean checkWater(Vector position) {
return (VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8),
new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14)));
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.inWater(player.getWorld(), position), 8),
new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 14));
}
protected AbstractTraceEntity createEntity(Vector position, boolean exploded, boolean tnt) {
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, player, exploded, tnt), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, player, exploded, tnt), 14));
protected AbstractTraceEntity createEntity(Vector position, boolean tnt) {
return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_12.create(player.getWorld(), position, tnt), 8),
new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 14));
}
@Override
public void hide() {
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> {
abstractTraceEntity.hide(player);
abstractTraceEntity.killEntity();
});
tntEntityMap.forEach((roundedTNTPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
tntEntityMap.clear();
}
}