Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
bb7d543658
Commit
c4f1b4f01a
@ -64,6 +64,9 @@ public class SimulatorStorage implements Enable, Disable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static TNTSimulator getSimulator(ItemStack itemStack) {
|
public static TNTSimulator getSimulator(ItemStack itemStack) {
|
||||||
|
if (itemStack == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -74,6 +77,29 @@ public class SimulatorStorage implements Enable, Disable {
|
|||||||
return tntSimulators.get(selection);
|
return tntSimulators.get(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setSimulator(ItemStack itemStack, TNTSimulator simulator) {
|
||||||
|
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
||||||
|
if (entry.getValue() == simulator) {
|
||||||
|
ItemUtils.setTag(itemStack, simulatorSelection, entry.getKey());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSimulator(ItemStack itemStack, String name) {
|
||||||
|
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemUtils.setTag(itemStack, simulatorSelection, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeSimulator(ItemStack itemStack) {
|
||||||
|
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemUtils.setTag(itemStack, simulatorSelection, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static ItemStack getWand(Player p) {
|
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();
|
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");
|
ItemUtils.setItem(itemStack, "simulator");
|
||||||
|
@ -22,7 +22,11 @@ package de.steamwar.bausystem.features.simulatorn;
|
|||||||
import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement;
|
import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement;
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTGroup;
|
import de.steamwar.bausystem.features.simulatorn.tnt.TNTGroup;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.util.RayTraceResult;
|
||||||
import yapion.hierarchy.types.YAPIONArray;
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.hierarchy.types.YAPIONType;
|
import yapion.hierarchy.types.YAPIONType;
|
||||||
@ -31,6 +35,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TNTSimulator {
|
public class TNTSimulator {
|
||||||
|
|
||||||
private Material material = Material.TNT;
|
private Material material = Material.TNT;
|
||||||
@ -63,4 +68,16 @@ public class TNTSimulator {
|
|||||||
yapionObject.add("tntElements", yapionArray);
|
yapionObject.add("tntElements", yapionArray);
|
||||||
return yapionObject;
|
return yapionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hide(Player player) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(Player player, RayTraceResult rayTraceResult) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Entity> getEntities() {
|
||||||
|
return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.simulatorn;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
|
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.Location;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
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;
|
||||||
|
import org.bukkit.util.RayTraceResult;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static RayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
Entity nearestHitEntity = null;
|
||||||
|
RayTraceResult nearestHitResult = null;
|
||||||
|
double nearestDistanceSq = Double.MAX_VALUE;
|
||||||
|
for (Entity entity : simulator.getEntities()) {
|
||||||
|
BoundingBox boundingBox = entity.getBoundingBox();
|
||||||
|
RayTraceResult hitResult = boundingBox.rayTrace(startPos.toVector(), direction, 10.0);
|
||||||
|
if (hitResult != null) {
|
||||||
|
double distanceSq = startPos.toVector().distanceSquared(hitResult.getHitPosition());
|
||||||
|
if (distanceSq < nearestDistanceSq) {
|
||||||
|
nearestHitEntity = entity;
|
||||||
|
nearestHitResult = hitResult;
|
||||||
|
nearestDistanceSq = distanceSq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RayTraceResult entities = nearestHitEntity == null ? null : new RayTraceResult(nearestHitResult.getHitPosition(), nearestHitEntity, nearestHitResult.getHitBlockFace());
|
||||||
|
|
||||||
|
if (blocks == null) {
|
||||||
|
return entities;
|
||||||
|
} else if (entities == null) {
|
||||||
|
return blocks;
|
||||||
|
} else {
|
||||||
|
Vector startVec = startPos.toVector();
|
||||||
|
double blockHitDistance = startVec.distance(blocks.getHitPosition());
|
||||||
|
double entityHitDistanceSquared = startVec.distanceSquared(entities.getHitPosition());
|
||||||
|
return entityHitDistanceSquared < blockHitDistance * blockHitDistance ? entities : blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent e) {
|
||||||
|
simulatorShowHide(e.getPlayer(), ignore -> null, PlayerInventory::getItemInMainHand, e.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
||||||
|
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getPreviousSlot()), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
oldSimulator.hide(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
||||||
|
if (simulator == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
simulator.show(player, trace(player, location, simulator));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (!permissionCheck(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.simulatorn.gui;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
||||||
|
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
|
||||||
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.inventory.SWListInv;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class SimulatorSelectionGUI {
|
||||||
|
|
||||||
|
public void open(Player player, ItemStack hand) {
|
||||||
|
List<SWListInv.SWListEntry<TNTSimulator>> swListEntryList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String name : SimulatorStorage.getSimulatorNames()) {
|
||||||
|
TNTSimulator simulator = SimulatorStorage.getSimulator(name);
|
||||||
|
SWItem swItem = new SWItem(simulator.getMaterial(), name, new ArrayList<>(), false, null);
|
||||||
|
swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator));
|
||||||
|
}
|
||||||
|
|
||||||
|
SWListInv<TNTSimulator> inv = new SWListInv<>(player, "§6Simulatorauswahl", false, swListEntryList, (clickType, tntSimulator) -> {
|
||||||
|
SimulatorStorage.setSimulator(hand, tntSimulator);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: Add button to create new simulator with AnvilGUI
|
||||||
|
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
}
|
@ -20,16 +20,19 @@
|
|||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulatorn.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public interface SimulatorElement {
|
public interface SimulatorElement {
|
||||||
|
|
||||||
YAPIONObject toYAPION();
|
YAPIONObject toYAPION();
|
||||||
|
List<Entity> getEntities();
|
||||||
|
|
||||||
void show(Player player);
|
void show(Player player);
|
||||||
void hide(Player player);
|
void hide(Player player);
|
||||||
|
@ -24,13 +24,16 @@ import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
|||||||
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
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.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TNTElement implements SimulatorElement {
|
public class TNTElement implements SimulatorElement {
|
||||||
@ -82,6 +85,11 @@ public class TNTElement implements SimulatorElement {
|
|||||||
return yapionObject;
|
return yapionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Entity> getEntities() {
|
||||||
|
return Arrays.asList(entity.getBukkitEntity());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(Player player) {
|
public void show(Player player) {
|
||||||
entity.sendEntity(player);
|
entity.sendEntity(player);
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn.tnt;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
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.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
@ -69,6 +70,11 @@ public class TNTGroup implements SimulatorElement {
|
|||||||
return yapionObject;
|
return yapionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Entity> getEntities() {
|
||||||
|
return elements.stream().flatMap(tntElement -> tntElement.getEntities().stream()).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(Player player) {
|
public void show(Player player) {
|
||||||
elements.forEach(tntElement -> {
|
elements.forEach(tntElement -> {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren