Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
6e56ecdc99
Commit
41391df882
@ -19,13 +19,15 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.tracer.show.mode;
|
package de.steamwar.bausystem.features.tracer.show.mode;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
|
||||||
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
import de.steamwar.bausystem.features.tracer.TNTPosition;
|
||||||
import de.steamwar.bausystem.features.tracer.show.EntityTraceShowMode;
|
import de.steamwar.bausystem.features.tracer.show.EntityTraceShowMode;
|
||||||
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
|
||||||
import de.steamwar.bausystem.shared.RoundedPosition;
|
import de.steamwar.bausystem.shared.RoundedPosition;
|
||||||
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
import de.steamwar.bausystem.utils.FlatteningWrapper;
|
||||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
import de.steamwar.entity.REntity;
|
||||||
|
import de.steamwar.entity.REntityServer;
|
||||||
|
import de.steamwar.entity.RFallingBlockEntity;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Consumer;
|
import org.bukkit.util.Consumer;
|
||||||
@ -42,15 +44,17 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
|
|
||||||
protected final Player player;
|
protected final Player player;
|
||||||
protected final ShowModeParameter showModeParameter;
|
protected final ShowModeParameter showModeParameter;
|
||||||
|
protected final REntityServer entityServer = new REntityServer(); // TODO: Needs to be closed
|
||||||
|
|
||||||
private final Map<RoundedPosition, AbstractTraceEntity> tntEntityMap = new HashMap<>();
|
private final Map<RoundedPosition, REntity> tntEntityMap = new HashMap<>();
|
||||||
private final Map<RoundedPosition, AbstractTraceEntity> updateEntityMap = new HashMap<>();
|
private final Map<RoundedPosition, REntity> updateEntityMap = new HashMap<>();
|
||||||
private final Map<Entity, TNTPosition> tntPositionMap = new HashMap<>();
|
private final Map<REntity, TNTPosition> tntPositionMap = new HashMap<>();
|
||||||
|
|
||||||
protected FactoredEntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) {
|
protected FactoredEntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) { // TODO: Fix factor
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.showModeParameter = showModeParameter;
|
this.showModeParameter = showModeParameter;
|
||||||
this.factor = factor;
|
this.factor = factor;
|
||||||
|
entityServer.addPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,9 +65,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
if (showModeParameter.isExplodeOnly()) {
|
if (showModeParameter.isExplodeOnly()) {
|
||||||
if (position.isExploded()) {
|
if (position.isExploded()) {
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
||||||
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
|
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
|
||||||
tntPositionMap.put(entity.getBukkitEntity(), position);
|
tntPositionMap.put(entity, position);
|
||||||
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
|
|
||||||
}
|
}
|
||||||
if (!showModeParameter.isSourceOnly()) {
|
if (!showModeParameter.isSourceOnly()) {
|
||||||
return;
|
return;
|
||||||
@ -72,9 +75,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
if (showModeParameter.isSourceOnly()) {
|
if (showModeParameter.isSourceOnly()) {
|
||||||
if (position.isSource()) {
|
if (position.isSource()) {
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
||||||
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
|
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
|
||||||
tntPositionMap.put(entity.getBukkitEntity(), position);
|
tntPositionMap.put(entity, position);
|
||||||
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -83,14 +85,16 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
for (TNTPosition pos : position.getRecord().getPositions()) {
|
for (TNTPosition pos : position.getRecord().getPositions()) {
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(pos, factor);
|
RoundedPosition roundedPosition = new RoundedPosition(pos, factor);
|
||||||
tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> {
|
tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> {
|
||||||
return tnt.hide(player, false) ? null : tnt;
|
tnt.die();
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Advanced
|
// Advanced
|
||||||
for (TNTPosition pos : position.getRecord().getPositions()) {
|
for (TNTPosition pos : position.getRecord().getPositions()) {
|
||||||
applyOnPosition(pos, updatePointPosition -> {
|
applyOnPosition(pos, updatePointPosition -> {
|
||||||
updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition, factor), (p, point) -> {
|
updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition, factor), (p, point) -> {
|
||||||
return point.hide(player, false) ? null : point;
|
point.die();
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -98,14 +102,13 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
|
||||||
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
|
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
|
||||||
tntPositionMap.put(entity.getBukkitEntity(), position);
|
tntPositionMap.put(entity, position);
|
||||||
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
|
|
||||||
|
|
||||||
applyOnPosition(position, updatePointPosition -> {
|
applyOnPosition(position, updatePointPosition -> {
|
||||||
updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> {
|
updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> {
|
||||||
return createEntity(player, updatePointPosition, false);
|
return createEntity(player, updatePointPosition, false, false, -1);
|
||||||
}).display(player, false, showModeParameter.isTicks() ? position.getFuseTicks() : -1);
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +116,15 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
return FlatteningWrapper.impl.inWater(player.getWorld(), position);
|
return FlatteningWrapper.impl.inWater(player.getWorld(), position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) {
|
private REntity createEntity(Player player, Vector position, boolean tnt, boolean explode, int ticks) {
|
||||||
return NMSWrapper.impl.createTrace(player.getWorld(), position, tnt);
|
Material material = tnt ? Material.TNT : Material.WHITE_STAINED_GLASS;
|
||||||
|
if (tnt && explode) material = Material.RED_STAINED_GLASS;
|
||||||
|
RFallingBlockEntity entity = new RFallingBlockEntity(entityServer, position.toLocation(player.getWorld()), material);
|
||||||
|
entity.setNoGravity(true);
|
||||||
|
if (ticks != -1) {
|
||||||
|
entity.setDisplayName(ticks + "");
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyOnPosition(TNTPosition position, Consumer<Vector> function) {
|
private void applyOnPosition(TNTPosition position, Consumer<Vector> function) {
|
||||||
@ -140,19 +150,21 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
|
|||||||
@Override
|
@Override
|
||||||
public void hide() {
|
public void hide() {
|
||||||
tntPositionMap.clear();
|
tntPositionMap.clear();
|
||||||
tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die());
|
||||||
tntEntityMap.clear();
|
tntEntityMap.clear();
|
||||||
updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die());
|
||||||
updateEntityMap.clear();
|
updateEntityMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Entity> getEntities() {
|
public List<Entity> getEntities() {
|
||||||
return new ArrayList<>(tntPositionMap.keySet());
|
// return new ArrayList<>(tntPositionMap.keySet());
|
||||||
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TNTPosition getTNTPosition(Entity entity) {
|
public TNTPosition getTNTPosition(Entity entity) {
|
||||||
return tntPositionMap.get(entity);
|
// return tntPositionMap.get(entity);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren