Add SimulatorCommand Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
c4f1b4f01a
Commit
6ed13702d4
@ -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
|
UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again
|
||||||
|
|
||||||
# Simulator
|
# Simulator
|
||||||
|
SIMULATORN_NO_SIM_IN_HAND = §cNo simulator item selected
|
||||||
|
SIMULATORN_GUI_SELECT_SIM = Simulator selection
|
||||||
|
|
||||||
|
|
||||||
SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator
|
SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator
|
||||||
SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand
|
SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand
|
||||||
SIMULATOR_START_HELP = §8/§esimulator start §8-§7 Starts the simulation
|
SIMULATOR_START_HELP = §8/§esimulator start §8-§7 Starts the simulation
|
||||||
|
@ -30,7 +30,7 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@Linked(LinkageType.BAU_GUI_ITEM)
|
// @Linked(LinkageType.BAU_GUI_ITEM)
|
||||||
public class SimulatorBauGuiItem extends BauGuiItem {
|
public class SimulatorBauGuiItem extends BauGuiItem {
|
||||||
|
|
||||||
public SimulatorBauGuiItem() {
|
public SimulatorBauGuiItem() {
|
||||||
|
@ -37,7 +37,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Linked(LinkageType.COMMAND)
|
// @Linked(LinkageType.COMMAND)
|
||||||
public class SimulatorCommand extends SWCommand {
|
public class SimulatorCommand extends SWCommand {
|
||||||
|
|
||||||
public SimulatorCommand() {
|
public SimulatorCommand() {
|
||||||
|
@ -47,8 +47,8 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.TNTSimulator.get;
|
import static de.steamwar.bausystem.features.simulator.TNTSimulator.get;
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
// @Linked(LinkageType.LISTENER)
|
||||||
@Linked(LinkageType.DISABLE_LINK)
|
// @Linked(LinkageType.DISABLE_LINK)
|
||||||
public class TNTSimulatorListener implements Listener, Disable {
|
public class TNTSimulatorListener implements Listener, Disable {
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
private boolean permissionCheck(Player player) {
|
||||||
|
@ -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 <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.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;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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<Player, AbstractSimulatorEntity> 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<SimulatorElement> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -21,12 +21,14 @@ package de.steamwar.bausystem.features.simulatorn;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.linkage.Disable;
|
import de.steamwar.bausystem.linkage.Disable;
|
||||||
import de.steamwar.bausystem.linkage.Enable;
|
import de.steamwar.bausystem.linkage.Enable;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@ -34,6 +36,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import yapion.exceptions.YAPIONException;
|
import yapion.exceptions.YAPIONException;
|
||||||
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
import yapion.parser.YAPIONParser;
|
import yapion.parser.YAPIONParser;
|
||||||
|
|
||||||
@ -43,6 +46,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Linked(LinkageType.ENABLE_LINK)
|
@Linked(LinkageType.ENABLE_LINK)
|
||||||
@Linked(LinkageType.DISABLE_LINK)
|
@Linked(LinkageType.DISABLE_LINK)
|
||||||
@ -122,7 +126,9 @@ public class SimulatorStorage implements Enable, Disable {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (file.getName().endsWith(".yapion")) {
|
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 {
|
} else {
|
||||||
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
String name = file.getName().substring(0, file.getName().length() - ".simulator".length());
|
||||||
tntSimulators.put(name, new TNTSimulator(yapionObject));
|
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
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
for (Map.Entry<String, TNTSimulator> entry : tntSimulators.entrySet()) {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn;
|
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.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;
|
||||||
@ -26,18 +27,22 @@ import lombok.Getter;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.RayTraceResult;
|
import org.bukkit.util.Vector;
|
||||||
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;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class TNTSimulator {
|
public class TNTSimulator {
|
||||||
|
|
||||||
|
private Map<Player, SimulatorEntityShowMode> playerShowMode = new HashMap<>();
|
||||||
|
|
||||||
private Material material = Material.TNT;
|
private Material material = Material.TNT;
|
||||||
|
|
||||||
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
||||||
@ -70,14 +75,41 @@ public class TNTSimulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void hide(Player player) {
|
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<SimulatorElement> 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<Entity> getEntities() {
|
public List<Entity> 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) {
|
||||||
|
List<SimulatorElement> tntSpawns = new ArrayList<>();
|
||||||
|
for (SimulatorElement spawn : tntElementList) {
|
||||||
|
spawn.getEntity(tntSpawns, new Vector(0, 0, 0), entity);
|
||||||
|
}
|
||||||
|
return tntSpawns;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulatorn;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
|
import de.steamwar.bausystem.features.simulatorn.gui.SimulatorSelectionGUI;
|
||||||
import de.steamwar.bausystem.linkage.LinkageType;
|
import de.steamwar.bausystem.linkage.LinkageType;
|
||||||
import de.steamwar.bausystem.linkage.Linked;
|
import de.steamwar.bausystem.linkage.Linked;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
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.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
@ -42,8 +42,6 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static de.steamwar.bausystem.features.simulator.TNTSimulator.get;
|
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
@Linked(LinkageType.LISTENER)
|
||||||
public class TNTSimulatorListener implements Listener {
|
public class TNTSimulatorListener implements Listener {
|
||||||
|
|
||||||
@ -102,7 +100,7 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
|
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
|
||||||
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
|
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
|
||||||
if (oldSimulator != null) {
|
if (oldSimulator != null) {
|
||||||
oldSimulator.hide(player);
|
SimulatorCursor.hide(player, oldSimulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
||||||
@ -110,7 +108,7 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator.show(player, trace(player, location, simulator));
|
SimulatorCursor.show(player, simulator, trace(player, location, simulator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -123,5 +121,27 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
if (!permissionCheck(event.getPlayer())) {
|
if (!permissionCheck(event.getPlayer())) {
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.gui;
|
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.SimulatorStorage;
|
||||||
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
|
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
@ -38,12 +39,13 @@ public class SimulatorSelectionGUI {
|
|||||||
|
|
||||||
for (String name : SimulatorStorage.getSimulatorNames()) {
|
for (String name : SimulatorStorage.getSimulatorNames()) {
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(name);
|
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));
|
swListEntryList.add(new SWListInv.SWListEntry<>(swItem, simulator));
|
||||||
}
|
}
|
||||||
|
|
||||||
SWListInv<TNTSimulator> inv = new SWListInv<>(player, "§6Simulatorauswahl", false, swListEntryList, (clickType, tntSimulator) -> {
|
SWListInv<TNTSimulator> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATORN_GUI_SELECT_SIM", player), false, swListEntryList, (clickType, tntSimulator) -> {
|
||||||
SimulatorStorage.setSimulator(hand, tntSimulator);
|
SimulatorStorage.setSimulator(hand, tntSimulator);
|
||||||
|
player.getInventory().setItemInMainHand(hand);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Add button to create new simulator with AnvilGUI
|
// TODO: Add button to create new simulator with AnvilGUI
|
||||||
|
@ -26,6 +26,7 @@ import de.steamwar.bausystem.shared.RoundedPosition;
|
|||||||
import de.steamwar.bausystem.shared.ShowMode;
|
import de.steamwar.bausystem.shared.ShowMode;
|
||||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
import de.steamwar.bausystem.utils.NMSWrapper;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Panda;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@ -53,6 +54,17 @@ public class SimulatorEntityShowMode implements ShowMode<Position> {
|
|||||||
return NMSWrapper.impl.createSimulator(SimulatorStorage.WORLD, position, highlight);
|
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
|
@Override
|
||||||
public void hide() {
|
public void hide() {
|
||||||
entityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
entityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulatorn.tnt;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
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;
|
||||||
@ -33,9 +33,13 @@ public interface SimulatorElement {
|
|||||||
|
|
||||||
YAPIONObject toYAPION();
|
YAPIONObject toYAPION();
|
||||||
List<Entity> getEntities();
|
List<Entity> getEntities();
|
||||||
|
void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity);
|
||||||
|
default Vector getPosition() {
|
||||||
|
return new Vector(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void show(Player player);
|
void show(SimulatorEntityShowMode showMode);
|
||||||
void hide(Player player);
|
void hide(SimulatorEntityShowMode showMode);
|
||||||
|
|
||||||
ItemStack menu();
|
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, Vector origin, int tickOffset); // Ticks to subtick order to spawning runnable to count of activations
|
||||||
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
|||||||
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
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 de.steamwar.bausystem.shared.Position;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -56,7 +57,7 @@ public class TNTElement implements SimulatorElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TNTElement(YAPIONObject yapionObject) {
|
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.entity = SimulatorEntityShowMode.createEntity(position, false);
|
||||||
this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80);
|
this.fuseTicks = yapionObject.getIntOrDefault("fuseTicks", 80);
|
||||||
this.count = yapionObject.getIntOrDefault("count", 1);
|
this.count = yapionObject.getIntOrDefault("count", 1);
|
||||||
@ -64,7 +65,7 @@ public class TNTElement implements SimulatorElement {
|
|||||||
this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false);
|
this.xVelocity = yapionObject.getBooleanOrDefault("xVelocity", false);
|
||||||
this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false);
|
this.yVelocity = yapionObject.getBooleanOrDefault("yVelocity", false);
|
||||||
this.zVelocity = yapionObject.getBooleanOrDefault("zVelocity", 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()));
|
this.material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +92,25 @@ public class TNTElement implements SimulatorElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(Player player) {
|
public void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity) {
|
||||||
entity.sendEntity(player);
|
if (this.entity.getId() == entity.getEntityId() || position.clone().add(origin).equals(entity.getLocation().toVector())) {
|
||||||
|
elements.add(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hide(Player player) {
|
public Vector getPosition() {
|
||||||
entity.hide(player, true);
|
return position.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(SimulatorEntityShowMode showMode) {
|
||||||
|
showMode.show(new Position(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide(SimulatorEntityShowMode showMode) {
|
||||||
|
showMode.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulatorn.tnt;
|
||||||
|
|
||||||
|
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.Entity;
|
||||||
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.YAPIONArray;
|
import yapion.hierarchy.types.YAPIONArray;
|
||||||
@ -76,16 +76,23 @@ public class TNTGroup implements SimulatorElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(Player player) {
|
public void getEntity(List<SimulatorElement> elements, Vector origin, Entity entity) {
|
||||||
|
for (TNTElement tntElement : this.elements) {
|
||||||
|
tntElement.getEntity(elements, origin, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(SimulatorEntityShowMode showMode) {
|
||||||
elements.forEach(tntElement -> {
|
elements.forEach(tntElement -> {
|
||||||
tntElement.show(player);
|
tntElement.show(showMode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void hide(Player player) {
|
public void hide(SimulatorEntityShowMode showMode) {
|
||||||
elements.forEach(tntElement -> {
|
elements.forEach(tntElement -> {
|
||||||
tntElement.hide(player);
|
tntElement.hide(showMode);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class ItemUtils {
|
|||||||
if (!container.has(key, PersistentDataType.STRING)) {
|
if (!container.has(key, PersistentDataType.STRING)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return container.get(ITEM_KEY, PersistentDataType.STRING);
|
return container.get(key, PersistentDataType.STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTag(ItemStack itemStack, NamespacedKey key, String value) {
|
public void setTag(ItemStack itemStack, NamespacedKey key, String value) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren