SteamWar/BauSystem2.0
Archiviert
12
0

Update tracer to REntityServer
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-02-03 19:20:34 +01:00
Ursprung 6e56ecdc99
Commit 41391df882

Datei anzeigen

@ -19,13 +19,15 @@
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.show.EntityTraceShowMode;
import de.steamwar.bausystem.features.tracer.show.ShowModeParameter;
import de.steamwar.bausystem.shared.RoundedPosition;
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.Player;
import org.bukkit.util.Consumer;
@ -42,15 +44,17 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
protected final Player player;
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, AbstractTraceEntity> updateEntityMap = new HashMap<>();
private final Map<Entity, TNTPosition> tntPositionMap = new HashMap<>();
private final Map<RoundedPosition, REntity> tntEntityMap = new HashMap<>();
private final Map<RoundedPosition, REntity> updateEntityMap = 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.showModeParameter = showModeParameter;
this.factor = factor;
entityServer.addPlayer(player);
}
@Override
@ -61,9 +65,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
if (showModeParameter.isExplodeOnly()) {
if (position.isExploded()) {
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
tntPositionMap.put(entity.getBukkitEntity(), position);
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
tntPositionMap.put(entity, position);
}
if (!showModeParameter.isSourceOnly()) {
return;
@ -72,9 +75,8 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
if (showModeParameter.isSourceOnly()) {
if (position.isSource()) {
RoundedPosition roundedPosition = new RoundedPosition(position, factor);
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
tntPositionMap.put(entity.getBukkitEntity(), position);
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
tntPositionMap.put(entity, position);
}
return;
}
@ -83,14 +85,16 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
for (TNTPosition pos : position.getRecord().getPositions()) {
RoundedPosition roundedPosition = new RoundedPosition(pos, factor);
tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> {
return tnt.hide(player, false) ? null : tnt;
tnt.die();
return null;
});
}
// Advanced
for (TNTPosition pos : position.getRecord().getPositions()) {
applyOnPosition(pos, updatePointPosition -> {
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);
AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true));
tntPositionMap.put(entity.getBukkitEntity(), position);
entity.display(player, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1);
REntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true, position.isExploded(), showModeParameter.isTicks() ? position.getFuseTicks() : -1));
tntPositionMap.put(entity, position);
applyOnPosition(position, updatePointPosition -> {
updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> {
return createEntity(player, updatePointPosition, false);
}).display(player, false, showModeParameter.isTicks() ? position.getFuseTicks() : -1);
return createEntity(player, updatePointPosition, false, false, -1);
});
});
}
@ -113,8 +116,15 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
return FlatteningWrapper.impl.inWater(player.getWorld(), position);
}
public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) {
return NMSWrapper.impl.createTrace(player.getWorld(), position, tnt);
private REntity createEntity(Player player, Vector position, boolean tnt, boolean explode, int ticks) {
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) {
@ -140,19 +150,21 @@ public abstract class FactoredEntityShowMode implements EntityTraceShowMode {
@Override
public void hide() {
tntPositionMap.clear();
tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die());
tntEntityMap.clear();
updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.die());
updateEntityMap.clear();
}
@Override
public List<Entity> getEntities() {
return new ArrayList<>(tntPositionMap.keySet());
// return new ArrayList<>(tntPositionMap.keySet());
return new ArrayList<>();
}
@Override
public TNTPosition getTNTPosition(Entity entity) {
return tntPositionMap.get(entity);
// return tntPositionMap.get(entity);
return null;
}
}