diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java new file mode 100644 index 00000000..77c5efb3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/SimulatorStorage.java @@ -0,0 +1,82 @@ +/* + * 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.SWUtils; +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 org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +@Linked(LinkageType.ENABLE_LINK) +@Linked(LinkageType.DISABLE_LINK) +public class SimulatorStorage implements Enable, Disable { + + private static NamespacedKey simulatorSelection = SWUtils.getNamespaceKey("simulator_selection"); + + private static Map tntSimulators = new HashMap<>(); + + public static Set getSimulatorNames() { + return tntSimulators.keySet(); + } + + public static TNTSimulator getSimulator(String name) { + return tntSimulators.get(name); + } + + public static TNTSimulator getSimulator(ItemStack itemStack) { + if (!ItemUtils.isItem(itemStack, "simulator")) { + return null; + } + String selection = ItemUtils.getTag(itemStack, simulatorSelection); + if (selection == null) { + return null; + } + return tntSimulators.get(selection); + } + + public static ItemStack getWand(Player p) { + ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_1", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_2", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_3", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_4", p)), false, null).getItemStack(); + ItemUtils.setItem(itemStack, "simulator"); + return itemStack; + } + + @Override + public void enable() { + + } + + @Override + public void disable() { + + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java new file mode 100644 index 00000000..8e61e360 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/TNTSimulator.java @@ -0,0 +1,27 @@ +/* + * 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 org.bukkit.Material; + +public class TNTSimulator { + + private Material material; +} 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 new file mode 100644 index 00000000..2e6feb7e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/SimulatorElement.java @@ -0,0 +1,37 @@ +/* + * 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.tnt; + +import de.steamwar.bausystem.shared.Pair; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.Map; + +public interface SimulatorElement { + + void show(Player player); + void hide(Player player); + + ItemStack menu(); + void locations(Map>> result, Vector origin, int tickOffset, World world); // 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 new file mode 100644 index 00000000..1b32d622 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTElement.java @@ -0,0 +1,80 @@ +/* + * 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.tnt; + +import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity; +import de.steamwar.bausystem.shared.Pair; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.Map; + +public class TNTElement implements SimulatorElement { + + private final AbstractSimulatorEntity entity; + + private final Vector position; + private int fuseTicks = 80; + private int count = 1; + private int tickOffset = 0; + private boolean xVelocity = false; + private boolean yVelocity = false; + private boolean zVelocity = false; + private int order = 0; + private Material material = Material.TNT; + + public TNTElement(Vector position, AbstractSimulatorEntity entity) { + this.position = position; + this.entity = entity; + } + + @Override + public void show(Player player) { + entity.sendEntity(player); + } + + @Override + public void hide(Player player) { + entity.hide(player, true); + } + + @Override + public ItemStack menu() { + return null; + } + + @Override + public void locations(Map>> result, Vector origin, int tickOffset, World world) { + result.computeIfAbsent(this.tickOffset + tickOffset, ignore -> new HashMap<>()) + .computeIfAbsent(order, ignore -> new Pair<>(() -> { + world.spawn(position.clone().add(origin).toLocation(world), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); + if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); + if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); + if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); + }); + }, count)); + } +} 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 new file mode 100644 index 00000000..a8626030 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulatorn/tnt/TNTGroup.java @@ -0,0 +1,69 @@ +/* + * 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.tnt; + +import de.steamwar.bausystem.shared.Pair; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TNTGroup implements SimulatorElement { + + private final Vector position; + private int tickOffset = 0; + private Material material = Material.BARREL; + private List elements = new ArrayList<>(); + + public TNTGroup(Vector position) { + this.position = position; + } + + @Override + public void show(Player player) { + elements.forEach(tntElement -> { + tntElement.show(player); + }); + } + + @Override + public void hide(Player player) { + elements.forEach(tntElement -> { + tntElement.hide(player); + }); + } + + @Override + public ItemStack menu() { + return null; + } + + @Override + public void locations(Map>> result, Vector origin, int tickOffset, World world) { + elements.forEach(tntElement -> { + tntElement.locations(result, origin.clone().add(position), this.tickOffset + tickOffset, world); + }); + } +}