SteamWar/BauSystem2.0
Archiviert
12
0

Add seamless changing and showing and hiding
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-09 19:42:11 +02:00
Ursprung 6ed13702d4
Commit 8b351fe871
14 geänderte Dateien mit 136 neuen und 62 gelöschten Zeilen

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.shared.BaseEntity15;
import de.steamwar.bausystem.shared.ReferenceCounter;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -29,7 +28,7 @@ import org.bukkit.util.Vector;
public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulatorEntity {
private ReferenceCounter referenceCounter = new ReferenceCounter();
private boolean printed = false;
public SimulatorEntity15(World world, Vector position, boolean highlight) {
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
@ -40,9 +39,8 @@ public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulator
@Override
public void display(Player player) {
if (referenceCounter.increment() > 0) {
return;
}
if (printed) return;
printed = true;
sendEntity(player);
}
@ -55,9 +53,9 @@ public class SimulatorEntity15 extends BaseEntity15 implements AbstractSimulator
@Override
public boolean hide(Player player, boolean force) {
if (!force && referenceCounter.decrement() > 0) {
return false;
}
if (!printed) return false;
printed = false;
sendEntityDestroy(player);
die();

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.shared.BaseEntity18;
import de.steamwar.bausystem.shared.ReferenceCounter;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -29,7 +28,7 @@ import org.bukkit.util.Vector;
public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulatorEntity {
private ReferenceCounter referenceCounter = new ReferenceCounter();
private boolean printed = false;
public SimulatorEntity18(World world, Vector position, boolean highlight) {
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
@ -45,9 +44,8 @@ public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulator
@Override
public void display(Player player) {
if (referenceCounter.increment() > 0) {
return;
}
if (printed) return;
printed = true;
sendEntity(player);
}
@ -60,9 +58,8 @@ public class SimulatorEntity18 extends BaseEntity18 implements AbstractSimulator
@Override
public boolean hide(Player player, boolean force) {
if (!force && referenceCounter.decrement() > 0) {
return false;
}
if (!printed) return false;
printed = false;
sendEntityDestroy(player);
ag();

Datei anzeigen

@ -21,7 +21,6 @@ package de.steamwar.bausystem.entities;
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
import de.steamwar.bausystem.shared.BaseEntity19;
import de.steamwar.bausystem.shared.ReferenceCounter;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
@ -29,7 +28,7 @@ import org.bukkit.util.Vector;
public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulatorEntity {
private ReferenceCounter referenceCounter = new ReferenceCounter();
private boolean printed = false;
public SimulatorEntity19(World world, Vector position, boolean highlight) {
super(world, position, highlight ? Material.WHITE_STAINED_GLASS : Material.TNT);
@ -45,9 +44,8 @@ public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulator
@Override
public void display(Player player) {
if (referenceCounter.increment() > 0) {
return;
}
if (printed) return;
printed = true;
sendEntity(player);
}
@ -60,9 +58,8 @@ public class SimulatorEntity19 extends BaseEntity19 implements AbstractSimulator
@Override
public boolean hide(Player player, boolean force) {
if (!force && referenceCounter.decrement() > 0) {
return false;
}
if (!printed) return false;
printed = false;
sendEntityDestroy(player);
ag();

Datei anzeigen

@ -501,12 +501,15 @@ SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eregion type§7 of the current region
UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again
# Simulator
SIMULATORN_NO_SIM_IN_HAND = §cNo simulator item selected
SIMULATORN_GUI_SELECT_SIM = Simulator selection
SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand
SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Change your simulator wand selection
SIMULATOR_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Create a new simulator
SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected
SIMULATOR_GUI_SELECT_SIM = Simulator selection
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists
SIMULATOR_CREATE = §aSimulator created
SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator
SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand
SIMULATOR_START_HELP = §8/§esimulator start §8-§7 Starts the simulation
SIMULATOR_GUI_HELP = §8/§esimulator gui §8-§7 Opens the simulator's gui
SIMULATOR_DELETE_HELP = §8/§esimulator delete §8-§7 Deletes all TNT

Datei anzeigen

@ -42,19 +42,30 @@ public class SimulatorCommand extends SWCommand {
@Register(description = "SIMULATOR_HELP")
public void genericCommand(@Guard Player p) {
SimulatorCursor.hide(p, null);
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
}
@Register(value = "change", description = "")
public void changeCommand(@Guard Player p) {
@Register(value = "change", description = "SIMULATOR_CHANGE_HELP")
public void change(@Guard Player p) {
ItemStack itemStack = p.getInventory().getItemInMainHand();
if (!ItemUtils.isItem(itemStack, "simulator")) {
BauSystem.MESSAGE.send("SIMULATORN_NO_SIM_IN_HAND", p);
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
return;
}
SimulatorSelectionGUI.open(p, itemStack);
}
@Register(value = "create", description = "SIMULATOR_CREATE_HELP")
public void create(@Guard Player p, String name) {
if (SimulatorStorage.getSimulatorNames().contains(name)) {
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
return;
}
SimulatorStorage.createNewSimulator(name);
BauSystem.MESSAGE.send("SIMULATOR_CREATE", p);
}
@ClassGuard(value = Player.class, local = true)
public GuardChecker guardChecker() {
return (commandSender, guardCheckType, strings, s) -> {

Datei anzeigen

@ -73,11 +73,13 @@ public class SimulatorCursor {
if (cursor != null)
cursor.hide(player, false);
tntSimulator.hide(player);
if (tntSimulator != null) {
tntSimulator.remove(player);
}
cursors.remove(player);
}
private Vector getPos(Player player, RayTraceResult result) {
public static Vector getPos(Player player, RayTraceResult result) {
Vector pos = result.getHitPosition();
BlockFace face = result.getHitBlockFace();

Datei anzeigen

@ -59,6 +59,10 @@ public class SimulatorStorage implements Enable, Disable {
private static Map<String, TNTSimulator> tntSimulators = new HashMap<>();
public static void createNewSimulator(String name) {
tntSimulators.put(name, new TNTSimulator());
}
public static Set<String> getSimulatorNames() {
return tntSimulators.keySet();
}

Datei anzeigen

@ -27,15 +27,13 @@ import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
import yapion.hierarchy.types.YAPIONArray;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Getter
@ -84,6 +82,16 @@ public class TNTSimulator {
});
}
public void remove(Player player) {
SimulatorEntityShowMode showMode = playerShowMode.remove(player);
if (showMode == null) {
return;
}
tntElementList.forEach(simulatorElement -> {
simulatorElement.hide(showMode);
});
}
public void hide(Player player, List<SimulatorElement> simulatorElements) {
SimulatorEntityShowMode showMode = playerShowMode.get(player);
if (showMode == null) {
@ -108,8 +116,41 @@ public class TNTSimulator {
public List<SimulatorElement> getEntity(Entity entity) {
List<SimulatorElement> tntSpawns = new ArrayList<>();
for (SimulatorElement spawn : tntElementList) {
spawn.getEntity(tntSpawns, new Vector(0, 0, 0), entity);
spawn.getEntity(tntSpawns, entity);
}
return tntSpawns;
}
public void edit(Player player, RayTraceResult result) {
if (result == null) {
// TODO: Open gui
return;
}
SimulatorCursor.show(player, this, result);
if (result.getHitEntity() != null) {
return;
}
/*
if (result.getHitEntity() != null) {
List<de.steamwar.bausystem.features.simulator.TNTSimulator.TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
if (tntSpawns.isEmpty()) {
return;
}
if (tntSpawns.size() == 1) {
tntSpawns.get(0).editTNT(spawns);
} else {
showGUI(new HashSet<>(tntSpawns));
}
return;
}
*/
tntElementList.add(new TNTElement(SimulatorCursor.getPos(player, result)));
playerShowMode.forEach((p, simulatorEntityShowMode) -> {
show(p);
});
}
}

Datei anzeigen

@ -26,6 +26,7 @@ import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.utils.ItemUtils;
import org.bukkit.FluidCollisionMode;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -54,6 +55,10 @@ public class TNTSimulatorListener implements Listener {
}
static RayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
if (player.getGameMode() == GameMode.SPECTATOR) {
return null;
}
Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0);
Vector direction = to.getDirection();
RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true);
@ -89,7 +94,7 @@ public class TNTSimulatorListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
simulatorShowHide(e.getPlayer(), ignore -> null, PlayerInventory::getItemInMainHand, e.getTo());
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo());
}
@EventHandler
@ -99,9 +104,7 @@ public class TNTSimulatorListener implements Listener {
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
if (oldSimulator != null) {
SimulatorCursor.hide(player, oldSimulator);
}
SimulatorCursor.hide(player, oldSimulator);
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
if (simulator == null) {
@ -136,9 +139,8 @@ public class TNTSimulatorListener implements Listener {
if (simulator == null) {
SimulatorSelectionGUI.open(event.getPlayer(), event.getItem());
} else {
simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator));
}
// get(event.getPlayer()).edit(trace(event.getPlayer(), event.getPlayer().getLocation()));
break;
default:
break;

Datei anzeigen

@ -43,9 +43,14 @@ public class SimulatorSelectionGUI {
swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator));
}
SWListInv<TNTSimulator> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATORN_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> {
SWListInv<TNTSimulator> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> {
TNTSimulator current = SimulatorStorage.getSimulator(hand);
if (current != null) {
current.remove(player);
}
SimulatorStorage.setSimulator(hand, tntSimulator);
player.getInventory().setItemInMainHand(hand);
player.closeInventory();
});
// TODO: Add button to create new simulator with AnvilGUI

Datei anzeigen

@ -25,8 +25,6 @@ import de.steamwar.bausystem.shared.Position;
import de.steamwar.bausystem.shared.RoundedPosition;
import de.steamwar.bausystem.shared.ShowMode;
import de.steamwar.bausystem.utils.NMSWrapper;
import org.bukkit.World;
import org.bukkit.entity.Panda;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

Datei anzeigen

@ -33,7 +33,7 @@ public interface SimulatorElement {
YAPIONObject toYAPION();
List<Entity> getEntities();
void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity);
void getEntity(List<SimulatorElement> elements, Entity entity);
default Vector getPosition() {
return new Vector(0, 0, 0);
}
@ -42,5 +42,5 @@ public interface SimulatorElement {
void hide(SimulatorEntityShowMode showMode);
ItemStack menu();
void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result, Vector origin, int tickOffset); // Ticks to subtick order to spawning runnable to count of activations
void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result); // Ticks to subtick order to spawning runnable to count of activations
}

Datei anzeigen

@ -24,9 +24,9 @@ import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.shared.Position;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
@ -37,9 +37,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
public class TNTElement implements SimulatorElement {
private final AbstractSimulatorEntity entity;
TNTGroup tntGroup = null;
private final Vector position;
private int fuseTicks = 80;
@ -92,25 +94,35 @@ public class TNTElement implements SimulatorElement {
}
@Override
public void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity) {
if (this.entity.getId() == entity.getEntityId() || position.clone().add(origin).equals(entity.getLocation().toVector())) {
public void getEntity(List<SimulatorElement> elements, Entity entity) {
if (this.entity.getId() == entity.getEntityId() || getPosition().equals(entity.getLocation().toVector())) {
elements.add(this);
}
}
@Override
public Vector getPosition() {
if (tntGroup != null) {
return tntGroup.getPosition().clone().add(position);
}
return position.clone();
}
protected int getTickOffset() {
if (tntGroup != null) {
return tntGroup.getTickOffset() + tickOffset;
}
return tickOffset;
}
@Override
public void show(SimulatorEntityShowMode showMode) {
showMode.show(new Position(position));
showMode.show(new Position(getPosition()));
}
@Override
public void hide(SimulatorEntityShowMode showMode) {
showMode.hide();
showMode.hide(new Position(getPosition()));
}
@Override
@ -119,10 +131,10 @@ public class TNTElement implements SimulatorElement {
}
@Override
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result, Vector origin, int tickOffset) {
result.computeIfAbsent(this.tickOffset + tickOffset, ignore -> new HashMap<>())
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
result.computeIfAbsent(getTickOffset(), ignore -> new HashMap<>())
.computeIfAbsent(order, ignore -> new Pair<>(() -> {
SimulatorStorage.WORLD.spawn(position.clone().add(origin).toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> {
SimulatorStorage.WORLD.spawn(getPosition().toLocation(SimulatorStorage.WORLD), TNTPrimed.class, tntPrimed -> {
tntPrimed.setFuseTicks(fuseTicks);
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn.tnt;
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
import de.steamwar.bausystem.shared.Pair;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
@ -33,6 +34,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Getter
public class TNTGroup implements SimulatorElement {
private final Vector position;
@ -50,7 +52,9 @@ public class TNTGroup implements SimulatorElement {
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
this.elements.add(new TNTElement(element));
TNTElement tntElement = new TNTElement(element);
tntElement.tntGroup = this;
this.elements.add(tntElement);
}
}
@ -76,9 +80,9 @@ public class TNTGroup implements SimulatorElement {
}
@Override
public void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity) {
public void getEntity(List<SimulatorElement> elements, Entity entity) {
for (TNTElement tntElement : this.elements) {
tntElement.getEntity(elements, origin, entity);
tntElement.getEntity(elements, entity);
}
}
@ -102,9 +106,9 @@ public class TNTGroup implements SimulatorElement {
}
@Override
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result, Vector origin, int tickOffset) {
public void locations(Map<Integer, Map<Integer, Pair<Runnable, Integer>>> result) {
elements.forEach(tntElement -> {
tntElement.locations(result, origin.clone().add(position), this.tickOffset + tickOffset);
tntElement.locations(result);
});
}
}