Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
2d9c201803
Commit
426f257358
@ -502,8 +502,10 @@ UNSIGN_HELP=§8/§eunsign §8- §7Make a signed book writable again
|
|||||||
|
|
||||||
# Simulator
|
# Simulator
|
||||||
SIMULATOR_HELP = §8/§esimulator §8-§7 Gives you the simulator wand
|
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_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Create a new simulator
|
||||||
|
SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Change your simulator wand selection
|
||||||
|
SIMULATOR_NO_PERMS = §cYou are not allowed to use the simulator here
|
||||||
|
|
||||||
SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected
|
SIMULATOR_NO_SIM_IN_HAND = §cNo simulator item selected
|
||||||
SIMULATOR_GUI_SELECT_SIM = Simulator selection
|
SIMULATOR_GUI_SELECT_SIM = Simulator selection
|
||||||
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists
|
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator already exists
|
||||||
@ -512,25 +514,6 @@ SIMULATOR_EDIT_LOCATION = §7Edit position
|
|||||||
SIMULATOR_EDIT_PROPERTIES = §7Edit properties
|
SIMULATOR_EDIT_PROPERTIES = §7Edit properties
|
||||||
SIMULATOR_EDIT_OTHER = §7Edit other
|
SIMULATOR_EDIT_OTHER = §7Edit other
|
||||||
|
|
||||||
SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator
|
|
||||||
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
|
|
||||||
SIMULATOR_SAVE_HELP = §8/§esimulator save §8<§eName§8> §8-§7 Saves the simulator
|
|
||||||
SIMULATOR_LOAD_HELP = §8/§esimulator load §8<§eName§8> §8-§7 Loads a simulator
|
|
||||||
SIMULATOR_LIST_HELP = §8/§esimulator list §8-§7 Lists all saved simulators
|
|
||||||
SIMULATOR_REMOVE_HELP = §8/§esimulator remove §8<§eName§8> §8-§7 Deletes the simulator
|
|
||||||
SIMULATOR_NO_PERMS = §cYou are not allowed to use the simulator here
|
|
||||||
|
|
||||||
SIMULATOR_DELETE_TNT = §7All TNTs have been deleted
|
|
||||||
SIMULATOR_SAVE = §7Simulator §e{0} §7was saved
|
|
||||||
SIMULATOR_LOAD = §7Simulator §e{0} §7was loaded
|
|
||||||
SIMULATOR_REMOVE = §7Simulator §e{0} §7was deleted
|
|
||||||
SIMULATOR_LIST_NOTHING = §7No saved simulators
|
|
||||||
SIMULATOR_LIST_HEADER = §7Saved simulators:
|
|
||||||
SIMULATOR_LIST_ELEMENT = §e{0} §8[§7Laden§8]
|
|
||||||
SIMULATOR_LIST_ELEMENT_HOVER = §eClick to load
|
|
||||||
|
|
||||||
SIMULATOR_WAND_NAME = §eSimulator
|
SIMULATOR_WAND_NAME = §eSimulator
|
||||||
SIMULATOR_WAND_LORE_1 = §eRigth click §8- §7adds a position
|
SIMULATOR_WAND_LORE_1 = §eRigth click §8- §7adds a position
|
||||||
SIMULATOR_WAND_LORE_2 = §eSneaking §8- §7Free movement
|
SIMULATOR_WAND_LORE_2 = §eSneaking §8- §7Free movement
|
||||||
|
@ -502,25 +502,18 @@ SCRIPT_GUI_CONSTANT_REGION_TYPE_LORE = §eRegionstype§7 der jetztigen Region
|
|||||||
UNSIGN_HELP=§8/§eunsign §8- §7Mache ein Buch beschreibbar
|
UNSIGN_HELP=§8/§eunsign §8- §7Mache ein Buch beschreibbar
|
||||||
|
|
||||||
# Simulator
|
# Simulator
|
||||||
SIMULATOR_GUI_ITEM_NAME = §eTNT Simulator
|
|
||||||
SIMULATOR_HELP = §8/§esimulator §8-§7 Legt dir den Simulatorstab ins Inventar
|
SIMULATOR_HELP = §8/§esimulator §8-§7 Legt dir den Simulatorstab ins Inventar
|
||||||
SIMULATOR_START_HELP = §8/§esimulator start §8-§7 Startet die Simulation
|
SIMULATOR_CREATE_HELP = §8/§esimulator create §8[§7name§8] §8-§7 Erstelle einen neuen Simulator
|
||||||
SIMULATOR_GUI_HELP = §8/§esimulator gui §8-§7 Öffnet die GUI
|
SIMULATOR_CHANGE_HELP = §8/§esimulator change §8-§7 Wechsel zu einem anderen Simulator
|
||||||
SIMULATOR_DELETE_HELP = §8/§esimulator delete §8-§7 Löscht alle TNT
|
|
||||||
SIMULATOR_SAVE_HELP = §8/§esimulator save §8<§eName§8> §8-§7 Speichert den Simulator
|
|
||||||
SIMULATOR_LOAD_HELP = §8/§esimulator load §8<§eName§8> §8-§7 Lädt den Simulator
|
|
||||||
SIMULATOR_LIST_HELP = §8/§esimulator list §8-§7 Listet alle gespeicherten Simulator
|
|
||||||
SIMULATOR_REMOVE_HELP = §8/§esimulator remove §8<§eName§8> §8-§7 Löscht den Simulator
|
|
||||||
SIMULATOR_NO_PERMS = §cDu darfst hier nicht den Simulator nutzen
|
SIMULATOR_NO_PERMS = §cDu darfst hier nicht den Simulator nutzen
|
||||||
|
|
||||||
SIMULATOR_DELETE_TNT = §7Alle TNT wurden gelöscht
|
SIMULATOR_NO_SIM_IN_HAND = §cKein Simulator Item gewählt
|
||||||
SIMULATOR_SAVE = §7Simulator §e{0} §7wurde gespeichert
|
SIMULATOR_GUI_SELECT_SIM = Simulator wählen
|
||||||
SIMULATOR_LOAD = §7Simulator §e{0} §7wurde geladen
|
SIMULATOR_NAME_ALREADY_EXISTS = §cSimulator existiert bereits
|
||||||
SIMULATOR_REMOVE = §7Simulator §e{0} §7wurde gelöscht
|
SIMULATOR_CREATE = §aSimulator erstellt
|
||||||
SIMULATOR_LIST_NOTHING = §7Keine gespeicherten Simulatoren
|
SIMULATOR_EDIT_LOCATION = §7Editiere Positionen
|
||||||
SIMULATOR_LIST_HEADER = §7Gespeicherte Simulatoren:
|
SIMULATOR_EDIT_PROPERTIES = §7Editiere Eigenschaften
|
||||||
SIMULATOR_LIST_ELEMENT = §e{0} §8[§7Laden§8]
|
SIMULATOR_EDIT_OTHER = §7Editiere Andere
|
||||||
SIMULATOR_LIST_ELEMENT_HOVER = §eZum laden klicken
|
|
||||||
|
|
||||||
SIMULATOR_WAND_NAME = §eKanonensimulator
|
SIMULATOR_WAND_NAME = §eKanonensimulator
|
||||||
SIMULATOR_WAND_LORE_1 = §eRechtsklick §8- §7Füge eine Position hinzu
|
SIMULATOR_WAND_LORE_1 = §eRechtsklick §8- §7Füge eine Position hinzu
|
||||||
@ -580,13 +573,13 @@ SIMULATOR_TNT_SPAWN_POSITION_Z = §7z-Position §8- §e{0}
|
|||||||
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH = §7Gezündet durch §8- §e{0}
|
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH = §7Gezündet durch §8- §e{0}
|
||||||
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR = Comparator
|
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR = Comparator
|
||||||
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER = Repeater
|
SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER = Repeater
|
||||||
|
SIMULATOR_TNT_SPAWN_ACTIVATED_UNKNOWN = Unbekannt
|
||||||
SIMULATOR_TNT_SPAWN_MATERIAL = §eMaterial
|
SIMULATOR_TNT_SPAWN_MATERIAL = §eMaterial
|
||||||
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1 = §7Jetziges Material§8: §e{0}
|
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1 = §7Jetziges Material§8: §e{0}
|
||||||
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2 = §eLink-Click §7Zum ändern
|
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2 = §eLink-Click §7Zum ändern
|
||||||
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3 = §eRechts-Click §7Zum zurücksetzten
|
SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3 = §eRechts-Click §7Zum zurücksetzten
|
||||||
SIMULATOR_MATERIAL_GUI_NAME = Material ändern
|
SIMULATOR_MATERIAL_GUI_NAME = Material ändern
|
||||||
SIMULATOR_MATERIAL_NAME = §e{0}
|
SIMULATOR_MATERIAL_CLICK = §eKlicken zum wählen
|
||||||
SIMULATOR_MATERIAL_CLICK = §eClicken zum wählen
|
|
||||||
SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE = §eZündphase hinzufügen
|
SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE = §eZündphase hinzufügen
|
||||||
SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE_SHIFT = §eShift-Click§8: §7Zündphase hinzufügen und +1 Tick Offset
|
SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE_SHIFT = §eShift-Click§8: §7Zündphase hinzufügen und +1 Tick Offset
|
||||||
SIMULATOR_TNT_SPAWN_ADD_TNT = §eTNT hinzufügen
|
SIMULATOR_TNT_SPAWN_ADD_TNT = §eTNT hinzufügen
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is a part of the SteamWar software.
|
|
||||||
|
|
||||||
Copyright (C) 2020 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.simulator;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.shared.AbstractEntity;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
public interface AbstractSimulatorEntity extends AbstractEntity {
|
|
||||||
|
|
||||||
void display(Player player);
|
|
||||||
|
|
||||||
void setPosition(Vector position);
|
|
||||||
|
|
||||||
boolean hide(Player player, boolean always);
|
|
||||||
|
|
||||||
int getId();
|
|
||||||
|
|
||||||
Entity getBukkitEntity();
|
|
||||||
}
|
|
@ -17,7 +17,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2021 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.simulator;
|
|
||||||
|
|
||||||
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.linkage.specific.BauGuiItem;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
// @Linked(LinkageType.BAU_GUI_ITEM)
|
|
||||||
public class SimulatorBauGuiItem extends BauGuiItem {
|
|
||||||
|
|
||||||
public SimulatorBauGuiItem() {
|
|
||||||
super(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getItem(Player player) {
|
|
||||||
return new SWItem(Material.REDSTONE_TORCH, BauSystem.MESSAGE.parse("SIMULATOR_GUI_ITEM_NAME", player)).getItemStack();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean click(ClickType click, Player p) {
|
|
||||||
p.closeInventory();
|
|
||||||
p.performCommand("sim");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Permission permission() {
|
|
||||||
return Permission.WORLD;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* This file is a part of the SteamWar software.
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 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 free software: you can redistribute it and/or modify
|
* This program is distributed in the hope that it will be useful,
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* (at your option) any later version.
|
* GNU Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
* 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.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
@ -23,21 +22,18 @@ package de.steamwar.bausystem.features.simulator;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.SWUtils;
|
import de.steamwar.bausystem.SWUtils;
|
||||||
|
import de.steamwar.bausystem.features.simulator.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.ListChatView;
|
import de.steamwar.bausystem.utils.ItemUtils;
|
||||||
import de.steamwar.bausystem.worlddata.SimulatorData;
|
import de.steamwar.command.GuardCheckType;
|
||||||
import de.steamwar.command.*;
|
import de.steamwar.command.GuardChecker;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import de.steamwar.command.GuardResult;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import de.steamwar.command.SWCommand;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
@Linked(LinkageType.COMMAND)
|
||||||
|
|
||||||
// @Linked(LinkageType.COMMAND)
|
|
||||||
public class SimulatorCommand extends SWCommand {
|
public class SimulatorCommand extends SWCommand {
|
||||||
|
|
||||||
public SimulatorCommand() {
|
public SimulatorCommand() {
|
||||||
@ -46,66 +42,28 @@ public class SimulatorCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register(description = "SIMULATOR_HELP")
|
@Register(description = "SIMULATOR_HELP")
|
||||||
public void genericCommand(@Guard Player p) {
|
public void genericCommand(@Guard Player p) {
|
||||||
SWUtils.giveItemToPlayer(p, TNTSimulator.getWand(p));
|
SimulatorCursor.hide(p, null);
|
||||||
|
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(value = {"start"}, description = "SIMULATOR_START_HELP")
|
@Register(value = "change", description = "SIMULATOR_CHANGE_HELP")
|
||||||
public void startCommand(@Guard Player p) {
|
public void change(@Guard Player p) {
|
||||||
TNTSimulator.get(p).start();
|
ItemStack itemStack = p.getInventory().getItemInMainHand();
|
||||||
}
|
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
||||||
|
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
|
||||||
@Register(value = {"gui"}, description = "SIMULATOR_GUI_HELP")
|
|
||||||
public void guiCommand(@Guard Player p) {
|
|
||||||
TNTSimulator.get(p).showGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"delete"}, description = "SIMULATOR_DELETE_HELP")
|
|
||||||
public void deleteCommand(@Guard Player p) {
|
|
||||||
TNTSimulator.get(p).delete();
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_DELETE_TNT", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"save"}, description = "SIMULATOR_SAVE_HELP")
|
|
||||||
public void saveCommand(@Guard Player p, String name) {
|
|
||||||
TNTSimulator.get(p).save();
|
|
||||||
SimulatorData.saveSimulator(p, name);
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_SAVE", p, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"load"}, description = "SIMULATOR_LOAD_HELP")
|
|
||||||
public void loadCommand(@Guard Player p, @Mapper("SavedSimulators") String name) {
|
|
||||||
TNTSimulator.get(p).delete();
|
|
||||||
SimulatorData.loadSimulator(p, name);
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_LOAD", p, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"remove"}, description = "SIMULATOR_REMOVE_HELP")
|
|
||||||
public void removeCommand(@Guard Player p, @Mapper("SavedSimulators") String name) {
|
|
||||||
SimulatorData.removeSimulator(p, name);
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_REMOVE", p, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register(value = {"list"}, description = "SIMULATOR_LIST_HELP")
|
|
||||||
public void listCommand(@Guard Player p, @OptionalValue("0") int page) {
|
|
||||||
List<String> sims = SimulatorData.listSimulator(p);
|
|
||||||
if (sims.isEmpty()) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_LIST_NOTHING", p);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_LIST_HEADER", p);
|
SimulatorSelectionGUI.open(p, itemStack);
|
||||||
ListChatView.chatView(p, sims, page, simulator -> {
|
}
|
||||||
TextComponent component = new TextComponent();
|
|
||||||
component.setText(BauSystem.MESSAGE.parse("SIMULATOR_LIST_ELEMENT", p, simulator));
|
@Register(value = "create", description = "SIMULATOR_CREATE_HELP")
|
||||||
component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/simulator load " + simulator));
|
public void create(@Guard Player p, String name) {
|
||||||
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(BauSystem.MESSAGE.parse("SIMULATOR_LIST_ELEMENT_HOVER", p))));
|
if (SimulatorStorage.getSimulatorNames().contains(name)) {
|
||||||
return component;
|
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", p);
|
||||||
}, (beforePageComponent, beforePage) -> {
|
return;
|
||||||
beforePageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_PREVIOUS_PAGE", p)).create()));
|
}
|
||||||
beforePageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/simulator list " + beforePage));
|
SimulatorStorage.createNewSimulator(name);
|
||||||
}, (afterPageComponent, afterPage) -> {
|
BauSystem.MESSAGE.send("SIMULATOR_CREATE", p);
|
||||||
afterPageComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(BauSystem.MESSAGE.parse("LIST_NEXT_PAGE", p)).create()));
|
|
||||||
afterPageComponent.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/simulator list " + afterPage));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ClassGuard(value = Player.class, local = true)
|
@ClassGuard(value = Player.class, local = true)
|
||||||
@ -121,22 +79,4 @@ public class SimulatorCommand extends SWCommand {
|
|||||||
return GuardResult.DENIED;
|
return GuardResult.DENIED;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mapper(value = "SavedSimulators", local = true)
|
|
||||||
public TypeMapper<String> simulatorListTypeMapper() {
|
|
||||||
return new TypeMapper<String>() {
|
|
||||||
@Override
|
|
||||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
|
||||||
if (SimulatorData.listSimulator(((Player) commandSender)).contains(s)) {
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
|
||||||
return SimulatorData.listSimulator(((Player) commandSender));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement;
|
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
@ -17,11 +17,11 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
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.features.simulator.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;
|
@ -1,741 +1,180 @@
|
|||||||
/*
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* This file is a part of the SteamWar software.
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 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 free software: you can redistribute it and/or modify
|
* This program is distributed in the hope that it will be useful,
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* (at your option) any later version.
|
* GNU Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
* 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.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI;
|
||||||
import de.steamwar.bausystem.configplayer.Config;
|
import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui;
|
||||||
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.features.tracer.record.RecordStateMachine;
|
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
import lombok.Getter;
|
||||||
import de.steamwar.bausystem.utils.ItemUtils;
|
|
||||||
import de.steamwar.bausystem.worlddata.SimulatorData;
|
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.BlockFace;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.util.Consumer;
|
|
||||||
import org.bukkit.util.RayTraceResult;
|
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 java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TNTSimulator {
|
public class TNTSimulator {
|
||||||
|
|
||||||
private static final Vector X_VECTOR = new Vector(0.0625, 0, 0);
|
private Map<Player, SimulatorEntityShowMode> playerShowMode = new HashMap<>();
|
||||||
private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0);
|
|
||||||
private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625);
|
|
||||||
|
|
||||||
private static final Vector FX_VECTOR = new Vector(1, 0, 0);
|
private Material material = Material.TNT;
|
||||||
private static final Vector FY_VECTOR = new Vector(0, 1, 0);
|
|
||||||
private static final Vector FZ_VECTOR = new Vector(0, 0, 1);
|
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
||||||
private static final List<TNTSpawn> EMPTY = new ArrayList<>();
|
|
||||||
|
public TNTSimulator() {
|
||||||
|
|
||||||
private static final List<Material> MATERIALS = new ArrayList<>();
|
|
||||||
static {
|
|
||||||
Arrays.stream(Material.values())
|
|
||||||
.filter(Material::isItem)
|
|
||||||
.filter(material -> !material.isLegacy())
|
|
||||||
.forEach(MATERIALS::add);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getWand(Player p) {
|
public TNTSimulator(YAPIONObject yapionObject) {
|
||||||
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();
|
material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
||||||
ItemUtils.setItem(itemStack, "simulator");
|
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
||||||
return itemStack;
|
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
|
||||||
}
|
if (element.containsKey("elements", YAPIONType.ARRAY)) {
|
||||||
|
tntElementList.add(new TNTGroup(element));
|
||||||
static final Map<Player, TNTSimulator> TNT_SIMULATOR_MAP = new HashMap<>();
|
} else {
|
||||||
|
tntElementList.add(new TNTElement(element));
|
||||||
public static TNTSimulator get(Player player) {
|
|
||||||
return TNT_SIMULATOR_MAP.computeIfAbsent(player, p -> {
|
|
||||||
YAPIONArray yapionArray = SimulatorData.getSimulator(player).getYAPIONArrayOrSetDefault("", new YAPIONArray());
|
|
||||||
TNTSimulator simulator = new TNTSimulator(player);
|
|
||||||
if (!yapionArray.isEmpty()) {
|
|
||||||
yapionArray.forEach(yapionAnyType -> {
|
|
||||||
simulator.spawns.add(simulator.new TNTSpawn((YAPIONObject) yapionAnyType));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return simulator;
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public YAPIONObject toYAPION() {
|
||||||
TNTSimulator simulator = TNT_SIMULATOR_MAP.get(player);
|
YAPIONObject yapionObject = new YAPIONObject();
|
||||||
|
yapionObject.add("material", material.name());
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
YAPIONArray yapionArray = new YAPIONArray();
|
||||||
simulator.spawns.forEach(tntSpawn -> {
|
for (SimulatorElement element : tntElementList) {
|
||||||
yapionArray.add(tntSpawn.output());
|
yapionArray.add(element.toYAPION());
|
||||||
|
}
|
||||||
|
yapionObject.add("tntElements", yapionArray);
|
||||||
|
return yapionObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hide(Player player) {
|
||||||
|
SimulatorEntityShowMode showMode = playerShowMode.get(player);
|
||||||
|
if (showMode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tntElementList.forEach(simulatorElement -> {
|
||||||
|
simulatorElement.hide(showMode);
|
||||||
});
|
});
|
||||||
SimulatorData.saveSimulator(player, yapionArray);
|
|
||||||
simulator.hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void remove(Player player) {
|
||||||
TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player);
|
SimulatorEntityShowMode showMode = playerShowMode.remove(player);
|
||||||
SimulatorData.removeSimulator(player, "");
|
if (showMode == null) {
|
||||||
simulator.hide();
|
return;
|
||||||
|
}
|
||||||
|
tntElementList.forEach(simulatorElement -> {
|
||||||
|
simulatorElement.hide(showMode);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void hide(Player player, List<SimulatorElement> simulatorElements) {
|
||||||
TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player);
|
SimulatorEntityShowMode showMode = playerShowMode.get(player);
|
||||||
simulator.hide();
|
if (showMode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
simulatorElements.forEach(simulatorElement -> {
|
||||||
|
simulatorElement.hide(showMode);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<TNTSpawn> spawns = new HashSet<>();
|
public void hide(TNTElement tntElement) {
|
||||||
private final Player player;
|
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||||
|
tntElement.hide(simulatorEntityShowMode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private AbstractSimulatorEntity cursor = null;
|
public void show(Player player) {
|
||||||
private boolean printed = false;
|
SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new);
|
||||||
|
tntElementList.forEach(simulatorElement -> {
|
||||||
|
simulatorElement.show(showMode);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private TNTSimulator(Player player) {
|
public void show(TNTElement tntElement) {
|
||||||
this.player = player;
|
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
||||||
|
tntElement.show(simulatorEntityShowMode);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Entity> getEntities() {
|
public List<Entity> getEntities() {
|
||||||
return spawns.stream().map(spawn -> spawn.entity.getBukkitEntity()).collect(Collectors.toList());
|
return tntElementList.stream().flatMap(element -> element.getEntities().stream()).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(RayTraceResult result) {
|
public List<SimulatorElement> getEntity(Entity entity) {
|
||||||
printed = true;
|
List<SimulatorElement> tntSpawns = new ArrayList<>();
|
||||||
|
for (SimulatorElement spawn : tntElementList) {
|
||||||
if (cursor != null)
|
spawn.getEntity(tntSpawns, entity);
|
||||||
cursor.hide(player, false);
|
|
||||||
|
|
||||||
spawns.forEach(TNTSpawn::show);
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (result.getHitEntity() != null) {
|
|
||||||
List<TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
|
|
||||||
tntSpawns.forEach(TNTSpawn::hide);
|
|
||||||
|
|
||||||
cursor = SimulatorEntityShowMode.createEntity(player, tntSpawns.isEmpty() ? getPos(result) : tntSpawns.get(0).position, true);
|
|
||||||
cursor.display(player);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_EDIT", player, ChatMessageType.ACTION_BAR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor = SimulatorEntityShowMode.createEntity(player, getPos(result), false);
|
|
||||||
cursor.display(player);
|
|
||||||
BauSystem.MESSAGE.sendPrefixless("SIMULATOR_POSITION_ADD", player, ChatMessageType.ACTION_BAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void edit(RayTraceResult result) {
|
|
||||||
if (result == null) {
|
|
||||||
showGUI();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
show(result);
|
|
||||||
|
|
||||||
if (result.getHitEntity() != null) {
|
|
||||||
List<TNTSpawn> tntSpawns = getEntity(result.getHitEntity());
|
|
||||||
if (tntSpawns.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (tntSpawns.size() == 1) {
|
|
||||||
tntSpawns.get(0).editTNT(spawns);
|
|
||||||
} else {
|
|
||||||
showGUI(new HashSet<>(tntSpawns));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spawns.add(new TNTSpawn(getPos(result), cursor));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hide() {
|
|
||||||
if (!printed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
printed = false;
|
|
||||||
if (cursor != null)
|
|
||||||
cursor.hide(player, true);
|
|
||||||
cursor = null;
|
|
||||||
spawns.forEach(TNTSpawn::hide);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
for (TNTSpawn tntSpawn : spawns) {
|
|
||||||
if (Region.getRegion(tntSpawn.position.toLocation(player.getWorld())).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
|
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_REGION_FREEZED", player);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
|
||||||
if (simulatorAutoTrace) {
|
|
||||||
RecordStateMachine.commandSingle();
|
|
||||||
player.performCommand("trace show");
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Integer, List<TNTSpawn>> first = new HashMap<>();
|
|
||||||
Map<Integer, List<TNTSpawn>> second = new HashMap<>();
|
|
||||||
int lastTick = 0;
|
|
||||||
|
|
||||||
for (TNTSpawn tntSpawn : spawns) {
|
|
||||||
Map<Integer, List<TNTSpawn>> list = tntSpawn.comparator ? second : first;
|
|
||||||
for (int i = 0; i < tntSpawn.count; i++) {
|
|
||||||
list.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList<>()).add(tntSpawn);
|
|
||||||
}
|
|
||||||
if (lastTick < tntSpawn.getTickOffset()) {
|
|
||||||
lastTick = tntSpawn.getTickOffset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int finalLastTick = lastTick;
|
|
||||||
|
|
||||||
AtomicInteger currentTick = new AtomicInteger(0);
|
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), bukkitTask -> {
|
|
||||||
int tick = currentTick.get();
|
|
||||||
spawnRandomList(first.getOrDefault(tick, EMPTY));
|
|
||||||
spawnRandomList(second.getOrDefault(tick, EMPTY));
|
|
||||||
if (tick > finalLastTick) bukkitTask.cancel();
|
|
||||||
currentTick.incrementAndGet();
|
|
||||||
}, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showGUI() {
|
|
||||||
showGUI(spawns);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showGUI(Set<TNTSpawn> tntSpawns) {
|
|
||||||
List<SWListInv.SWListEntry<TNTSpawn>> swListEntryList = tntSpawns.stream().map(spawn -> {
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_1", player, spawn.count));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_2", player, spawn.getTickOffset()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_3", player));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_4", player, spawn.position.getX()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_5", player, spawn.position.getY()));
|
|
||||||
lore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_LORE_6", player, spawn.position.getZ()));
|
|
||||||
SWItem swItem = new SWItem(spawn.material, BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_SPAWN_NAME", player), lore, false, null);
|
|
||||||
swItem.getItemStack().setAmount(spawn.count);
|
|
||||||
return new SWListInv.SWListEntry<>(swItem, spawn);
|
|
||||||
}).sorted(Comparator.comparing(SWListInv.SWListEntry::getObject)).collect(Collectors.toList());
|
|
||||||
|
|
||||||
SWListInv<TNTSpawn> swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, spawn) -> {
|
|
||||||
spawn.editTNT(tntSpawns);
|
|
||||||
});
|
|
||||||
swListInv.setItem(51, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_GUI_DELETE", player), clickType -> {
|
|
||||||
delete();
|
|
||||||
player.closeInventory();
|
|
||||||
}));
|
|
||||||
swListInv.setItem(47, new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("SIMULATOR_GUI_START", player), clickType -> {
|
|
||||||
start();
|
|
||||||
player.closeInventory();
|
|
||||||
}));
|
|
||||||
boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false);
|
|
||||||
swListInv.setItem(48, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, BauSystem.MESSAGE.parse("SIMULATOR_GUI_AUTO_TRACE", player, simulatorAutoTrace), clickType -> {
|
|
||||||
Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace);
|
|
||||||
showGUI(tntSpawns);
|
|
||||||
}));
|
|
||||||
swListInv.setItem(49, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> {
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
swListInv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void move(Set<TNTSpawn> tntSpawns) {
|
|
||||||
SWInventory swInventory = new SWInventory(player, 54, BauSystem.MESSAGE.parse("SIMULATOR_MOVE_ALL_GUI_NAME", player));
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
|
||||||
|
|
||||||
// Position Settings
|
|
||||||
// X Position
|
|
||||||
swInventory.setItem(12, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(21, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_X", player), clickType -> {
|
|
||||||
}));
|
|
||||||
swInventory.setItem(30, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Y Position
|
|
||||||
swInventory.setItem(13, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(22, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Y", player), clickType -> {
|
|
||||||
}));
|
|
||||||
swInventory.setItem(31, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Z Position
|
|
||||||
swInventory.setItem(14, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(23, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_POSITION_Z", player), clickType -> {
|
|
||||||
}));
|
|
||||||
swInventory.setItem(32, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR));
|
|
||||||
move(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
swInventory.setItem(53, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> {
|
|
||||||
showGUI(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updatePosition(Set<TNTSpawn> tntSpawns, Consumer<Vector> positionChanger) {
|
|
||||||
Map<Vector, Boolean> vectors = new IdentityHashMap<>();
|
|
||||||
for (TNTSpawn tntSpawn : tntSpawns) {
|
|
||||||
if (vectors.put(tntSpawn.position, true) == null) {
|
|
||||||
positionChanger.accept(tntSpawn.position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<TNTSpawn> getEntity(Entity entity) {
|
|
||||||
List<TNTSpawn> tntSpawns = new ArrayList<>();
|
|
||||||
for (TNTSpawn spawn : spawns) {
|
|
||||||
if (spawn.entity.getId() == entity.getEntityId() || spawn.position.equals(entity.getLocation().toVector())) {
|
|
||||||
tntSpawns.add(spawn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return tntSpawns;
|
return tntSpawns;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnRandomList(List<TNTSpawn> tntSpawns) {
|
public void remove(TNTElement tntElement) {
|
||||||
if (tntSpawns.isEmpty()) return;
|
hide(tntElement);
|
||||||
|
tntElementList.remove(tntElement);
|
||||||
List<TNTSpawn> toShuffle = new ArrayList<>();
|
Set<SimulatorElement> toRemove = new HashSet<>();
|
||||||
List<Integer> indices = new ArrayList<>();
|
for (SimulatorElement spawn : tntElementList) {
|
||||||
|
spawn.remove(tntElement);
|
||||||
for (int i = 0; i < tntSpawns.size(); i++) {
|
if (spawn instanceof TNTGroup) {
|
||||||
TNTSpawn tntSpawn = tntSpawns.get(i);
|
if (((TNTGroup) spawn).getElements().isEmpty()) {
|
||||||
if (tntSpawn.xVelocity || tntSpawn.yVelocity || tntSpawn.zVelocity) {
|
toRemove.add(spawn);
|
||||||
toShuffle.add(tntSpawn);
|
}
|
||||||
indices.add(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.shuffle(indices);
|
tntElementList.removeAll(toRemove);
|
||||||
|
tntElement.close();
|
||||||
for (TNTSpawn tntSpawn : toShuffle) {
|
|
||||||
tntSpawns.set(indices.remove(0), tntSpawn);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (TNTSpawn tntSpawn : tntSpawns) {
|
|
||||||
tntSpawn.spawn();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector getPos(RayTraceResult result) {
|
public void edit(Player player, RayTraceResult result) {
|
||||||
Vector pos = result.getHitPosition();
|
if (result == null) {
|
||||||
|
TNTSimulatorGui.open(player, this, null, getTntElementList(), null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BlockFace face = result.getHitBlockFace();
|
SimulatorCursor.show(player, this, result);
|
||||||
if (face != null) {
|
|
||||||
switch (face) {
|
if (result.getHitEntity() != null) {
|
||||||
case DOWN:
|
List<SimulatorElement> elements = getEntity(result.getHitEntity());
|
||||||
pos.setY(pos.getY() - 0.98);
|
if (elements.isEmpty()) return;
|
||||||
break;
|
|
||||||
case EAST:
|
if (elements.size() == 1) {
|
||||||
pos.setX(pos.getX() + 0.49);
|
TNTElementGUI.open(player, (TNTElement) elements.get(0), null);
|
||||||
break;
|
} else {
|
||||||
case WEST:
|
TNTSimulatorGui.open(player, null, null, elements, null);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.isSneaking()) {
|
TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result));
|
||||||
pos.setX(pos.getBlockX() + 0.5);
|
tntElementList.add(tntElement);
|
||||||
if (face == null || face.getModY() == 0)
|
TNTElementGUI.open(player, tntElement, null);
|
||||||
pos.setY(pos.getBlockY() + 0.0);
|
playerShowMode.forEach((p, simulatorEntityShowMode) -> {
|
||||||
pos.setZ(pos.getBlockZ() + 0.5);
|
show(p);
|
||||||
}
|
});
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TNTSpawn implements Comparable<TNTSpawn> {
|
|
||||||
|
|
||||||
private final AbstractSimulatorEntity entity;
|
|
||||||
private boolean printed = false;
|
|
||||||
|
|
||||||
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 boolean comparator = false;
|
|
||||||
private Material material = Material.TNT;
|
|
||||||
|
|
||||||
private TNTSpawn(Vector position, AbstractSimulatorEntity entity) {
|
|
||||||
this.position = position;
|
|
||||||
this.entity = entity;
|
|
||||||
show();
|
|
||||||
editTNT(spawns);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TNTSpawn(YAPIONObject yapionObject) {
|
|
||||||
this.position = new Vector(yapionObject.getPlainValueOrDefault("positionX", 0.0), yapionObject.getPlainValueOrDefault("positionY", 0.0), yapionObject.getPlainValueOrDefault("positionZ", 0.0));
|
|
||||||
this.entity = SimulatorEntityShowMode.createEntity(player, position, false);
|
|
||||||
this.fuseTicks = yapionObject.getPlainValueOrDefault("fuseTicks", 80);
|
|
||||||
this.count = yapionObject.getPlainValue("count");
|
|
||||||
this.tickOffset = yapionObject.getPlainValue("tickOffset");
|
|
||||||
this.xVelocity = yapionObject.getPlainValue("xVelocity");
|
|
||||||
this.yVelocity = yapionObject.getPlainValue("yVelocity");
|
|
||||||
this.zVelocity = yapionObject.getPlainValue("zVelocity");
|
|
||||||
this.comparator = yapionObject.getPlainValue("comparator");
|
|
||||||
this.material = Material.getMaterial(yapionObject.getPlainValueOrDefault("material", "TNT"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private YAPIONObject output() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("positionX", position.getX());
|
|
||||||
yapionObject.add("positionY", position.getY());
|
|
||||||
yapionObject.add("positionZ", position.getZ());
|
|
||||||
yapionObject.add("fuseTicks", fuseTicks);
|
|
||||||
yapionObject.add("count", count);
|
|
||||||
yapionObject.add("tickOffset", tickOffset);
|
|
||||||
yapionObject.add("xVelocity", xVelocity);
|
|
||||||
yapionObject.add("yVelocity", yVelocity);
|
|
||||||
yapionObject.add("zVelocity", zVelocity);
|
|
||||||
yapionObject.add("comparator", comparator);
|
|
||||||
yapionObject.add("material", material.name());
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void show() {
|
|
||||||
if (printed)
|
|
||||||
return;
|
|
||||||
printed = true;
|
|
||||||
entity.display(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void hide() {
|
|
||||||
if (!printed)
|
|
||||||
return;
|
|
||||||
printed = false;
|
|
||||||
entity.hide(player, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void spawn() {
|
|
||||||
WORLD.spawn(position.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));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setFuseTicks(int fuseTicks) {
|
|
||||||
if (fuseTicks < 0) fuseTicks = 0;
|
|
||||||
if (fuseTicks > 160) fuseTicks = 160;
|
|
||||||
this.fuseTicks = fuseTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setCount(int count) {
|
|
||||||
if (count < 1) count = 1;
|
|
||||||
if (count > 400) count = 400;
|
|
||||||
this.count = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getTickOffset() {
|
|
||||||
return tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTickOffset(int tickOffset) {
|
|
||||||
if (tickOffset < 0) tickOffset = 0;
|
|
||||||
if (tickOffset > 400) tickOffset = 400;
|
|
||||||
this.tickOffset = tickOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(TNTSpawn tntSpawn) {
|
|
||||||
return -Integer.compare(tickOffset, tntSpawn.tickOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void editTNT(Set<TNTSpawn> tntSpawns) {
|
|
||||||
hide();
|
|
||||||
entity.setPosition(position);
|
|
||||||
show();
|
|
||||||
SWInventory swInventory = new SWInventory(player, 54, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_GUI_NAME", player));
|
|
||||||
|
|
||||||
String plusOneName = BauSystem.MESSAGE.parse("SIMULATOR_PLUS_ONE", player);
|
|
||||||
String minusOneName = BauSystem.MESSAGE.parse("SIMULATOR_MINUS_ONE", player);
|
|
||||||
List<String> plusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> minusOnePixelShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_PIXEL_SHIFT", player));
|
|
||||||
List<String> plusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_PLUS_FIVE_SHIFT", player));
|
|
||||||
List<String> minusOneFiveShiftLore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MINUS_FIVE_SHIFT", player));
|
|
||||||
List<String> lore = Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_LORE", player));
|
|
||||||
|
|
||||||
// Change Count of spawned TNT
|
|
||||||
swInventory.setItem(1, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setCount(count + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
SWItem countItem = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT", player, count), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_COUNT_ANVIL_GUI_NAME", player), count, c -> {
|
|
||||||
setCount(c);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns)));
|
|
||||||
countItem.getItemStack().setAmount(count);
|
|
||||||
swInventory.setItem(10, countItem);
|
|
||||||
swInventory.setItem(19, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setCount(count - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Change TickOffset
|
|
||||||
swInventory.setItem(2, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setTickOffset(tickOffset + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, tickOffset), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK_ANVIL_GUI_NAME", player), tickOffset, tick -> {
|
|
||||||
setTickOffset(tick);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns)));
|
|
||||||
tickItem.getItemStack().setAmount(Math.max(tickOffset, 1));
|
|
||||||
swInventory.setItem(11, tickItem);
|
|
||||||
swInventory.setItem(20, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setTickOffset(tickOffset - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Change FuseTicks
|
|
||||||
swInventory.setItem(3, new SWItem(SWItem.getDye(10), plusOneName, plusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setFuseTicks(fuseTicks + (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
SWItem fuseTickItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE", player, fuseTicks), lore, false, clickType -> changeCount(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_FUSE_ANVIL_GUI_NAME", player), fuseTicks, tick -> {
|
|
||||||
setFuseTicks(tick);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns)));
|
|
||||||
fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1));
|
|
||||||
swInventory.setItem(12, fuseTickItem);
|
|
||||||
swInventory.setItem(21, new SWItem(SWItem.getDye(1), minusOneName, minusOneFiveShiftLore, false, clickType -> {
|
|
||||||
setFuseTicks(fuseTicks - (clickType.isShiftClick() ? 5 : 1));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Velocity Settings
|
|
||||||
swInventory.setItem(38, Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_NAME", player), clickType -> {
|
|
||||||
if (xVelocity || yVelocity || zVelocity) {
|
|
||||||
xVelocity = false;
|
|
||||||
yVelocity = false;
|
|
||||||
zVelocity = false;
|
|
||||||
} else {
|
|
||||||
xVelocity = true;
|
|
||||||
yVelocity = true;
|
|
||||||
zVelocity = true;
|
|
||||||
}
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
});
|
|
||||||
swInventory.setItem(46, new SWItem(getWool(xVelocity), getColor(xVelocity), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_X", player, BauSystem.MESSAGE.parse(active(xVelocity), player)), clickType -> {
|
|
||||||
xVelocity = !xVelocity;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(29, new SWItem(getWool(yVelocity), getColor(yVelocity), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Y", player, BauSystem.MESSAGE.parse(active(yVelocity), player)), clickType -> {
|
|
||||||
yVelocity = !yVelocity;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(48, new SWItem(getWool(zVelocity), getColor(zVelocity), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_VELOCITY_Z", player, BauSystem.MESSAGE.parse(active(zVelocity), player)), clickType -> {
|
|
||||||
zVelocity = !zVelocity;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Position Settings
|
|
||||||
// X Position
|
|
||||||
swInventory.setItem(5, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(14, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, position.getX()), lore, false, clickType -> {
|
|
||||||
changePosition(player, position.getX(), x -> {
|
|
||||||
position.setX(clamp(x));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns));
|
|
||||||
}));
|
|
||||||
swInventory.setItem(23, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Y Position
|
|
||||||
swInventory.setItem(6, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(15, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, position.getY()), lore, false, clickType -> {
|
|
||||||
changePosition(player, position.getY(), y -> {
|
|
||||||
position.setY(clamp(y));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns));
|
|
||||||
}));
|
|
||||||
swInventory.setItem(24, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Z Position
|
|
||||||
swInventory.setItem(7, new SWItem(SWItem.getDye(10), plusOneName, plusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(16, new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, position.getZ()), lore, false, clickType -> {
|
|
||||||
changePosition(player, position.getZ(), z -> {
|
|
||||||
position.setZ(clamp(z));
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}, () -> editTNT(tntSpawns));
|
|
||||||
}));
|
|
||||||
swInventory.setItem(25, new SWItem(SWItem.getDye(1), minusOneName, minusOnePixelShiftLore, false, clickType -> {
|
|
||||||
position.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR);
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Repeater before Comparator
|
|
||||||
swInventory.setItem(42, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, BauSystem.MESSAGE.parse(comparator ? "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_COMPARATOR" : "SIMULATOR_TNT_SPAWN_ACTIVATED_WITH_REPEATER", player)), clickType -> {
|
|
||||||
comparator = !comparator;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}));
|
|
||||||
swInventory.setItem(41, new SWItem(material, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_1", player, material.name().toLowerCase()), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_2", player), BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_MATERIAL_LORE_3", player)), false, clickType -> {
|
|
||||||
if (clickType.isLeftClick()) {
|
|
||||||
List<SWListInv.SWListEntry<Material>> swListEntries = new ArrayList<>();
|
|
||||||
MATERIALS.forEach(current -> {
|
|
||||||
swListEntries.add(new SWListInv.SWListEntry<>(new SWItem(current, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME", player, current.name().toLowerCase()), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_CLICK", player)), false, ignored -> {
|
|
||||||
}), current));
|
|
||||||
});
|
|
||||||
SWListInv<Material> swListInv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_GUI_NAME", player), false, swListEntries, (invClickType, material) -> {
|
|
||||||
TNTSpawn.this.material = material;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
});
|
|
||||||
swListInv.open();
|
|
||||||
} else {
|
|
||||||
material = Material.TNT;
|
|
||||||
editTNT(tntSpawns);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
swInventory.setItem(33, new SWItem(Material.TNT, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE", player), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_IGNITION_PHASE_SHIFT", player)), false, clickType -> {
|
|
||||||
TNTSpawn tntSpawn = new TNTSpawn(position, entity);
|
|
||||||
if (clickType.isShiftClick()) {
|
|
||||||
tntSpawn.setTickOffset(tickOffset + 1);
|
|
||||||
}
|
|
||||||
tntSpawn.material = material;
|
|
||||||
spawns.add(tntSpawn);
|
|
||||||
}));
|
|
||||||
|
|
||||||
swInventory.setItem(53, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> {
|
|
||||||
showGUI(tntSpawns);
|
|
||||||
}));
|
|
||||||
|
|
||||||
swInventory.setItem(51, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> {
|
|
||||||
Vector vector = position.clone();
|
|
||||||
spawns.add(new TNTSpawn(vector, SimulatorEntityShowMode.createEntity(player, vector, false)));
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Delete tnt
|
|
||||||
swInventory.setItem(44, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_REMOVE_TNT", player), clickType -> {
|
|
||||||
hide();
|
|
||||||
spawns.remove(this);
|
|
||||||
player.closeInventory();
|
|
||||||
}));
|
|
||||||
|
|
||||||
swInventory.addCloseCallback(clickType -> {
|
|
||||||
TNTSimulator.get(player).show(TNTSimulatorListener.trace(player, player.getLocation()));
|
|
||||||
});
|
|
||||||
swInventory.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeCount(Player player, String name, int defaultValue, Consumer<Integer> result, Runnable failure) {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, name, defaultValue + "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
result.accept(Integer.parseInt(s));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
failure.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changePosition(Player player, double defaultValue, Consumer<Double> result, Runnable failure) {
|
|
||||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_ANVIL_GUI_NAME", player), defaultValue + "");
|
|
||||||
swAnvilInv.setItem(Material.PAPER);
|
|
||||||
swAnvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
result.accept(Double.parseDouble(s.replace(',', '.')));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
failure.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swAnvilInv.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private double clamp(double d) {
|
|
||||||
return (int) (d * 100) * 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Material getWool(boolean b) {
|
|
||||||
return b ? Material.LIME_WOOL : Material.RED_WOOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte getColor(boolean b) {
|
|
||||||
return (byte) (b ? 10 : 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String active(boolean b) {
|
|
||||||
return b ? "SIMULATOR_TNT_SPAWN_VELOCITY_ON" : "SIMULATOR_TNT_SPAWN_VELOCITY_OFF";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
* This file is a part of the SteamWar software.
|
* Copyright (C) 2022 SteamWar.de-Serverteam
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 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 free software: you can redistribute it and/or modify
|
* This program is distributed in the hope that it will be useful,
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* (at your option) any later version.
|
* GNU Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
* 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.simulator;
|
package de.steamwar.bausystem.features.simulator;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.linkage.Disable;
|
import de.steamwar.bausystem.features.simulator.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;
|
||||||
import org.bukkit.FluidCollisionMode;
|
import org.bukkit.FluidCollisionMode;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -36,7 +35,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;
|
||||||
@ -45,13 +43,11 @@ 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)
|
||||||
|
public class TNTSimulatorListener implements Listener {
|
||||||
// @Linked(LinkageType.LISTENER)
|
|
||||||
// @Linked(LinkageType.DISABLE_LINK)
|
|
||||||
public class TNTSimulatorListener implements Listener, Disable {
|
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
private boolean permissionCheck(Player player) {
|
||||||
|
if (true) return true;
|
||||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
||||||
return false;
|
return false;
|
||||||
@ -59,7 +55,11 @@ public class TNTSimulatorListener implements Listener, Disable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RayTraceResult trace(Player player, Location to) {
|
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);
|
Location startPos = to.clone().add(0.0, player.getEyeHeight(), 0.0);
|
||||||
Vector direction = to.getDirection();
|
Vector direction = to.getDirection();
|
||||||
RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true);
|
RayTraceResult blocks = player.getWorld().rayTraceBlocks(startPos, direction, 10.0, FluidCollisionMode.NEVER, true);
|
||||||
@ -67,7 +67,7 @@ public class TNTSimulatorListener implements Listener, Disable {
|
|||||||
Entity nearestHitEntity = null;
|
Entity nearestHitEntity = null;
|
||||||
RayTraceResult nearestHitResult = null;
|
RayTraceResult nearestHitResult = null;
|
||||||
double nearestDistanceSq = Double.MAX_VALUE;
|
double nearestDistanceSq = Double.MAX_VALUE;
|
||||||
for (Entity entity : get(player).getEntities()) {
|
for (Entity entity : simulator.getEntities()) {
|
||||||
BoundingBox boundingBox = entity.getBoundingBox();
|
BoundingBox boundingBox = entity.getBoundingBox();
|
||||||
RayTraceResult hitResult = boundingBox.rayTrace(startPos.toVector(), direction, 10.0);
|
RayTraceResult hitResult = boundingBox.rayTrace(startPos.toVector(), direction, 10.0);
|
||||||
if (hitResult != null) {
|
if (hitResult != null) {
|
||||||
@ -95,23 +95,24 @@ public class TNTSimulatorListener implements Listener, Disable {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent e) {
|
public void onPlayerMove(PlayerMoveEvent e) {
|
||||||
simulatorShowHide(e.getPlayer(), PlayerInventory::getItemInMainHand, e.getTo());
|
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
||||||
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
|
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getPreviousSlot()), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> itemStackFunction, Location location) {
|
private void simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
|
||||||
TNTSimulator simulator = get(player);
|
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
|
||||||
ItemStack itemStack = itemStackFunction.apply(player.getInventory());
|
SimulatorCursor.hide(player, oldSimulator);
|
||||||
if (!ItemUtils.isItem(itemStack, "simulator")) {
|
|
||||||
simulator.hide();
|
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
||||||
|
if (simulator == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
simulator.show(trace(player, location));
|
SimulatorCursor.show(player, simulator, trace(player, location, simulator));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -124,31 +125,26 @@ public class TNTSimulatorListener implements Listener, Disable {
|
|||||||
if (!permissionCheck(event.getPlayer())) {
|
if (!permissionCheck(event.getPlayer())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
TNTSimulator simulator = SimulatorStorage.getSimulator(event.getItem());
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case LEFT_CLICK_BLOCK:
|
case LEFT_CLICK_BLOCK:
|
||||||
case LEFT_CLICK_AIR:
|
case LEFT_CLICK_AIR:
|
||||||
get(event.getPlayer()).start();
|
if (simulator == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
System.out.println("Left click");
|
||||||
break;
|
break;
|
||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
case RIGHT_CLICK_AIR:
|
case RIGHT_CLICK_AIR:
|
||||||
get(event.getPlayer()).edit(trace(event.getPlayer(), event.getPlayer().getLocation()));
|
if (simulator == null) {
|
||||||
|
SimulatorSelectionGUI.open(event.getPlayer(), event.getItem());
|
||||||
|
} else {
|
||||||
|
simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
get(event.getPlayer()).save();
|
|
||||||
get(event.getPlayer()).remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
for (TNTSimulator simulator : TNTSimulator.TNT_SIMULATOR_MAP.values()) {
|
|
||||||
simulator.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||||
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
|
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
@ -17,14 +17,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.gui;
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulatorn.OrderUtils;
|
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
||||||
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||||
import de.steamwar.bausystem.features.simulatorn.TNTSimulator;
|
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
|
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTGroup;
|
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
@ -101,6 +101,10 @@ public class TNTElementGUI {
|
|||||||
otherLore.add("");
|
otherLore.add("");
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, BauSystem.MESSAGE.parse(OrderUtils.name(tntElement.getOrder()), player)));
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ACTIVATED_WITH", player, BauSystem.MESSAGE.parse(OrderUtils.name(tntElement.getOrder()), player)));
|
||||||
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name()));
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, tntElement.getMaterial().name()));
|
||||||
|
if (tntElement.isDisabled()) {
|
||||||
|
otherLore.add("");
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
||||||
|
}
|
||||||
inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> {
|
inv.setItem(24, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> {
|
||||||
editOther(player, tntElement, () -> open(player, tntElement, back));
|
editOther(player, tntElement, () -> open(player, tntElement, back));
|
||||||
}));
|
}));
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.bausystem.features.simulator.gui;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||||
|
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||||
|
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||||
|
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||||
|
import de.steamwar.inventory.SWItem;
|
||||||
|
import de.steamwar.inventory.SWListInv;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class TNTSimulatorGui {
|
||||||
|
|
||||||
|
public void open(Player player, TNTSimulator currentTntSimulator, TNTGroup currentTntGroup, List<SimulatorElement> simulatorElements, Runnable back) {
|
||||||
|
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (SimulatorElement element : simulatorElements) {
|
||||||
|
swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
||||||
|
}
|
||||||
|
|
||||||
|
SWListInv<SimulatorElement> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> {
|
||||||
|
if (simulatorElement instanceof TNTGroup) {
|
||||||
|
TNTGroup tntGroup = (TNTGroup) simulatorElement;
|
||||||
|
List<SimulatorElement> elements = new ArrayList<>(tntGroup.getElements());
|
||||||
|
open(player, null, tntGroup, elements, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
||||||
|
} else {
|
||||||
|
TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, currentTntSimulator, currentTntGroup, simulatorElements, back));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (back != null) {
|
||||||
|
inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
||||||
|
}
|
||||||
|
if (currentTntSimulator != null) {
|
||||||
|
inv.setItem(49, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, BauSystem.MESSAGE.parse("SIMULATOR_GUI_MOVE_ALL", player), clickType -> {
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (currentTntGroup != null) {
|
||||||
|
List<String> otherLore = new ArrayList<>();
|
||||||
|
otherLore.add("");
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_X", player, currentTntGroup.getPosition().getX()));
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Y", player, currentTntGroup.getPosition().getY()));
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_POSITION_Z", player, currentTntGroup.getPosition().getZ()));
|
||||||
|
otherLore.add("");
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_MATERIAL_NAME_LORE", player, currentTntGroup.getMaterial().name()));
|
||||||
|
otherLore.add("");
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_TICK", player, currentTntGroup.getTickOffset()));
|
||||||
|
if (currentTntGroup.isDisabled()) {
|
||||||
|
otherLore.add("");
|
||||||
|
otherLore.add(BauSystem.MESSAGE.parse("SIMULATOR_GUI_TNT_DISABLED", player));
|
||||||
|
}
|
||||||
|
inv.setItem(51, new SWItem(Material.ANVIL, BauSystem.MESSAGE.parse("SIMULATOR_EDIT_OTHER", player), otherLore, false, clickType -> {
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
package de.steamwar.bausystem.features.simulator.show;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is a part of the SteamWar software.
|
* This file is a part of the SteamWar software.
|
||||||
*
|
*
|
||||||
@ -17,9 +19,8 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulator.show;
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
|
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||||
import de.steamwar.bausystem.shared.Position;
|
import de.steamwar.bausystem.shared.Position;
|
||||||
import de.steamwar.bausystem.shared.RoundedPosition;
|
import de.steamwar.bausystem.shared.RoundedPosition;
|
||||||
import de.steamwar.bausystem.shared.ShowMode;
|
import de.steamwar.bausystem.shared.ShowMode;
|
||||||
@ -43,12 +44,23 @@ public class SimulatorEntityShowMode implements ShowMode<Position> {
|
|||||||
@Override
|
@Override
|
||||||
public void show(Position position) {
|
public void show(Position position) {
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(position);
|
RoundedPosition roundedPosition = new RoundedPosition(position);
|
||||||
AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), false));
|
AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(position.getLocation(), false));
|
||||||
entity.display(player);
|
entity.display(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstractSimulatorEntity createEntity(Player player, Vector position, boolean highlight) {
|
public static AbstractSimulatorEntity createEntity(Vector position, boolean highlight) {
|
||||||
return NMSWrapper.impl.createSimulator(player.getWorld(), 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
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulator.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
@ -17,13 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulator.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
||||||
import de.steamwar.bausystem.features.simulatorn.OrderUtils;
|
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
||||||
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||||
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.bausystem.shared.Position;
|
import de.steamwar.bausystem.shared.Position;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
@ -17,10 +17,10 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.steamwar.bausystem.features.simulatorn.tnt;
|
package de.steamwar.bausystem.features.simulator.tnt;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.simulatorn.show.SimulatorEntityShowMode;
|
import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode;
|
||||||
import de.steamwar.bausystem.shared.Pair;
|
import de.steamwar.bausystem.shared.Pair;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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) {
|
|
||||||
SimulatorCursor.hide(p, null);
|
|
||||||
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(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("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) -> {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,182 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.features.simulatorn.gui.TNTElementGUI;
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.gui.TNTSimulatorGui;
|
|
||||||
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;
|
|
||||||
import lombok.Getter;
|
|
||||||
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.YAPIONObject;
|
|
||||||
import yapion.hierarchy.types.YAPIONType;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class TNTSimulator {
|
|
||||||
|
|
||||||
private Map<Player, SimulatorEntityShowMode> playerShowMode = new HashMap<>();
|
|
||||||
|
|
||||||
private Material material = Material.TNT;
|
|
||||||
|
|
||||||
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
|
||||||
|
|
||||||
public TNTSimulator() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public TNTSimulator(YAPIONObject yapionObject) {
|
|
||||||
material = Material.valueOf(yapionObject.getStringOrDefault("material", Material.TNT.name()));
|
|
||||||
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
|
||||||
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
|
|
||||||
if (element.containsKey("elements", YAPIONType.ARRAY)) {
|
|
||||||
tntElementList.add(new TNTGroup(element));
|
|
||||||
} else {
|
|
||||||
tntElementList.add(new TNTElement(element));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public YAPIONObject toYAPION() {
|
|
||||||
YAPIONObject yapionObject = new YAPIONObject();
|
|
||||||
yapionObject.add("material", material.name());
|
|
||||||
YAPIONArray yapionArray = new YAPIONArray();
|
|
||||||
for (SimulatorElement element : tntElementList) {
|
|
||||||
yapionArray.add(element.toYAPION());
|
|
||||||
}
|
|
||||||
yapionObject.add("tntElements", yapionArray);
|
|
||||||
return yapionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hide(Player player) {
|
|
||||||
SimulatorEntityShowMode showMode = playerShowMode.get(player);
|
|
||||||
if (showMode == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tntElementList.forEach(simulatorElement -> {
|
|
||||||
simulatorElement.hide(showMode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
simulatorElements.forEach(simulatorElement -> {
|
|
||||||
simulatorElement.hide(showMode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void hide(TNTElement tntElement) {
|
|
||||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
|
||||||
tntElement.hide(simulatorEntityShowMode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(Player player) {
|
|
||||||
SimulatorEntityShowMode showMode = playerShowMode.computeIfAbsent(player, SimulatorEntityShowMode::new);
|
|
||||||
tntElementList.forEach(simulatorElement -> {
|
|
||||||
simulatorElement.show(showMode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(TNTElement tntElement) {
|
|
||||||
playerShowMode.forEach((player, simulatorEntityShowMode) -> {
|
|
||||||
tntElement.show(simulatorEntityShowMode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Entity> getEntities() {
|
|
||||||
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, entity);
|
|
||||||
}
|
|
||||||
return tntSpawns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(TNTElement tntElement) {
|
|
||||||
hide(tntElement);
|
|
||||||
tntElementList.remove(tntElement);
|
|
||||||
Set<SimulatorElement> toRemove = new HashSet<>();
|
|
||||||
for (SimulatorElement spawn : tntElementList) {
|
|
||||||
spawn.remove(tntElement);
|
|
||||||
if (spawn instanceof TNTGroup) {
|
|
||||||
if (((TNTGroup) spawn).getElements().isEmpty()) {
|
|
||||||
toRemove.add(spawn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tntElementList.removeAll(toRemove);
|
|
||||||
tntElement.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void edit(Player player, RayTraceResult result) {
|
|
||||||
if (result == null) {
|
|
||||||
TNTSimulatorGui.open(player, vector -> {
|
|
||||||
|
|
||||||
}, null, getTntElementList(), null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimulatorCursor.show(player, this, result);
|
|
||||||
|
|
||||||
if (result.getHitEntity() != null) {
|
|
||||||
List<SimulatorElement> elements = getEntity(result.getHitEntity());
|
|
||||||
if (elements.isEmpty()) return;
|
|
||||||
|
|
||||||
if (elements.size() == 1) {
|
|
||||||
TNTElementGUI.open(player, (TNTElement) elements.get(0), null);
|
|
||||||
} else {
|
|
||||||
TNTSimulatorGui.open(player, null, null, elements, null);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result));
|
|
||||||
tntElementList.add(tntElement);
|
|
||||||
TNTElementGUI.open(player, tntElement, null);
|
|
||||||
playerShowMode.forEach((p, simulatorEntityShowMode) -> {
|
|
||||||
show(p);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,150 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.features.simulatorn.gui.SimulatorSelectionGUI;
|
|
||||||
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;
|
|
||||||
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.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;
|
|
||||||
|
|
||||||
@Linked(LinkageType.LISTENER)
|
|
||||||
public class TNTSimulatorListener implements Listener {
|
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
|
||||||
if (true) return true;
|
|
||||||
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) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
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(), i -> 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()));
|
|
||||||
SimulatorCursor.hide(player, oldSimulator);
|
|
||||||
|
|
||||||
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
|
|
||||||
if (simulator == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimulatorCursor.show(player, simulator, 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;
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.BauSystem;
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.SimulatorElement;
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTElement;
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.tnt.TNTGroup;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
|
||||||
import de.steamwar.inventory.SWListInv;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
@UtilityClass
|
|
||||||
public class TNTSimulatorGui {
|
|
||||||
|
|
||||||
public void open(Player player, Consumer<Vector> moveAll, Consumer<Material> materialChanger, List<SimulatorElement> simulatorElements, Runnable back) {
|
|
||||||
List<SWListInv.SWListEntry<SimulatorElement>> swListEntryList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (SimulatorElement element : simulatorElements) {
|
|
||||||
swListEntryList.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
|
||||||
}
|
|
||||||
|
|
||||||
SWListInv<SimulatorElement> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SIMULATOR_GUI_NAME", player), false, swListEntryList, (clickType, simulatorElement) -> {
|
|
||||||
if (simulatorElement instanceof TNTGroup) {
|
|
||||||
TNTGroup tntGroup = (TNTGroup) simulatorElement;
|
|
||||||
List<SimulatorElement> elements = new ArrayList<>(tntGroup.getElements());
|
|
||||||
open(player, vector -> {
|
|
||||||
|
|
||||||
}, material -> {}, elements, () -> open(player, moveAll, materialChanger, simulatorElements, back));
|
|
||||||
} else {
|
|
||||||
TNTElementGUI.open(player, (TNTElement) simulatorElement, () -> open(player, moveAll, materialChanger, simulatorElements, back));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (back != null) {
|
|
||||||
inv.setItem(47, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("SIMULATOR_BACK", player), clickType -> back.run()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Add button
|
|
||||||
|
|
||||||
inv.open();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
package de.steamwar.bausystem.features.simulatorn.show;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is a part of the SteamWar software.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2021 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import de.steamwar.bausystem.features.simulator.AbstractSimulatorEntity;
|
|
||||||
import de.steamwar.bausystem.features.simulatorn.SimulatorStorage;
|
|
||||||
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.entity.Player;
|
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SimulatorEntityShowMode implements ShowMode<Position> {
|
|
||||||
|
|
||||||
protected final Player player;
|
|
||||||
|
|
||||||
private final Map<RoundedPosition, AbstractSimulatorEntity> entityMap = new HashMap<>();
|
|
||||||
|
|
||||||
public SimulatorEntityShowMode(Player player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void show(Position position) {
|
|
||||||
RoundedPosition roundedPosition = new RoundedPosition(position);
|
|
||||||
AbstractSimulatorEntity entity = entityMap.computeIfAbsent(roundedPosition, pos -> createEntity(position.getLocation(), false));
|
|
||||||
entity.display(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AbstractSimulatorEntity createEntity(Vector position, boolean 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
|
|
||||||
public void hide() {
|
|
||||||
entityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true));
|
|
||||||
entityMap.clear();
|
|
||||||
}
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren