From 6ed13702d4869b5e683e068528b16d38509725cd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Jun 2022 16:28:06 +0200 Subject: [PATCH] Add SimulatorCursor Add SimulatorCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 4 + .../simulator/SimulatorBauGuiItem.java | 2 +- .../features/simulator/SimulatorCommand.java | 2 +- .../simulator/TNTSimulatorListener.java | 4 +- .../features/simulatorn/SimulatorCommand.java | 71 +++++++++++ .../features/simulatorn/SimulatorCursor.java | 119 ++++++++++++++++++ .../features/simulatorn/SimulatorStorage.java | 32 ++++- .../features/simulatorn/TNTSimulator.java | 38 +++++- .../simulatorn/TNTSimulatorListener.java | 30 ++++- .../simulatorn/gui/SimulatorSelectionGUI.java | 6 +- .../show/SimulatorEntityShowMode.java | 12 ++ .../simulatorn/tnt/SimulatorElement.java | 10 +- .../features/simulatorn/tnt/TNTElement.java | 25 +++- .../features/simulatorn/tnt/TNTGroup.java | 17 ++- .../steamwar/bausystem/utils/ItemUtils.java | 2 +- 15 files changed, 344 insertions(+), 30 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 5e1e9335..f7833bbe 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -501,6 +501,10 @@ 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_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 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java index 850b0fdd..29f0030c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorBauGuiItem.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; -@Linked(LinkageType.BAU_GUI_ITEM) +// @Linked(LinkageType.BAU_GUI_ITEM) public class SimulatorBauGuiItem extends BauGuiItem { public SimulatorBauGuiItem() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index 2291ee42..ce9d3bc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -37,7 +37,7 @@ import org.bukkit.entity.Player; import java.util.List; -@Linked(LinkageType.COMMAND) +// @Linked(LinkageType.COMMAND) public class SimulatorCommand extends SWCommand { public SimulatorCommand() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index 8bbb3711..206f7419 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -47,8 +47,8 @@ import java.util.function.Function; import static de.steamwar.bausystem.features.simulator.TNTSimulator.get; -@Linked(LinkageType.LISTENER) -@Linked(LinkageType.DISABLE_LINK) +// @Linked(LinkageType.LISTENER) +// @Linked(LinkageType.DISABLE_LINK) public class TNTSimulatorListener implements Listener, Disable { private boolean permissionCheck(Player player) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java new file mode 100644 index 00000000..54435365 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCommand.java @@ -0,0 +1,71 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.simulatorn; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.simulatorn.gui.SimulatorSelectionGUI; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.command.GuardCheckType; +import de.steamwar.command.GuardChecker; +import de.steamwar.command.GuardResult; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +@Linked(LinkageType.COMMAND) +public class SimulatorCommand extends SWCommand { + + public SimulatorCommand() { + super("simulator", "sim"); + } + + @Register(description = "SIMULATOR_HELP") + public void genericCommand(@Guard Player p) { + SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p)); + } + + @Register(value = "change", description = "") + public void changeCommand(@Guard Player p) { + ItemStack itemStack = p.getInventory().getItemInMainHand(); + if (!ItemUtils.isItem(itemStack, "simulator")) { + BauSystem.MESSAGE.send("SIMULATORN_NO_SIM_IN_HAND", p); + return; + } + SimulatorSelectionGUI.open(p, itemStack); + } + + @ClassGuard(value = Player.class, local = true) + public GuardChecker guardChecker() { + return (commandSender, guardCheckType, strings, s) -> { + Player player = (Player) commandSender; + if (Permission.hasPermission(player, Permission.WORLD)) { + return GuardResult.ALLOWED; + } + if (guardCheckType != GuardCheckType.TAB_COMPLETE) { + BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player); + } + return GuardResult.DENIED; + }; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java new file mode 100644 index 00000000..7136e7c3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorCursor.java @@ -0,0 +1,119 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.simulatorn; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; +import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; +import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement; +import lombok.experimental.UtilityClass; +import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.util.RayTraceResult; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@UtilityClass +public class SimulatorCursor { + + private Map cursors = new HashMap<>(); + + public void show(Player player, TNTSimulator tntSimulator, RayTraceResult result) { + AbstractSimulatorEntity cursor = cursors.get(player); + + if (cursor != null) + cursor.hide(player, false); + + tntSimulator.show(player); + + if (result == null) + return; + + if (result.getHitEntity() != null) { + List elements = tntSimulator.getEntity(result.getHitEntity()); + tntSimulator.hide(player, elements); + + cursor = SimulatorEntityShowMode.createEntity(player, elements.isEmpty() ? getPos(player, result) : elements.get(0).getPosition(), true); + cursor.display(player); + cursors.put(player, cursor); + BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR); + return; + } + + cursor = SimulatorEntityShowMode.createEntity(player, getPos(player, result), false); + cursor.display(player); + cursors.put(player, cursor); + BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_ADD", player, ChatMessageType.ACTION_BAR); + } + + public void hide(Player player, TNTSimulator tntSimulator) { + AbstractSimulatorEntity cursor = cursors.get(player); + + if (cursor != null) + cursor.hide(player, false); + + tntSimulator.hide(player); + cursors.remove(player); + } + + private Vector getPos(Player player, RayTraceResult result) { + Vector pos = result.getHitPosition(); + + BlockFace face = result.getHitBlockFace(); + if (face != null) { + switch (face) { + case DOWN: + pos.setY(pos.getY() - 0.98); + break; + case EAST: + pos.setX(pos.getX() + 0.49); + break; + case WEST: + pos.setX(pos.getX() - 0.49); + break; + case NORTH: + pos.setZ(pos.getZ() - 0.49); + break; + case SOUTH: + pos.setZ(pos.getZ() + 0.49); + break; + default: + break; + } + + if (face.getModY() == 0 && player.isSneaking()) { + pos.setY(pos.getY() - 0.49); + } + } + + if (!player.isSneaking()) { + pos.setX(pos.getBlockX() + 0.5); + if (face == null || face.getModY() == 0) + pos.setY(pos.getBlockY() + 0.0); + pos.setZ(pos.getBlockZ() + 0.5); + } + + return pos; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java index 110f4129..bf54be8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java @@ -21,12 +21,14 @@ package de.steamwar.bausystem.features.simulatorn; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; +import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement; import de.steamwar.bausystem.linkage.Disable; import de.steamwar.bausystem.linkage.Enable; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.inventory.SWItem; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -34,6 +36,7 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import yapion.exceptions.YAPIONException; +import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.parser.YAPIONParser; @@ -43,6 +46,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; @Linked(LinkageType.ENABLE_LINK) @Linked(LinkageType.DISABLE_LINK) @@ -122,7 +126,9 @@ public class SimulatorStorage implements Enable, Disable { continue; } if (file.getName().endsWith(".yapion")) { - // TODO: Load old simulators + String name = file.getName().substring(0, file.getName().length() - 7); + SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name)); + convert(file, steamwarUser); } else { String name = file.getName().substring(0, file.getName().length() - ".simulator".length()); tntSimulators.put(name, new TNTSimulator(yapionObject)); @@ -130,6 +136,30 @@ public class SimulatorStorage implements Enable, Disable { } } + private static void convert(File file, SteamwarUser steamwarUser) { + YAPIONObject yapionObject; + try { + yapionObject = YAPIONParser.parse(file); + } catch (YAPIONException | IOException e) { + return; + } + try { + file.delete(); + } catch (Exception e) { + e.printStackTrace(); + } + for (String s : yapionObject.getKeys()) { + String newName = steamwarUser.getUserName() + (s.isEmpty() ? "" : "_" + s); + YAPIONArray content = yapionObject.getArray(s); + if (content.isEmpty()) continue; + TNTSimulator tntSimulator = new TNTSimulator(); + for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) { + tntSimulator.getTntElementList().add(new TNTElement(element)); + } + tntSimulators.put(newName, tntSimulator); + } + } + @Override public void disable() { for (Map.Entry entry : tntSimulators.entrySet()) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java index 580808b2..1ab1cbf2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulatorn; +import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement; import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement; import de.steamwar.bausystem.features.simulatorn.tnt.TNTGroup; @@ -26,18 +27,22 @@ 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.stream.Collectors; @Getter public class TNTSimulator { + private Map playerShowMode = new HashMap<>(); + private Material material = Material.TNT; private List tntElementList = new ArrayList<>(); @@ -70,14 +75,41 @@ public class TNTSimulator { } public void hide(Player player) { - + SimulatorEntityShowMode showMode = playerShowMode.get(player); + if (showMode == null) { + return; + } + tntElementList.forEach(simulatorElement -> { + simulatorElement.hide(showMode); + }); } - public void show(Player player, RayTraceResult rayTraceResult) { + public void hide(Player player, List simulatorElements) { + SimulatorEntityShowMode showMode = playerShowMode.get(player); + if (showMode == null) { + return; + } + simulatorElements.forEach(simulatorElement -> { + simulatorElement.hide(showMode); + }); + } + public void show(Player player) { + SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new); + tntElementList.forEach(simulatorElement -> { + simulatorElement.show(showMode); + }); } public List getEntities() { return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList()); } + + public List getEntity(Entity entity) { + List tntSpawns = new ArrayList<>(); + for (SimulatorElement spawn : tntElementList) { + spawn.getEntity(tntSpawns, new Vector(0, 0, 0), entity); + } + return tntSpawns; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java index 9292b1b1..060718a3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulatorListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.features.simulatorn.gui.SimulatorSelectionGUI; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ItemUtils; @@ -33,7 +34,6 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.util.BoundingBox; @@ -42,8 +42,6 @@ import org.bukkit.util.Vector; import java.util.function.Function; -import static de.steamwar.bausystem.features.simulator.TNTSimulator.get; - @Linked(LinkageType.LISTENER) public class TNTSimulatorListener implements Listener { @@ -102,7 +100,7 @@ public class TNTSimulatorListener implements Listener { private void simulatorShowHide(Player player, Function oldItemFunction, Function newItemFunction, Location location) { TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory())); if (oldSimulator != null) { - oldSimulator.hide(player); + SimulatorCursor.hide(player, oldSimulator); } TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory())); @@ -110,7 +108,7 @@ public class TNTSimulatorListener implements Listener { return; } - simulator.show(player, trace(player, location, simulator)); + SimulatorCursor.show(player, simulator, trace(player, location, simulator)); } @EventHandler @@ -123,5 +121,27 @@ public class TNTSimulatorListener implements Listener { if (!permissionCheck(event.getPlayer())) { return; } + TNTSimulator simulator = SimulatorStorage.getSimulator(event.getItem()); + + switch (event.getAction()) { + case LEFT_CLICK_BLOCK: + case LEFT_CLICK_AIR: + if (simulator == null) { + return; + } + System.out.println("Left click"); + break; + case RIGHT_CLICK_BLOCK: + case RIGHT_CLICK_AIR: + if (simulator == null) { + SimulatorSelectionGUI.open(event.getPlayer(), event.getItem()); + } else { + + } + // get(event.getPlayer()).edit(trace(event.getPlayer(), event.getPlayer().getLocation())); + break; + default: + break; + } } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java index c0088329..72e1c75e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/gui/SimulatorSelectionGUI.java @@ -19,6 +19,7 @@ package de.steamwar.bausystem.features.simulatorn.gui; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.simulatorn.SimulatorStorage; import de.steamwar.bausystem.features.simulatorn.TNTSimulator; import de.steamwar.inventory.SWItem; @@ -38,12 +39,13 @@ public class SimulatorSelectionGUI { for (String name : SimulatorStorage.getSimulatorNames()) { TNTSimulator simulator = SimulatorStorage.getSimulator(name); - SWItem swItem = new SWItem(simulator.getMaterial(), name, new ArrayList<>(), false, null); + SWItem swItem = new SWItem(simulator.getMaterial(), "§f" + name, new ArrayList<>(), false, null); swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator)); } - SWListInv inv = new SWListInv<>(player, "§6Simulatorauswahl", false, swListEntryList, (clickType, tntSimulator) -> { + SWListInv inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATORN_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> { SimulatorStorage.setSimulator(hand, tntSimulator); + player.getInventory().setItemInMainHand(hand); }); // TODO: Add button to create new simulator with AnvilGUI diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java index 2ce67b26..a88c8bbc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/show/SimulatorEntityShowMode.java @@ -26,6 +26,7 @@ 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; @@ -53,6 +54,17 @@ public class SimulatorEntityShowMode implements ShowMode { return NMSWrapper.impl.createSimulator(SimulatorStorage.WORLD, position, highlight); } + public void hide(Position position) { + RoundedPosition roundedPosition = new RoundedPosition(position); + AbstractSimulatorEntity abstractSimulatorEntity = entityMap.get(roundedPosition); + if (abstractSimulatorEntity == null) { + return; + } + if (abstractSimulatorEntity.hide(player, false)) { + entityMap.remove(roundedPosition); + } + } + @Override public void hide() { entityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java index f389c75a..7c3f42cc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java @@ -19,9 +19,9 @@ package de.steamwar.bausystem.features.simulatorn.tnt; +import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONObject; @@ -33,9 +33,13 @@ public interface SimulatorElement { YAPIONObject toYAPION(); List getEntities(); + void getEntity(List elements, Vector origin, Entity entity); + default Vector getPosition() { + return new Vector(0, 0, 0); + } - void show(Player player); - void hide(Player player); + void show(SimulatorEntityShowMode showMode); + void hide(SimulatorEntityShowMode showMode); ItemStack menu(); void locations(Map>> result, Vector origin, int tickOffset); // Ticks to subtick order to spawning runnable to count of activations diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java index 6372a339..c7645c30 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; 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 org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -56,7 +57,7 @@ public class TNTElement implements SimulatorElement { } public TNTElement(YAPIONObject yapionObject) { - this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 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.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80); this.count = yapionObject.getIntOrDefault("count", 1); @@ -64,7 +65,7 @@ public class TNTElement implements SimulatorElement { this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false); this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false); this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", false); - this.order = yapionObject.getIntOrDefault("order", 0); + this.order = yapionObject.getIntOrDefault("order", yapionObject.getBooleanOrDefault("comparator", false) ? 1 : 0); this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name())); } @@ -91,13 +92,25 @@ public class TNTElement implements SimulatorElement { } @Override - public void show(Player player) { - entity.sendEntity(player); + public void getEntity(List elements, Vector origin, Entity entity) { + if (this.entity.getId() == entity.getEntityId() || position.clone().add(origin).equals(entity.getLocation().toVector())) { + elements.add(this); + } } @Override - public void hide(Player player) { - entity.hide(player, true); + public Vector getPosition() { + return position.clone(); + } + + @Override + public void show(SimulatorEntityShowMode showMode) { + showMode.show(new Position(position)); + } + + @Override + public void hide(SimulatorEntityShowMode showMode) { + showMode.hide(); } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java index 8d960f65..1f46be25 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java @@ -19,10 +19,10 @@ package de.steamwar.bausystem.features.simulatorn.tnt; +import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode; import de.steamwar.bausystem.shared.Pair; import org.bukkit.Material; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import yapion.hierarchy.types.YAPIONArray; @@ -76,16 +76,23 @@ public class TNTGroup implements SimulatorElement { } @Override - public void show(Player player) { + public void getEntity(List elements, Vector origin, Entity entity) { + for (TNTElement tntElement : this.elements) { + tntElement.getEntity(elements, origin, entity); + } + } + + @Override + public void show(SimulatorEntityShowMode showMode) { elements.forEach(tntElement -> { - tntElement.show(player); + tntElement.show(showMode); }); } @Override - public void hide(Player player) { + public void hide(SimulatorEntityShowMode showMode) { elements.forEach(tntElement -> { - tntElement.hide(player); + tntElement.hide(showMode); }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java index a815be80..9c71993c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java @@ -53,7 +53,7 @@ public class ItemUtils { if (!container.has(key, PersistentDataType.STRING)) { return null; } - return container.get(ITEM_KEY, PersistentDataType.STRING); + return container.get(key, PersistentDataType.STRING); } public void setTag(ItemStack itemStack, NamespacedKey key, String value) {