SteamWar/BauSystem2.0
Archiviert
12
0

REntity #148

Zusammengeführt
YoyoNow hat 19 Commits von REntity nach master 2023-02-24 20:31:33 +01:00 zusammengeführt
6 geänderte Dateien mit 84 neuen und 90 gelöschten Zeilen
Nur Änderungen aus Commit a8b3410749 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -105,10 +105,7 @@ public class SimulatorStorage implements Enable, Disable {
public static void delete(String name) { public static void delete(String name) {
TNTSimulator tntSimulator = tntSimulators.remove(name); TNTSimulator tntSimulator = tntSimulators.remove(name);
if (tntSimulator != null) { if (tntSimulator != null) {
new HashMap<>(tntSimulator.getPlayerShowMode()).forEach((player, simulatorEntityShowMode) -> { tntSimulator.close();
SimulatorCursor.hide(player, tntSimulator);
});
tntSimulator.hide();
} }
new File(simulatorsDir, name + ".simulator").delete(); new File(simulatorsDir, name + ".simulator").delete();
} }
@ -181,7 +178,7 @@ public class SimulatorStorage implements Enable, Disable {
if (content.isEmpty()) continue; if (content.isEmpty()) continue;
TNTSimulator tntSimulator = new TNTSimulator(); TNTSimulator tntSimulator = new TNTSimulator();
for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) { for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) {
tntSimulator.getTntElementList().add(new TNTElement(element)); tntSimulator.getTntElementList().add(new TNTElement(element, tntSimulator.getEntityServer()));
} }
tntSimulators.put(newName, tntSimulator); tntSimulators.put(newName, tntSimulator);
} }

Datei anzeigen

@ -32,11 +32,11 @@ import de.steamwar.bausystem.features.tracer.record.SingleTraceRecorder;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.bausystem.utils.RayTraceUtils;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer; import de.steamwar.entity.REntityServer;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
@ -66,9 +66,9 @@ public class TNTSimulator {
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray()); YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) { for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
if (element.containsKey("elements", YAPIONType.ARRAY)) { if (element.containsKey("elements", YAPIONType.ARRAY)) {
tntElementList.add(new TNTGroup(element)); tntElementList.add(new TNTGroup(element, entityServer));
} else { } else {
tntElementList.add(new TNTElement(element)); tntElementList.add(new TNTElement(element, entityServer));
} }
} }
} }
@ -88,6 +88,11 @@ public class TNTSimulator {
entityServer.close(); entityServer.close();
} }
public void show(Player player) {
entityServer.addPlayer(player);
players.add(player);
}
public void hide(Player player) { public void hide(Player player) {
entityServer.removePlayer(player); entityServer.removePlayer(player);
players.remove(player); players.remove(player);
@ -109,22 +114,17 @@ public class TNTSimulator {
}); });
} }
public void show(Player player) {
entityServer.addPlayer(player);
players.add(player);
}
public void show(SimulatorElement simulatorElement) { public void show(SimulatorElement simulatorElement) {
playerShowMode.forEach((player, simulatorEntityShowMode) -> { playerShowMode.forEach((player, simulatorEntityShowMode) -> {
simulatorElement.show(simulatorEntityShowMode); simulatorElement.show(simulatorEntityShowMode);
}); });
} }
public List<Entity> getEntities() { public List<REntity> getEntities() {
return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList());
} }
public List<SimulatorElement> getEntity(Entity entity) { public List<SimulatorElement> getEntity(REntity entity) {
List<SimulatorElement> tntSpawns = new ArrayList<>(); List<SimulatorElement> tntSpawns = new ArrayList<>();
for (SimulatorElement spawn : tntElementList) { for (SimulatorElement spawn : tntElementList) {
spawn.getEntity(tntSpawns, entity); spawn.getEntity(tntSpawns, entity);
@ -184,7 +184,7 @@ public class TNTSimulator {
return; return;
} }
TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result)); TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), entityServer);
tntElementList.add(tntElement); tntElementList.add(tntElement);
TNTElementGUI.open(player, tntElement, null); TNTElementGUI.open(player, tntElement, null);
} }

Datei anzeigen

@ -19,13 +19,12 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONObject; import yapion.hierarchy.types.YAPIONObject;
@ -38,15 +37,13 @@ public interface SimulatorElement {
Map<Runnable, Runnable> closeObserver = new HashMap<>(); Map<Runnable, Runnable> closeObserver = new HashMap<>();
YAPIONObject toYAPION(); YAPIONObject toYAPION();
List<Entity> getEntities(); List<REntity> getEntities();
void getEntity(List<SimulatorElement> elements, Entity entity); void getEntity(List<SimulatorElement> elements, REntity entity);
default Vector getPosition() {
return new Vector(0, 0, 0); Vector getPosition();
} void setPosition(Vector position);
void remove(TNTElement tntElement); void remove(TNTElement tntElement);
void show(SimulatorEntityShowMode showMode);
void hide(SimulatorEntityShowMode showMode);
SWItem menu(Player p); SWItem menu(Player p);
boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations boolean locations(Map<Integer, Map<Integer, Set<Pair<Runnable, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations

Datei anzeigen

@ -20,25 +20,24 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.features.simulator.OrderUtils; import de.steamwar.bausystem.features.simulator.OrderUtils;
import de.steamwar.bausystem.features.simulator.SimulatorPreview;
import de.steamwar.bausystem.features.simulator.SimulatorStorage; import de.steamwar.bausystem.features.simulator.SimulatorStorage;
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode; import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.shared.Position; import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -49,6 +48,8 @@ import java.util.*;
@Getter @Getter
public class TNTElement implements SimulatorElement { public class TNTElement implements SimulatorElement {
private static final World WORLD = Bukkit.getWorlds().get(0);
private final RFallingBlockEntity entity; private final RFallingBlockEntity entity;
TNTGroup tntGroup = null; TNTGroup tntGroup = null;
@ -69,14 +70,18 @@ public class TNTElement implements SimulatorElement {
private Material material = Material.TNT; private Material material = Material.TNT;
private boolean disabled = false; private boolean disabled = false;
public TNTElement(Vector position) { public TNTElement(Vector position, REntityServer entityServer) {
this.position = position; this.position = position;
this.entity = SimulatorEntityShowMode.createEntity(position, false); this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT);
this.entity.setNoGravity(true);
} }
public TNTElement(YAPIONObject yapionObject) { public TNTElement(YAPIONObject yapionObject, REntityServer entityServer) {
this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0))); this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0)));
this.entity = SimulatorEntityShowMode.createEntity(position, false); this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
this.entity = new RFallingBlockEntity(entityServer, position.toLocation(WORLD), Material.TNT);
this.entity.setNoGravity(true);
this.entity.setInvisible(disabled);
this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80); this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80);
this.count = yapionObject.getIntOrDefault("count", 1); this.count = yapionObject.getIntOrDefault("count", 1);
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
@ -101,21 +106,20 @@ public class TNTElement implements SimulatorElement {
yapionObject.add("zVelocity", zVelocity); yapionObject.add("zVelocity", zVelocity);
yapionObject.add("order", order.name()); yapionObject.add("order", order.name());
yapionObject.add("material", material.name()); yapionObject.add("material", material.name());
yapionObject.add("disabled", disabled);
return yapionObject; return yapionObject;
} }
@Override @Override
public List<Entity> getEntities() { public List<REntity> getEntities() {
if (disabled) return new ArrayList<>(); if (disabled) return new ArrayList<>();
entity.setPosition(getPosition()); return Arrays.asList(entity);
return Arrays.asList(entity.getBukkitEntity());
} }
@Override @Override
public void getEntity(List<SimulatorElement> elements, Entity entity) { public void getEntity(List<SimulatorElement> elements, REntity entity) {
if (disabled) return; if (disabled) return;
this.entity.setPosition(getPosition()); if (this.entity.getEntityId() == entity.getEntityId() || getPosition().equals(new Vector(entity.getX(), entity.getY(), entity.getZ()))) {
if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) {
elements.add(this); elements.add(this);
} }
} }
@ -128,6 +132,19 @@ public class TNTElement implements SimulatorElement {
return position.clone(); return position.clone();
} }
@Override
public void setPosition(Vector position) {
this.position.setX(position.getX());
this.position.setY(position.getY());
this.position.setZ(position.getZ());
_updatePosition();
}
void _updatePosition() {
Vector position = getPosition();
entity.move(position.getX(), position.getY(), position.getZ(), 0F, 0F, (byte) 0);
}
public int getTickOffset() { public int getTickOffset() {
if (tntGroup != null) { if (tntGroup != null) {
return tntGroup.getTickOffset() + tickOffset; return tntGroup.getTickOffset() + tickOffset;
@ -137,20 +154,7 @@ public class TNTElement implements SimulatorElement {
@Override @Override
public void remove(TNTElement tntElement) { public void remove(TNTElement tntElement) {
} entity.die();
@Override
public void show(SimulatorEntityShowMode showMode) {
if (disabled) return;
entity.setPosition(getPosition());
showMode.show(new Position(getPosition()));
}
@Override
public void hide(SimulatorEntityShowMode showMode) {
if (disabled) return;
entity.setPosition(getPosition());
showMode.hide(new Position(getPosition()));
} }
@Override @Override
@ -246,14 +250,7 @@ public class TNTElement implements SimulatorElement {
} }
public Vector getOwnPosition() { public Vector getOwnPosition() {
return position; return position.clone();
}
public Vector getParentPosition() {
if (tntGroup != null) {
return tntGroup.getPosition();
}
return new Vector(0, 0, 0);
} }
public void setOrder(Material material) { public void setOrder(Material material) {
@ -274,5 +271,10 @@ public class TNTElement implements SimulatorElement {
public void setDisabled(boolean disabled) { public void setDisabled(boolean disabled) {
this.disabled = disabled; this.disabled = disabled;
entity.setInvisible(disabled);
}
void _setDisabled(boolean disabled) {
entity.setInvisible(disabled);
} }
} }

Datei anzeigen

@ -20,15 +20,14 @@
package de.steamwar.bausystem.features.simulator.tnt; package de.steamwar.bausystem.features.simulator.tnt;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.simulator.SimulatorPreview;
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONArray;
@ -53,14 +52,14 @@ public class TNTGroup implements SimulatorElement {
this.position = position; this.position = position;
} }
public TNTGroup(YAPIONObject yapionObject) { public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) {
this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0)); this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0));
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0); this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL")); this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
this.disabled = yapionObject.getBooleanOrDefault("disabled", false); this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray()); YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) { for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
TNTElement tntElement = new TNTElement(element); TNTElement tntElement = new TNTElement(element, entityServer);
tntElement.tntGroup = this; tntElement.tntGroup = this;
this.elements.add(tntElement); this.elements.add(tntElement);
} }
@ -89,38 +88,37 @@ public class TNTGroup implements SimulatorElement {
} }
@Override @Override
public List<Entity> getEntities() { public List<REntity> getEntities() {
if (disabled) new ArrayList<>(); if (disabled) new ArrayList<>();
return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList()); return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList());
} }
@Override @Override
public void getEntity(List<SimulatorElement> elements, Entity entity) { public void getEntity(List<SimulatorElement> elements, REntity entity) {
if (disabled) return; if (disabled) return;
for (TNTElement tntElement : this.elements) { for (TNTElement tntElement : this.elements) {
tntElement.getEntity(elements, entity); tntElement.getEntity(elements, entity);
} }
} }
@Override
public Vector getPosition() {
return position.clone();
}
@Override
public void setPosition(Vector position) {
this.position.setX(position.getX());
this.position.setY(position.getY());
this.position.setZ(position.getZ());
elements.forEach(TNTElement::_updatePosition);
}
@Override @Override
public void remove(TNTElement tntElement) { public void remove(TNTElement tntElement) {
elements.remove(tntElement); if (elements.remove(tntElement)) {
tntElement.remove(tntElement);
} }
@Override
public void show(SimulatorEntityShowMode showMode) {
if (disabled) return;
elements.forEach(tntElement -> {
tntElement.show(showMode);
});
}
@Override
public void hide(SimulatorEntityShowMode showMode) {
if (disabled) return;
elements.forEach(tntElement -> {
tntElement.hide(showMode);
});
} }
@Override @Override
@ -183,5 +181,8 @@ public class TNTGroup implements SimulatorElement {
public void setDisabled(boolean disabled) { public void setDisabled(boolean disabled) {
this.disabled = disabled; this.disabled = disabled;
elements.forEach(tntElement -> {
tntElement._setDisabled(disabled);
});
} }
} }

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.bausystem.utils; package de.steamwar.bausystem.utils;
import de.steamwar.entity.REntity; import de.steamwar.entity.REntity;
import de.steamwar.entity.RFallingBlockEntity;
import lombok.Data; import lombok.Data;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.FluidCollisionMode; import org.bukkit.FluidCollisionMode;
@ -28,9 +27,7 @@ import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.RayTraceResult; import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -39,7 +36,7 @@ import java.util.List;
@UtilityClass @UtilityClass
public class RayTraceUtils { public class RayTraceUtils {
public static RRayTraceResult traceREntity(Player player, Location to, List<RFallingBlockEntity> entityList) { public static RRayTraceResult traceREntity(Player player, Location to, List<REntity> entityList) {
if (player.getGameMode() == GameMode.SPECTATOR) { if (player.getGameMode() == GameMode.SPECTATOR) {
return null; return null;
} }