Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fceb93e8f | |||
| 057c0ae9a0 | |||
| 6ab0d207fc | |||
| e1b1366306 | |||
| 6c651e6d1c | |||
| 3f021933af | |||
| d66f3fe89f | |||
| 4c82469171 | |||
| 633dc67be0 | |||
| ca521f5495 | |||
| 7a598185a0 | |||
| 54b088214f | |||
| c133d57250 | |||
| a0dd017389 | |||
| 863d32ffc3 | |||
| 8061ea52f5 | |||
| 14886eb523 | |||
| bdd681c727 | |||
| 77ae31822f | |||
| 3d9b16f1b1 |
@@ -1,20 +1,18 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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;
|
||||
@@ -46,7 +44,6 @@ import de.steamwar.linkage.SpigotLinker;
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -72,6 +69,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
@Getter
|
||||
private static BauSystem instance;
|
||||
|
||||
@Getter
|
||||
private SpigotLinker linker;
|
||||
|
||||
@Override
|
||||
@@ -129,8 +127,6 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
TraceRecorder.instance.init();
|
||||
|
||||
new WorldEditRendererCUIEditor();
|
||||
|
||||
Bukkit.getWorlds().get(0).setGameRule(GameRule.SEND_COMMAND_FEEDBACK, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -186,7 +182,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (TickManager.impl.isFrozen()) return;
|
||||
if (TickManager.impl.isFrozen())
|
||||
return;
|
||||
if (counter >= delay) {
|
||||
runnable.run();
|
||||
cancel();
|
||||
@@ -204,7 +201,8 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (TickManager.impl.isFrozen()) return;
|
||||
if (TickManager.impl.isFrozen())
|
||||
return;
|
||||
if (counter >= (first ? delay : period)) {
|
||||
first = false;
|
||||
runnable.run();
|
||||
@@ -220,4 +218,4 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
AtomicReference<BukkitTask> task = new AtomicReference<>();
|
||||
task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class BauServer {
|
||||
private Integer owner;
|
||||
|
||||
public UUID getOwner() {
|
||||
return SteamwarUser.byId(getOwnerID()).getUUID();
|
||||
return SteamwarUser.get(getOwnerID()).getUUID();
|
||||
}
|
||||
|
||||
public int getOwnerID() {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class InfoCommand extends SWCommand {
|
||||
|
||||
@Register(description = "BAU_INFO_COMMAND_HELP")
|
||||
public void genericCommand(Player p) {
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.byId(bauServer.getOwnerID()).getUserName());
|
||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_OWNER", p, SteamwarUser.get(bauServer.getOwnerID()).getUserName());
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
for (Flag flag : Flag.getFlags()) {
|
||||
if (!region.getFlags().has(flag).isApplicable()) continue;
|
||||
@@ -97,7 +97,7 @@ public class InfoCommand extends SWCommand {
|
||||
st.append("§8, ");
|
||||
}
|
||||
st.append("§7");
|
||||
st.append(SteamwarUser.byId(bauweltMembers.get(i).getMemberID()).getUserName());
|
||||
st.append(SteamwarUser.get(bauweltMembers.get(i).getMemberID()).getUserName());
|
||||
}
|
||||
return st.toString();
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,6 +31,7 @@ import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.LinkedInstance;
|
||||
import de.steamwar.sql.BauweltMember;
|
||||
import de.steamwar.sql.Punishment;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
@@ -197,7 +198,7 @@ public class TestblockCommand extends SWCommand {
|
||||
@Override
|
||||
public List<String> tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
List<String> stringList = new ArrayList<>(SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s));
|
||||
stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.byId(0), s));
|
||||
stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s));
|
||||
return stringList;
|
||||
}
|
||||
|
||||
@@ -205,7 +206,7 @@ public class TestblockCommand extends SWCommand {
|
||||
public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) {
|
||||
SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s);
|
||||
if (node == null) {
|
||||
node = SchematicNode.getNodeFromPath(SteamwarUser.byId(0), s);
|
||||
node = SchematicNode.getNodeFromPath(SteamwarUser.get(0), s);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class ScriptHelper {
|
||||
BookMeta meta = (BookMeta) itemStack.getItemMeta();
|
||||
if(!writeable) {
|
||||
meta.setTitle(script.getName());
|
||||
meta.setAuthor(SteamwarUser.byId(script.getUserId()).getUserName());
|
||||
meta.setAuthor(SteamwarUser.get(script.getUserId()).getUserName());
|
||||
}
|
||||
meta.setPages(getScriptPages(script));
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
+1
-1
@@ -89,7 +89,7 @@ public class StorageLib implements LuaLib, Enable, Disable {
|
||||
jsonObject.keySet().forEach(key -> {
|
||||
map.put(key, fromJson(jsonObject.get(key)));
|
||||
});
|
||||
SteamwarUser steamwarUser = SteamwarUser.byId(Integer.parseInt(playerStorage.getName().substring(0, playerStorage.getName().length() - ".json".length())));
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(playerStorage.getName().substring(0, playerStorage.getName().length() - ".json".length())));
|
||||
PLAYER_STORAGE.put(steamwarUser.getUUID(), map);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,20 +1,18 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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;
|
||||
@@ -22,7 +20,9 @@ package de.steamwar.bausystem.features.simulator;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorCursorManager;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
@@ -40,7 +40,7 @@ import java.util.Collection;
|
||||
public class SimulatorCommand extends SWCommand {
|
||||
|
||||
@LinkedInstance
|
||||
public SimulatorCursor simulatorCursor;
|
||||
public SimulatorCursorManager cursorManager;
|
||||
|
||||
public SimulatorCommand() {
|
||||
super("sim", "simulator");
|
||||
@@ -49,12 +49,12 @@ public class SimulatorCommand extends SWCommand {
|
||||
@Register(description = "SIMULATOR_HELP")
|
||||
public void genericCommand(@Validator Player p) {
|
||||
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
|
||||
simulatorCursor.calcCursor(p);
|
||||
cursorManager.showCursor(p, null);
|
||||
}
|
||||
|
||||
@Register(value = "change", description = "SIMULATOR_CHANGE_HELP")
|
||||
public void change(@Validator Player p) {
|
||||
if (!SimulatorCursor.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorCursor.isSimulatorItem(p.getInventory().getItemInOffHand())) {
|
||||
if (!SimulatorUtils.isSimulatorItem(p.getInventory().getItemInMainHand()) && !SimulatorUtils.isSimulatorItem(p.getInventory().getItemInOffHand())) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
|
||||
return;
|
||||
}
|
||||
|
||||
-472
@@ -1,472 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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 com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.SWUtils;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.utils.BauMemberUpdateEvent;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.MinVersion;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Linked
|
||||
@MinVersion(19)
|
||||
public class SimulatorCursor implements Listener {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private Class<?> position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
|
||||
private Class<?> look = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot");
|
||||
private Class<?> positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
|
||||
|
||||
private static Map<Player, CursorType> cursorType = Collections.synchronizedMap(new HashMap<>());
|
||||
private static Map<Player, REntityServer> cursors = Collections.synchronizedMap(new HashMap<>());
|
||||
private static final Set<Player> calculating = new HashSet<>();
|
||||
|
||||
public static boolean isSimulatorItem(ItemStack itemStack) {
|
||||
return ItemUtils.isItem(itemStack, "simulator");
|
||||
}
|
||||
|
||||
public SimulatorCursor() {
|
||||
BiFunction<Player, Object, Object> function = (player, object) -> {
|
||||
calcCursor(player);
|
||||
return object;
|
||||
};
|
||||
TinyProtocol.instance.addFilter(position, function);
|
||||
TinyProtocol.instance.addFilter(look, function);
|
||||
TinyProtocol.instance.addFilter(positionLook, function);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
calcCursor(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
|
||||
event.getChanged().forEach(SimulatorCursor::calcCursor);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
cursorType.remove(event.getPlayer());
|
||||
cursors.remove(event.getPlayer());
|
||||
synchronized (calculating) {
|
||||
calculating.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<Player, Long> LAST_SNEAKS = new HashMap<>();
|
||||
|
||||
static {
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
long millis = System.currentTimeMillis();
|
||||
LAST_SNEAKS.entrySet().removeIf(entry -> millis - entry.getValue() > 200);
|
||||
}, 1, 1);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerToggleSneak(PlayerToggleSneakEvent event) {
|
||||
if (!event.isSneaking()) return;
|
||||
Player player = event.getPlayer();
|
||||
if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) {
|
||||
return;
|
||||
}
|
||||
if (LAST_SNEAKS.containsKey(player)) {
|
||||
CursorType currentType = cursorType.getOrDefault(player, CursorType.TNT);
|
||||
if (currentType == CursorType.TNT) {
|
||||
cursorType.put(player, CursorType.REDSTONE_BLOCK);
|
||||
} else {
|
||||
cursorType.put(player, CursorType.TNT);
|
||||
}
|
||||
calcCursor(player);
|
||||
} else {
|
||||
LAST_SNEAKS.put(player, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
public static CursorType getCursorType(Player player) {
|
||||
return cursorType.getOrDefault(player, CursorType.TNT);
|
||||
}
|
||||
|
||||
public static void setCursorType(Player player, CursorType cursorType) {
|
||||
SimulatorCursor.cursorType.put(player, cursorType);
|
||||
calcCursor(player);
|
||||
}
|
||||
|
||||
public static void calcCursor(Player player) {
|
||||
synchronized (calculating) {
|
||||
if (calculating.contains(player)) return;
|
||||
calculating.add(player);
|
||||
}
|
||||
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Simulator simulator = SimulatorStorage.getSimulator(player);
|
||||
if (simulator != null && simulator.getStabGenerator() != null) {
|
||||
removeCursor(player);
|
||||
SimulatorWatcher.show(null, player);
|
||||
SWUtils.sendToActionbar(player, "§cGenerating Stab");
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SimulatorWatcher.show(simulator, player);
|
||||
List<REntity> entities = SimulatorWatcher.getEntitiesOfSimulator(simulator);
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), entities);
|
||||
if (rayTraceResult == null) {
|
||||
removeCursor(player);
|
||||
if (simulator == null) {
|
||||
SWUtils.sendToActionbar(player, "§eSelect Simulator");
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eOpen Simulator");
|
||||
}
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
showCursor(player, rayTraceResult, simulator != null);
|
||||
synchronized (calculating) {
|
||||
calculating.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized boolean removeCursor(Player player) {
|
||||
REntityServer entityServer = cursors.get(player);
|
||||
boolean hadCursor = entityServer != null && !entityServer.getEntities().isEmpty();
|
||||
if (entityServer != null) {
|
||||
entityServer.getEntities().forEach(REntity::die);
|
||||
}
|
||||
return hadCursor;
|
||||
}
|
||||
|
||||
private static synchronized void showCursor(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, boolean hasSimulatorSelected) {
|
||||
REntityServer entityServer = cursors.computeIfAbsent(player, __ -> {
|
||||
REntityServer rEntityServer = new REntityServer();
|
||||
rEntityServer.addPlayer(player);
|
||||
return rEntityServer;
|
||||
});
|
||||
|
||||
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
||||
REntity hitEntity = rayTraceResult.getHitEntity();
|
||||
Location location = hitEntity != null ? new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD) :
|
||||
type.position.apply(player, rayTraceResult).toLocation(WORLD);
|
||||
|
||||
Material material = hitEntity != null ? Material.GLASS : type.getMaterial();
|
||||
List<RFallingBlockEntity> entities = entityServer.getEntitiesByType(RFallingBlockEntity.class);
|
||||
entities.removeIf(rFallingBlockEntity -> {
|
||||
if (rFallingBlockEntity.getMaterial() != material) {
|
||||
rFallingBlockEntity.die();
|
||||
return true;
|
||||
}
|
||||
rFallingBlockEntity.move(location);
|
||||
return false;
|
||||
});
|
||||
if (entities.isEmpty()) {
|
||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, location, material);
|
||||
rFallingBlockEntity.setNoGravity(true);
|
||||
if (material == Material.GLASS) {
|
||||
rFallingBlockEntity.setGlowing(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSimulatorSelected) {
|
||||
if (hitEntity != null) {
|
||||
SWUtils.sendToActionbar(player, "§eEdit Position");
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eAdd new " + type.name);
|
||||
}
|
||||
} else {
|
||||
SWUtils.sendToActionbar(player, "§eCreate new Simulator");
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector getPosFree(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (face.getModY() == 0 && player.isSneaking()) {
|
||||
pos.setY(pos.getY() - 0.49);
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.isSneaking()) {
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (face == null || face.getModY() == 0)
|
||||
pos.setY(pos.getBlockY() + 0.0);
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
private static Vector getPosBlockAligned(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
Vector pos = result.getHitPosition();
|
||||
|
||||
BlockFace face = result.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) {
|
||||
pos.setY(pos.getBlockY() + 1.0);
|
||||
} else {
|
||||
pos.setY(pos.getBlockY());
|
||||
}
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum CursorType {
|
||||
TNT(Material.TNT, Material.GUNPOWDER, SimulatorCursor::getPosFree, "TNT", vector -> new TNTElement(vector).add(new TNTPhase())),
|
||||
REDSTONE_BLOCK(Material.REDSTONE_BLOCK, Material.REDSTONE, SimulatorCursor::getPosBlockAligned, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase())),
|
||||
OBSERVER(Material.OBSERVER, Material.QUARTZ, SimulatorCursor::getPosBlockAligned, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase())),
|
||||
;
|
||||
|
||||
public final Material material;
|
||||
public final Material nonSelectedMaterial;
|
||||
public final BiFunction<Player, RayTraceUtils.RRayTraceResult, Vector> position;
|
||||
public final String name;
|
||||
public final Function<Vector, SimulatorElement<?>> elementFunction;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
Player player = event.getPlayer();
|
||||
Simulator simulator = SimulatorStorage.getSimulator(player);
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (simulator == null) {
|
||||
return;
|
||||
}
|
||||
SimulatorExecutor.run(event.getPlayer(), simulator, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(player, player.getLocation(), SimulatorWatcher.getEntitiesOfSimulator(simulator));
|
||||
if (simulator == null) {
|
||||
if (rayTraceResult == null) {
|
||||
SimulatorStorage.openSimulatorSelector(player);
|
||||
} else {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "Name");
|
||||
anvilInv.setCallback(s -> {
|
||||
Simulator sim = SimulatorStorage.getSimulator(s);
|
||||
if (sim != null) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", player);
|
||||
return;
|
||||
}
|
||||
if (!s.matches("[a-zA-Z_0-9-]+")) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", player);
|
||||
return;
|
||||
}
|
||||
sim = new Simulator(s);
|
||||
SimulatorStorage.addSimulator(s, sim);
|
||||
createElement(player, rayTraceResult, sim);
|
||||
SimulatorStorage.setSimulator(player, sim);
|
||||
});
|
||||
anvilInv.open();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (rayTraceResult == null) {
|
||||
new SimulatorGui(player, simulator).open();
|
||||
return;
|
||||
}
|
||||
|
||||
if (rayTraceResult.getHitEntity() != null) {
|
||||
REntity hitEntity = rayTraceResult.getHitEntity();
|
||||
Vector vector = new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ());
|
||||
List<SimulatorElement<?>> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream).filter(element -> {
|
||||
return element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
switch (elements.size()) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
// Open single element present in Simulator
|
||||
SimulatorElement<?> element = elements.get(0);
|
||||
SimulatorGroup group1 = element.getGroup(simulator);
|
||||
SimulatorBaseGui back = new SimulatorGui(player, simulator);
|
||||
if (group1.getElements().size() > 1) {
|
||||
back = new SimulatorGroupGui(player, simulator, group1, back);
|
||||
}
|
||||
element.open(player, simulator, group1, back);
|
||||
break;
|
||||
default:
|
||||
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().collect(Collectors.toList());
|
||||
if (parents.size() == 1) {
|
||||
// Open multi element present in Simulator in existing group
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, parents.get(0), simulatorGui).open();
|
||||
} else {
|
||||
// Open multi element present in Simulator in implicit group
|
||||
SimulatorGroup group2 = new SimulatorGroup();
|
||||
group2.setMaterial(null);
|
||||
group2.getElements().addAll(elements);
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
new SimulatorGroupGui(player, simulator, group2, simulatorGui).open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Add new Element to current simulator
|
||||
createElement(player, rayTraceResult, simulator);
|
||||
}
|
||||
|
||||
private void createElement(Player player, RayTraceUtils.RRayTraceResult rayTraceResult, Simulator simulator) {
|
||||
CursorType type = cursorType.getOrDefault(player, CursorType.TNT);
|
||||
Vector vector = type.position.apply(player, rayTraceResult);
|
||||
if (type == CursorType.REDSTONE_BLOCK) {
|
||||
vector.subtract(new Vector(0.5, 0, 0.5));
|
||||
}
|
||||
SimulatorElement<?> element = type.elementFunction.apply(vector);
|
||||
SimulatorGroup group = new SimulatorGroup().add(element);
|
||||
simulator.getGroups().add(group);
|
||||
SimulatorGui simulatorGui = new SimulatorGui(player, simulator);
|
||||
element.open(player, simulator, group, simulatorGui);
|
||||
SimulatorWatcher.update(simulator);
|
||||
calcCursor(player);
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.ASimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.display.EmptySimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursorMode;
|
||||
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.MinVersion;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.*;
|
||||
|
||||
// TODO fix memory leak when players leave the server
|
||||
// TODO fix cursor not being hidden when player deequips simulator item
|
||||
|
||||
@Linked
|
||||
@MinVersion(19)
|
||||
public class SimulatorCursorManager implements Listener {
|
||||
public static final SimulatorCursorManager INSTANCE = new SimulatorCursorManager();
|
||||
|
||||
private final Map<Player, Map<Simulator, ASimulatorCursor>> openCursorsByPlayerBySimulator = new HashMap<>();
|
||||
private final Map<Player, ASimulatorCursor> activeCursorByPlayer = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemEquip(PlayerItemHeldEvent event) {
|
||||
ItemStack newItem = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||
if (SimulatorUtils.isSimulatorItem(newItem)) {
|
||||
Simulator simulator = SimulatorStorage.getSimulator(newItem);
|
||||
showCursor(event.getPlayer(), simulator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the cursor for the given simulator to the given player. Shows an empty cursor if the
|
||||
* simulator is null.
|
||||
*/
|
||||
public void showCursor(Player player, Simulator simulator) {
|
||||
var currentActiveCursor = activeCursorByPlayer.get(player);
|
||||
if (currentActiveCursor != null) {
|
||||
currentActiveCursor.hide();
|
||||
}
|
||||
|
||||
var cursorMode = currentActiveCursor != null ? currentActiveCursor.getCursorMode() : SimulatorCursorMode.TNT;
|
||||
|
||||
var cursorsBySimulator = openCursorsByPlayerBySimulator.computeIfAbsent(player, __ -> new HashMap<>());
|
||||
var cursor = cursorsBySimulator.get(simulator);
|
||||
if (cursor == null) {
|
||||
if (simulator == null) {
|
||||
ASimulatorCursor emptyCursor = new EmptySimulatorCursor(player, cursorMode);
|
||||
cursorsBySimulator.put(simulator, emptyCursor);
|
||||
cursor = emptyCursor;
|
||||
} else {
|
||||
ASimulatorCursor newCursor = new SimulatorCursor(simulator, player, cursorMode);
|
||||
cursorsBySimulator.put(simulator, newCursor);
|
||||
cursor = newCursor;
|
||||
}
|
||||
}
|
||||
|
||||
cursor.show();
|
||||
}
|
||||
|
||||
public Optional<SimulatorCursorMode> getActiveCursorMode(Player player) {
|
||||
var currentActiveCursor = activeCursorByPlayer.get(player);
|
||||
if (currentActiveCursor != null) {
|
||||
return Optional.of(currentActiveCursor.getCursorMode());
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public void setActiveCursorMode(Player player, SimulatorCursorMode mode) {
|
||||
var currentActiveCursor = activeCursorByPlayer.get(player);
|
||||
if (currentActiveCursor != null) {
|
||||
currentActiveCursor.setCursorMode(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-25
@@ -1,20 +1,18 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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;
|
||||
@@ -56,12 +54,13 @@ public class SimulatorStorage implements Enable {
|
||||
|
||||
public static Simulator getSimulator(Player player) {
|
||||
Simulator simulator = getSimulator(player.getInventory().getItemInMainHand());
|
||||
if (simulator != null) return simulator;
|
||||
if (simulator != null)
|
||||
return simulator;
|
||||
return getSimulator(player.getInventory().getItemInOffHand());
|
||||
}
|
||||
|
||||
public static Simulator getSimulator(ItemStack itemStack) {
|
||||
if (!SimulatorCursor.isSimulatorItem(itemStack)) {
|
||||
if (!SimulatorUtils.isSimulatorItem(itemStack)) {
|
||||
return null;
|
||||
}
|
||||
String selection = ItemUtils.getTag(itemStack, simulatorSelection);
|
||||
@@ -86,11 +85,11 @@ public class SimulatorStorage implements Enable {
|
||||
YAPIONFormatSimulatorLoader yapionFormatSimulatorLoader = new YAPIONFormatSimulatorLoader();
|
||||
|
||||
File[] files = simulatorsDir.listFiles();
|
||||
if (files == null) return;
|
||||
if (files == null)
|
||||
return;
|
||||
for (File file : files) {
|
||||
try {
|
||||
List<Simulator> simulators = simFormatSimulatorLoader.load(file)
|
||||
.orElse(null);
|
||||
List<Simulator> simulators = simFormatSimulatorLoader.load(file).orElse(null);
|
||||
if (simulators != null) {
|
||||
simulators.forEach(simulator -> {
|
||||
simulatorMap.put(simulator.getName(), simulator);
|
||||
@@ -102,8 +101,7 @@ public class SimulatorStorage implements Enable {
|
||||
}
|
||||
|
||||
try {
|
||||
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file)
|
||||
.orElse(null);
|
||||
List<Simulator> simulators = simulatorFormatSimulatorLoader.load(file).orElse(null);
|
||||
if (simulators != null) {
|
||||
simulators.forEach(simulator -> {
|
||||
simulatorMap.put(simulator.getName(), simulator);
|
||||
@@ -116,8 +114,7 @@ public class SimulatorStorage implements Enable {
|
||||
}
|
||||
|
||||
try {
|
||||
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file)
|
||||
.orElse(null);
|
||||
List<Simulator> simulators = yapionFormatSimulatorLoader.load(file).orElse(null);
|
||||
if (simulators != null) {
|
||||
simulators.forEach(simulator -> {
|
||||
simulatorMap.put(simulator.getName(), simulator);
|
||||
@@ -131,7 +128,8 @@ public class SimulatorStorage implements Enable {
|
||||
}
|
||||
|
||||
public static void openSimulatorSelector(Player player) {
|
||||
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9, simulatorMap.values().stream().sorted(Comparator.comparing(Simulator::getName)).collect(Collectors.toList())) {
|
||||
SimulatorPageGui<Simulator> simulatorPageGui = new SimulatorPageGui<Simulator>(player, null, 6 * 9,
|
||||
simulatorMap.values().stream().sorted(Comparator.comparing(Simulator::getName)).collect(Collectors.toList())) {
|
||||
@Override
|
||||
public String baseTitle() {
|
||||
return "Simulators";
|
||||
@@ -171,7 +169,11 @@ public class SimulatorStorage implements Enable {
|
||||
}
|
||||
|
||||
public static ItemStack getWand(Player p) {
|
||||
ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME", p), Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_1", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_2", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_3", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_4", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_5", p)), false, null).getItemStack();
|
||||
ItemStack itemStack = new SWItem(Material.BLAZE_ROD, BauSystem.MESSAGE.parse("SIMULATOR_WAND_NAME", p),
|
||||
Arrays.asList(BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_1", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_2", p),
|
||||
BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_3", p), BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_4", p),
|
||||
BauSystem.MESSAGE.parse("SIMULATOR_WAND_LORE_5", p)),
|
||||
false, null).getItemStack();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.setCustomModelData(1);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
@@ -183,9 +185,9 @@ public class SimulatorStorage implements Enable {
|
||||
ItemStack mainHand = player.getInventory().getItemInMainHand();
|
||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||
ItemStack itemStack;
|
||||
if (SimulatorCursor.isSimulatorItem(mainHand)) {
|
||||
if (SimulatorUtils.isSimulatorItem(mainHand)) {
|
||||
itemStack = mainHand;
|
||||
} else if (SimulatorCursor.isSimulatorItem(offHand)) {
|
||||
} else if (SimulatorUtils.isSimulatorItem(offHand)) {
|
||||
itemStack = offHand;
|
||||
} else {
|
||||
itemStack = null;
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package de.steamwar.bausystem.features.simulator;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class SimulatorUtils {
|
||||
public static boolean isSimulatorItem(ItemStack itemStack) {
|
||||
return ItemUtils.isItem(itemStack, "simulator");
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import de.steamwar.linkage.MinVersion;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class SimulatorWatcher {
|
||||
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private Map<Simulator, REntityServer> entityServers = new HashMap<>();
|
||||
private Map<Player, Pair<Simulator, Runnable>> watchers = new HashMap<>();
|
||||
|
||||
public void watch(Player player, Simulator simulator, Runnable watcher) {
|
||||
if (simulator == null || watcher == null) {
|
||||
watchers.remove(player);
|
||||
} else {
|
||||
watchers.put(player, new Pair<>(simulator, watcher));
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void update(Simulator simulator) {
|
||||
REntityServer rEntityServer = entityServers.get(simulator);
|
||||
if (rEntityServer != null) {
|
||||
rEntityServer.getEntities().forEach(REntity::die);
|
||||
createSim(rEntityServer, simulator);
|
||||
}
|
||||
|
||||
new ArrayList<>(watchers.values()).forEach(simulatorRunnablePair -> {
|
||||
if (simulatorRunnablePair.getKey() == simulator) {
|
||||
simulatorRunnablePair.getValue().run();
|
||||
}
|
||||
});
|
||||
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
|
||||
}
|
||||
|
||||
@Linked
|
||||
@MinVersion(19)
|
||||
public static class QuitListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
watchers.remove(event.getPlayer());
|
||||
show(null, event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private REntityServer createSim(REntityServer server, Simulator simulator) {
|
||||
if (simulator == null) {
|
||||
return null;
|
||||
}
|
||||
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
||||
simulator.getGroups().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).collect(Collectors.toList())).flatMap(List::stream).forEach(pair -> {
|
||||
SimulatorGroup group = pair.getKey();
|
||||
SimulatorElement<?> element = pair.getValue();
|
||||
|
||||
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>())
|
||||
.add(element.getClass());
|
||||
if (!wasNotPresent) return;
|
||||
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
|
||||
Location location = element.getWorldPos().toLocation(WORLD);
|
||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
|
||||
rFallingBlockEntity.setNoGravity(true);
|
||||
});
|
||||
return server;
|
||||
}
|
||||
|
||||
public synchronized boolean show(Simulator sim, Player player) {
|
||||
AtomicBoolean removed = new AtomicBoolean();
|
||||
entityServers.forEach((simulator, rEntityServer) -> {
|
||||
if (rEntityServer == null) return;
|
||||
if (rEntityServer.getPlayers().contains(player) && sim != simulator) {
|
||||
rEntityServer.removePlayer(player);
|
||||
removed.set(true);
|
||||
}
|
||||
});
|
||||
if (sim == null) return removed.get();
|
||||
entityServers.computeIfAbsent(sim, __ -> createSim(new REntityServer(), sim)).addPlayer(player);
|
||||
return removed.get();
|
||||
}
|
||||
|
||||
synchronized List<REntity> getEntitiesOfSimulator(Simulator simulator) {
|
||||
REntityServer entityServer = entityServers.get(simulator);
|
||||
if (entityServer == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return entityServer.getEntities();
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package de.steamwar.bausystem.features.simulator.display;
|
||||
|
||||
import java.util.List;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import de.steamwar.bausystem.utils.cursor.Cursor;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
|
||||
public abstract class ASimulatorCursor extends Cursor implements Listener {
|
||||
protected final Player owner;
|
||||
|
||||
@Getter
|
||||
protected SimulatorCursorMode cursorMode;
|
||||
|
||||
protected ASimulatorCursor(Player owner, REntityServer targetServer, SimulatorCursorMode cursorMode) {
|
||||
super(targetServer, owner, Material.GLASS, Material.TNT, List.of(Cursor.CursorMode.FREE, Cursor.CursorMode.BLOCK_ALIGNED));
|
||||
this.cursorMode = cursorMode;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public void swapCursorMode() {
|
||||
cursorMode = cursorMode.switchType();
|
||||
setCursorMaterial(cursorMode.getMaterial());
|
||||
setAllowedCursorModes(cursorMode.getAllowedCursorModes());
|
||||
}
|
||||
|
||||
public void setCursorMode(SimulatorCursorMode mode) {
|
||||
this.cursorMode = mode;
|
||||
setCursorMaterial(cursorMode.getMaterial());
|
||||
setAllowedCursorModes(cursorMode.getAllowedCursorModes());
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
super.hide();
|
||||
super.getTargetServer().removePlayer(owner);
|
||||
}
|
||||
|
||||
public void show() {
|
||||
super.show();
|
||||
super.getTargetServer().addPlayer(owner);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerShift(PlayerToggleSneakEvent event) {
|
||||
if (event.getPlayer() != owner) {
|
||||
return;
|
||||
}
|
||||
swapCursorMode();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package de.steamwar.bausystem.features.simulator.display;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
|
||||
public class EmptySimulatorCursor extends ASimulatorCursor {
|
||||
public EmptySimulatorCursor(Player owner, SimulatorCursorMode cursorMode) {
|
||||
super(owner, new REntityServer(), cursorMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Optional<Location> clickedLocation, boolean clickedOnEntity, Action clickAction) {
|
||||
if (clickAction == Action.RIGHT_CLICK_AIR) {
|
||||
SimulatorStorage.openSimulatorSelector(owner);
|
||||
} else if (clickAction == Action.RIGHT_CLICK_BLOCK) {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(owner, "Name");
|
||||
anvilInv.setCallback(name -> {
|
||||
Simulator sim = SimulatorStorage.getSimulator(name);
|
||||
if (sim != null) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_ALREADY_EXISTS", owner);
|
||||
return;
|
||||
}
|
||||
if (!name.matches("[a-zA-Z_0-9-]+")) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_NAME_INVALID", owner);
|
||||
return;
|
||||
}
|
||||
sim = new Simulator(name);
|
||||
SimulatorStorage.addSimulator(name, sim);
|
||||
SimulatorElement<?> element = cursorMode.getElementFunction().apply(clickedLocation.get().toVector());
|
||||
SimulatorGroup group = new SimulatorGroup();
|
||||
group.add(element);
|
||||
sim.add(group);
|
||||
SimulatorStorage.setSimulator(owner, sim);
|
||||
});
|
||||
anvilInv.open();
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package de.steamwar.bausystem.features.simulator.display;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.util.Vector;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.SimulatorGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
|
||||
public class SimulatorCursor extends ASimulatorCursor {
|
||||
private final Simulator simulator;
|
||||
|
||||
public SimulatorCursor(Simulator simulator, Player owner, SimulatorCursorMode cursorMode) {
|
||||
super(owner, SimulatorRenderer.renderSimulator(simulator), cursorMode);
|
||||
|
||||
this.simulator = simulator;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(Optional<Location> clickedLocation, boolean clickedOnEntity, Action clickAction) {
|
||||
if (clickAction == Action.LEFT_CLICK_AIR || clickAction == Action.LEFT_CLICK_BLOCK) {
|
||||
SimulatorExecutor.run(owner, simulator, null);
|
||||
} else if (!clickedOnEntity || clickedLocation.isEmpty()) {
|
||||
new SimulatorGui(owner, simulator);
|
||||
} else {
|
||||
Vector vector = clickedLocation.get().toVector();
|
||||
List<SimulatorElement<?>> elements = simulator.getGroups().stream().map(SimulatorGroup::getElements).flatMap(List::stream)
|
||||
.filter(element -> element.getWorldPos().distanceSquared(vector) < (1 / 16.0) * (1 / 16.0)).toList();
|
||||
|
||||
switch (elements.size()) {
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
// Open single element present in Simulator
|
||||
SimulatorElement<?> element = elements.get(0);
|
||||
SimulatorGroup group1 = element.getGroup(simulator);
|
||||
SimulatorBaseGui back = new SimulatorGui(owner, simulator);
|
||||
if (group1.getElements().size() > 1) {
|
||||
back = new SimulatorGroupGui(owner, simulator, group1, back);
|
||||
}
|
||||
element.open(owner, simulator, group1, back);
|
||||
break;
|
||||
default:
|
||||
List<SimulatorGroup> parents = elements.stream().map(e -> e.getGroup(simulator)).distinct().toList();
|
||||
if (parents.size() == 1) {
|
||||
// Open multi element present in Simulator in existing group
|
||||
SimulatorGui simulatorGui = new SimulatorGui(owner, simulator);
|
||||
new SimulatorGroupGui(owner, simulator, parents.get(0), simulatorGui).open();
|
||||
} else {
|
||||
// Open multi element present in Simulator in implicit group
|
||||
SimulatorGroup group2 = new SimulatorGroup();
|
||||
group2.setMaterial(null);
|
||||
group2.getElements().addAll(elements);
|
||||
SimulatorGui simulatorGui = new SimulatorGui(owner, simulator);
|
||||
new SimulatorGroupGui(owner, simulator, group2, simulatorGui).open();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package de.steamwar.bausystem.features.simulator.display;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.util.Vector;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||
import de.steamwar.bausystem.utils.cursor.Cursor.CursorMode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum SimulatorCursorMode {
|
||||
TNT(Material.TNT, Material.GUNPOWDER, "TNT", vector -> new TNTElement(vector).add(new TNTPhase()),
|
||||
List.of(CursorMode.FREE, CursorMode.BLOCK_ALIGNED)), REDSTONE_BLOCK(Material.REDSTONE_BLOCK, Material.REDSTONE_WIRE, "Redstone Block",
|
||||
vector -> new RedstoneElement(vector).add(new RedstonePhase()), List.of(CursorMode.BLOCK_ALIGNED)), OBSERVER(Material.OBSERVER, Material.QUARTZ,
|
||||
"Observer", vector -> new ObserverElement(vector).add(new ObserverPhase()), List.of(CursorMode.BLOCK_ALIGNED)),;
|
||||
|
||||
public final Material material;
|
||||
public final Material nonSelectedMaterial;
|
||||
public final String name;
|
||||
public final Function<Vector, SimulatorElement<?>> elementFunction;
|
||||
public final List<CursorMode> allowedCursorModes;
|
||||
|
||||
public SimulatorCursorMode switchType() {
|
||||
if (this == TNT) {
|
||||
return REDSTONE_BLOCK;
|
||||
}
|
||||
if (this == REDSTONE_BLOCK) {
|
||||
return OBSERVER;
|
||||
}
|
||||
return TNT;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.display;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.storage.SimulatorSaver;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class SimulatorRenderer implements Listener {
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private Map<Simulator, REntityServer> entityServers = new HashMap<>();
|
||||
|
||||
public synchronized void update(Simulator simulator) {
|
||||
renderSimulator(simulator);
|
||||
|
||||
SimulatorSaver.saveSimulator(SimulatorStorage.simulatorsDir, simulator);
|
||||
}
|
||||
|
||||
public REntityServer renderSimulator(Simulator simulator) {
|
||||
if (simulator == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
REntityServer server = entityServers.computeIfAbsent(simulator, __ -> new REntityServer());
|
||||
|
||||
server.getEntities().forEach(REntity::die);
|
||||
|
||||
Map<Vector, Set<Class<?>>> positionCache = new HashMap<>();
|
||||
simulator.getGroups().stream().map(group -> group.getElements().stream().map(element -> new Pair<>(group, element)).toList()).flatMap(List::stream)
|
||||
.forEach(pair -> {
|
||||
SimulatorGroup group = pair.getKey();
|
||||
SimulatorElement<?> element = pair.getValue();
|
||||
|
||||
boolean wasNotPresent = positionCache.computeIfAbsent(element.getPosition(), __ -> new HashSet<>()).add(element.getClass());
|
||||
if (!wasNotPresent)
|
||||
return;
|
||||
Material material = group.isDisabled() || element.isDisabled() ? element.getWorldDisabledMaterial() : element.getWorldMaterial();
|
||||
Location location = element.getWorldPos().toLocation(WORLD);
|
||||
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(server, location, material);
|
||||
rFallingBlockEntity.setNoGravity(true);
|
||||
});
|
||||
return server;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -20,7 +20,7 @@
|
||||
package de.steamwar.bausystem.features.simulator.execute;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar;
|
||||
import de.steamwar.bausystem.utils.bossbar.BossBarService;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -72,7 +72,7 @@ public abstract class StabStep {
|
||||
|
||||
protected final void stop() {
|
||||
data.simulator.setStabGenerator(null);
|
||||
SimulatorWatcher.update(data.simulator);
|
||||
SimulatorRenderer.update(data.simulator);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
BauSystemBossbar bossbar = BossBarService.instance.get(player, data.region, "simulator_stab_generator");
|
||||
|
||||
+18
-20
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorCursor;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorCursorManager;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursorMode;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class SimulatorCursorSwitcherGui extends SimulatorBaseGui {
|
||||
private final SimulatorCursorManager cursorManager = BauSystem.getInstance().getLinker().get(SimulatorCursorManager.class).orElseThrow();
|
||||
|
||||
private SimulatorBaseGui back;
|
||||
|
||||
@@ -50,14 +50,12 @@ public class SimulatorCursorSwitcherGui extends SimulatorBaseGui {
|
||||
}).setCustomModelData(CMDs.BACK));
|
||||
|
||||
int slot = 2;
|
||||
SimulatorCursor.CursorType currentType = SimulatorCursor.getCursorType(player);
|
||||
for (SimulatorCursor.CursorType type : SimulatorCursor.CursorType.values()) {
|
||||
SimulatorCursorMode currentType = cursorManager.getActiveCursorMode(player).orElse(SimulatorCursorMode.TNT);
|
||||
for (SimulatorCursorMode type : SimulatorCursorMode.values()) {
|
||||
boolean selected = type == currentType;
|
||||
SWItem swItem = new SWItem(selected ? type.material : type.nonSelectedMaterial, "§e" + type.name)
|
||||
.setCustomModelData(selected ? 0 : CMDs.Simulator.NEW_PHASE)
|
||||
.setLore(Collections.singletonList("§eClick to select"))
|
||||
.setCallback(click -> {
|
||||
SimulatorCursor.setCursorType(player, type);
|
||||
.setCustomModelData(selected ? 0 : CMDs.Simulator.NEW_PHASE).setLore(Collections.singletonList("§eClick to select")).setCallback(click -> {
|
||||
cursorManager.setActiveCursorMode(player, type);
|
||||
player.closeInventory();
|
||||
});
|
||||
inventory.setItem(slot, swItem);
|
||||
|
||||
+17
-16
@@ -1,28 +1,26 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||
import de.steamwar.inventory.InvCallback;
|
||||
@@ -38,8 +36,11 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
||||
private final SimulatorGroup parent;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject, SimulatorGroup parent, SimulatorBaseGui back) {
|
||||
super(player, simulator, 6 * 9, simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e)).collect(Collectors.toList()));
|
||||
public SimulatorGroupChooserGui(Player player, Simulator simulator, SimulatorElement<?> subject,
|
||||
SimulatorGroup parent, SimulatorBaseGui back) {
|
||||
super(player, simulator, 6 * 9,
|
||||
simulator.getGroups().stream().filter(e -> e != parent).filter(e -> subject.canBeInGroup(e))
|
||||
.collect(Collectors.toList()));
|
||||
this.subject = subject;
|
||||
this.parent = parent;
|
||||
this.back = back;
|
||||
@@ -56,7 +57,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
||||
simulator.getGroups().add(newParent);
|
||||
parent.getElements().remove(subject);
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
if (parent.getElements().size() == 1) {
|
||||
parent.setDisabled(false);
|
||||
parent.setMaterial(Material.BARREL);
|
||||
@@ -83,7 +84,7 @@ public class SimulatorGroupChooserGui extends SimulatorPageGui<SimulatorGroup> {
|
||||
parent.setMaterial(Material.BARREL);
|
||||
}
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
};
|
||||
return simulatorGroup.toItem(player, invCallback, invCallback);
|
||||
}
|
||||
|
||||
+28
-27
@@ -1,28 +1,26 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -60,7 +58,7 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
||||
}
|
||||
|
||||
if (simulatorGroup.getElements().removeIf(element -> element.getPhases().isEmpty())) {
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}
|
||||
if (simulatorGroup.getElements().size() < 2) {
|
||||
back.open();
|
||||
@@ -75,11 +73,12 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
||||
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
simulatorGroup.getElements().clear();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
||||
if (simulatorGroup.getMaterial() == null) return;
|
||||
if (simulatorGroup.getMaterial() == null)
|
||||
return;
|
||||
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
||||
}, clickType -> {
|
||||
}));
|
||||
@@ -87,17 +86,19 @@ public class SimulatorGroupGui extends SimulatorPageGui<SimulatorElement<?>> {
|
||||
inventory.setItem(48, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
new SimulatorGroupSettingsGui(player, simulator, simulatorGroup, this).open();
|
||||
}).setCustomModelData(CMDs.Simulator.SETTINGS));
|
||||
boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled) : simulatorGroup.isDisabled();
|
||||
inventory.setItem(50, new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
if (simulatorGroup.getMaterial() == null) {
|
||||
simulatorGroup.getElements().forEach(simulatorElement -> {
|
||||
simulatorElement.setDisabled(!disabled);
|
||||
});
|
||||
} else {
|
||||
simulatorGroup.setDisabled(!disabled);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
boolean disabled = simulatorGroup.getMaterial() == null ? simulatorGroup.getElements().stream().allMatch(SimulatorElement::isDisabled)
|
||||
: simulatorGroup.isDisabled();
|
||||
inventory.setItem(50,
|
||||
new SWItem(disabled ? Material.ENDER_PEARL : Material.ENDER_EYE, simulatorGroup.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
if (simulatorGroup.getMaterial() == null) {
|
||||
simulatorGroup.getElements().forEach(simulatorElement -> {
|
||||
simulatorElement.setDisabled(!disabled);
|
||||
});
|
||||
} else {
|
||||
simulatorGroup.setDisabled(!disabled);
|
||||
}
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+110
-106
@@ -1,28 +1,26 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -37,7 +35,8 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
private final SimulatorGroup simulatorGroup;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorGroupSettingsGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup, SimulatorBaseGui back) {
|
||||
public SimulatorGroupSettingsGui(Player player, Simulator simulator, SimulatorGroup simulatorGroup,
|
||||
SimulatorBaseGui back) {
|
||||
super(player, simulator, 5 * 9);
|
||||
this.simulatorGroup = simulatorGroup;
|
||||
this.back = back;
|
||||
@@ -62,164 +61,169 @@ public class SimulatorGroupSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
// Material Chooser
|
||||
inventory.setItem(4, simulatorGroup.toItem(player, clickType -> {
|
||||
if (simulatorGroup.getMaterial() == null) return;
|
||||
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this).open();
|
||||
if (simulatorGroup.getMaterial() == null)
|
||||
return;
|
||||
new SimulatorMaterialGui(player, simulator, simulatorGroup::getMaterial, simulatorGroup::setMaterial, this)
|
||||
.open();
|
||||
}, clickType -> {
|
||||
}));
|
||||
|
||||
// Base Tick
|
||||
int baseTicks = simulatorGroup.getBaseTick();
|
||||
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(9,
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
simulatorGroup.changeBaseTicks(integer - baseTicks);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
baseTick.getItemStack().setAmount(Math.max(1, Math.min(baseTicks, 64)));
|
||||
inventory.setItem(18, baseTick);
|
||||
inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
|
||||
simulatorGroup.changeBaseTicks(-baseTicks);
|
||||
} else {
|
||||
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(27, new SWItem(SWItem.getDye(baseTicks > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"),
|
||||
false, clickType -> {
|
||||
if (baseTicks - (clickType.isShiftClick() ? 5 : 1) < 0) {
|
||||
simulatorGroup.changeBaseTicks(-baseTicks);
|
||||
} else {
|
||||
simulatorGroup.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
boolean allTNT = simulatorGroup.getElements().stream().allMatch(TNTElement.class::isInstance);
|
||||
|
||||
if (allTNT) {
|
||||
// Subpixel Alignment
|
||||
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
tntElement.alignX(0);
|
||||
tntElement.alignZ(0);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
|
||||
tntElement.alignX(0);
|
||||
tntElement.alignZ(0);
|
||||
});
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
|
||||
// Z
|
||||
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != -1) tntElement.alignZ(-1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != -1)
|
||||
tntElement.alignZ(-1);
|
||||
});
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
negativZItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == -1));
|
||||
negativZItem.setEnchanted(
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == -1));
|
||||
inventory.setItem(20, negativZItem);
|
||||
|
||||
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != 1) tntElement.alignZ(1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getZ() != 1)
|
||||
tntElement.alignZ(1);
|
||||
});
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
positivZItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == 1));
|
||||
positivZItem.setEnchanted(
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getZ() == 1));
|
||||
inventory.setItem(22, positivZItem);
|
||||
|
||||
// X
|
||||
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != -1) tntElement.alignX(-1);
|
||||
});
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != -1)
|
||||
tntElement.alignX(-1);
|
||||
});
|
||||
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
negativXItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
negativXItem.setEnchanted(
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
inventory.setItem(12, negativXItem);
|
||||
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != 1) tntElement.alignX(1);
|
||||
});
|
||||
SimulatorWatcher.update(simulator);
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast).forEach(tntElement -> {
|
||||
if (tntElement.getAlignment().getX() != 1)
|
||||
tntElement.alignX(1);
|
||||
});
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
positivXItem.setEnchanted(simulatorGroup.getElements().stream()
|
||||
.map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
positivXItem.setEnchanted(
|
||||
simulatorGroup.getElements().stream().map(TNTElement.class::cast)
|
||||
.allMatch(tntElement -> tntElement.getAlignment().getX() == -1));
|
||||
inventory.setItem(30, positivXItem);
|
||||
}
|
||||
|
||||
//Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
// Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0, 0);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative X", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
if (!allTNT) {
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(number, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0, 0);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
// Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1, 0);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative Y", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
if (!allTNT) {
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(0, number, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1, 0);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
|
||||
//Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
// Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e+0.0625" : "§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? 0.0625 : 5) : 1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Relative Z", "", Double::parseDouble, number -> {
|
||||
if(!allTNT){
|
||||
if (!allTNT) {
|
||||
number = (double) Math.round(number);
|
||||
}
|
||||
simulatorGroup.move(0, 0, number);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.PAPER).open();
|
||||
}));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1",
|
||||
Arrays.asList(allTNT ? "§7Shift§8: §e-0.0625" : "§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulatorGroup.move(0, 0, clickType.isShiftClick() ? (allTNT ? -0.0625 : -5) : -1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+21
-17
@@ -1,29 +1,30 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorCursorManager;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursor;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorCursorMode;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
@@ -32,6 +33,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
|
||||
|
||||
private final SimulatorCursorManager cursorManager = BauSystem.getInstance().getLinker().get(SimulatorCursorManager.class).orElseThrow();
|
||||
|
||||
public SimulatorGui(Player player, Simulator simulator) {
|
||||
super(player, simulator, 6 * 9, simulator.getGroups());
|
||||
}
|
||||
@@ -43,14 +46,15 @@ public class SimulatorGui extends SimulatorPageGui<SimulatorGroup> {
|
||||
|
||||
@Override
|
||||
public void headerAndFooter() {
|
||||
if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty() || element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) {
|
||||
SimulatorWatcher.update(simulator);
|
||||
if (simulator.getGroups().removeIf(element -> element.getElements().isEmpty()
|
||||
|| element.getElements().stream().allMatch(simulatorElement -> simulatorElement.getPhases().isEmpty()))) {
|
||||
SimulatorRenderer.update(simulator);
|
||||
}
|
||||
|
||||
inventory.setItem(4, simulator.toItem(player, clickType -> {
|
||||
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
|
||||
}));
|
||||
SimulatorCursor.CursorType cursorType = SimulatorCursor.getCursorType(player);
|
||||
SimulatorCursorMode cursorType = cursorManager.getActiveCursorMode(player).orElse(SimulatorCursorMode.TNT);
|
||||
inventory.setItem(48, new SWItem(cursorType.material, "§7Placing §8-§e " + cursorType.name, clickType -> {
|
||||
new SimulatorCursorSwitcherGui(player, simulator, this).open();
|
||||
}));
|
||||
|
||||
+19
-23
@@ -1,26 +1,24 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorPageGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -36,11 +34,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
|
||||
|
||||
private static final List<Material> MATERIALS = Arrays.stream(Material.values())
|
||||
.filter(material -> !material.isAir())
|
||||
.filter(material -> !material.isLegacy())
|
||||
.filter(Material::isItem)
|
||||
.collect(Collectors.toList());
|
||||
private static final List<Material> MATERIALS = Arrays.stream(Material.values()).filter(material -> !material.isAir())
|
||||
.filter(material -> !material.isLegacy()).filter(Material::isItem).collect(Collectors.toList());
|
||||
|
||||
private final Supplier<Material> currentMaterial;
|
||||
private Material material;
|
||||
@@ -60,7 +55,7 @@ public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
|
||||
return true;
|
||||
}
|
||||
change.accept(player.getItemOnCursor().getType());
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -81,9 +76,10 @@ public class SimulatorMaterialGui extends SimulatorPageGui<Material> {
|
||||
|
||||
@Override
|
||||
public SWItem convert(Material material) {
|
||||
return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material, clickType -> {
|
||||
change.accept(material);
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
return new SWItem(material, "§eNew Material", Arrays.asList(material == this.material ? "§eSelected" : "§eClick to select"), material == this.material,
|
||||
clickType -> {
|
||||
change.accept(material);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+35
-43
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -60,7 +58,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
public void headerAndFooter() {
|
||||
if (observer.getPhases().isEmpty()) {
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
observer.getPhases().clear();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
// Material Chooser
|
||||
@@ -101,10 +99,11 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
}).setCustomModelData(CMDs.Simulator.SETTINGS));
|
||||
|
||||
// Enable/Disable
|
||||
inventory.setItem(48, new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
observer.setDisabled(!observer.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(48,
|
||||
new SWItem(observer.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, observer.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
observer.setDisabled(!observer.isDisabled());
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
|
||||
// Group chooser
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
@@ -139,7 +138,7 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
SWItem observer = new SWItem(Material.OBSERVER, "§eObserver", lore, false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.observer.getPhases().remove(observerPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
} else {
|
||||
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
|
||||
}
|
||||
@@ -148,42 +147,35 @@ public class SimulatorObserverGui extends SimulatorScrollGui<ObserverPhase> {
|
||||
|
||||
Supplier<Integer> getter = observerPhase::getTickOffset;
|
||||
Consumer<Integer> setter = observerPhase::setTickOffset;
|
||||
return new SWItem[] {
|
||||
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
observer,
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), observer,
|
||||
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
||||
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||
new SimulatorObserverPhaseSettingsGui(player, simulator, this.observer, observerPhase, this).open();
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),
|
||||
};
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWItem[] lastColumn() {
|
||||
return new SWItem[]{
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
|
||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
};
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.QUARTZ, "§eObserver§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
|
||||
}
|
||||
|
||||
private void addNewPhase(boolean shift) {
|
||||
ObserverPhase lastElement = observer.getPhases().get(observer.getPhases().size() - 1);
|
||||
ObserverPhase newPhase = new ObserverPhase(lastElement.getTickOffset() + 4);
|
||||
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||
if (shift)
|
||||
newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||
scroll += 2;
|
||||
observer.add(newPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}
|
||||
}
|
||||
|
||||
+50
-44
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverPhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.core.Core;
|
||||
@@ -41,7 +39,8 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
|
||||
private final ObserverPhase observer;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer, SimulatorBaseGui back) {
|
||||
public SimulatorObserverPhaseSettingsGui(Player player, Simulator simulator, ObserverElement observerElement, ObserverPhase observer,
|
||||
SimulatorBaseGui back) {
|
||||
super(player, simulator, 5 * 9);
|
||||
this.observerElement = observerElement;
|
||||
this.observer = observer;
|
||||
@@ -74,7 +73,7 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
observerElement.getPhases().remove(observer);
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
int index = observerElement.getPhases().indexOf(observer);
|
||||
@@ -94,18 +93,19 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
|
||||
max = Integer.MAX_VALUE - 4;
|
||||
}
|
||||
|
||||
//Tick Offset
|
||||
// Tick Offset
|
||||
int offset = observer.getTickOffset();
|
||||
inventory.setItem(10, new SWItem(SWItem.getDye(offset < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.setTickOffset(Math.min(max, offset + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
observer.setTickOffset(Math.min(Math.max(integer, min), max));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -114,60 +114,66 @@ public class SimulatorObserverPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Order
|
||||
// Order
|
||||
int order = observer.getOrder();
|
||||
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(13,
|
||||
new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
|
||||
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> {
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
observer.setOrder(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
|
||||
});
|
||||
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
|
||||
inventory.setItem(22, orderItem);
|
||||
|
||||
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(31,
|
||||
new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
// Update orientation
|
||||
inventory.setItem(25, new SWItem(Material.SUNFLOWER, "§7", clickType -> {
|
||||
}));
|
||||
inventory.setItem(15, new SWItem(observer.getOrientation() == BlockFace.UP ? Material.LIME_CONCRETE : Material.GRAY_CONCRETE, "§eUp", clickType -> {
|
||||
observer.setOrientation(BlockFace.UP);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(observer.getOrientation() == BlockFace.DOWN ? Material.RED_CONCRETE : Material.GRAY_CONCRETE, "§eDown", clickType -> {
|
||||
observer.setOrientation(BlockFace.DOWN);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(16, new SWItem(observer.getOrientation() == BlockFace.NORTH ? Material.LIME_WOOL : Material.GRAY_WOOL, "§eNorth", clickType -> {
|
||||
observer.setOrientation(BlockFace.NORTH);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(observer.getOrientation() == BlockFace.SOUTH ? Material.RED_WOOL : Material.GRAY_WOOL, "§eSouth", clickType -> {
|
||||
observer.setOrientation(BlockFace.SOUTH);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(24, new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> {
|
||||
observer.setOrientation(BlockFace.EAST);
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(26, new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> {
|
||||
observer.setOrientation(BlockFace.WEST);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(24,
|
||||
new SWItem(observer.getOrientation() == BlockFace.EAST ? Material.LIME_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eEast", clickType -> {
|
||||
observer.setOrientation(BlockFace.EAST);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(26,
|
||||
new SWItem(observer.getOrientation() == BlockFace.WEST ? Material.RED_STAINED_GLASS : Material.GRAY_STAINED_GLASS, "§eWest", clickType -> {
|
||||
observer.setOrientation(BlockFace.WEST);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
+29
-30
@@ -1,27 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.observer.ObserverElement;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -68,13 +66,14 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui {
|
||||
int baseTicks = observer.getBaseTick();
|
||||
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
observer.changeBaseTicks(integer - baseTicks);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -86,58 +85,58 @@ public class SimulatorObserverSettingsGui extends SimulatorBaseGui {
|
||||
} else {
|
||||
observer.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
// Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + observer.getPosition().getBlockX(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "X", observer.getPosition().getBlockX() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setX(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Y
|
||||
// Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(0, clickType.isShiftClick() ? 5 : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + observer.getPosition().getBlockY(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Y", observer.getPosition().getBlockY() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setY(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(0, clickType.isShiftClick() ? -5 : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Z
|
||||
// Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
observer.move(0, 0, clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + observer.getPosition().getBlockZ(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Z", observer.getPosition().getBlockZ() + "", Integer::parseInt, i -> {
|
||||
observer.getPosition().setZ(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
observer.move(0, 0, clickType.isShiftClick() ? -5 : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+43
-50
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorScrollGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -61,7 +59,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
|
||||
public void headerAndFooter() {
|
||||
if (redstone.getPhases().isEmpty()) {
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -93,7 +91,7 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
|
||||
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
redstone.getPhases().clear();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
// Material Chooser
|
||||
@@ -107,10 +105,11 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
|
||||
}).setCustomModelData(CMDs.Simulator.SETTINGS));
|
||||
|
||||
// Enable/Disable
|
||||
inventory.setItem(48, new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
redstone.setDisabled(!redstone.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(48,
|
||||
new SWItem(redstone.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, redstone.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
redstone.setDisabled(!redstone.isDisabled());
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
|
||||
// Group chooser
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
@@ -151,55 +150,49 @@ public class SimulatorRedstoneGui extends SimulatorScrollGui<SimulatorRedstoneGu
|
||||
lore.add("");
|
||||
lore.add("§7Click§8:§e Edit");
|
||||
lore.add("§7Middle-Click§8:§e Remove");
|
||||
SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate", lore, false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.redstone.getPhases().remove(redstoneSubPhase.phase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
} else {
|
||||
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
|
||||
}
|
||||
});
|
||||
SWItem redstone = new SWItem(redstoneSubPhase.place ? Material.REDSTONE_BLOCK : Material.STONE, redstoneSubPhase.place ? "§eActivate" : "§eDeactivate",
|
||||
lore, false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.redstone.getPhases().remove(redstoneSubPhase.phase);
|
||||
SimulatorRenderer.update(simulator);
|
||||
} else {
|
||||
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
|
||||
}
|
||||
});
|
||||
redstone.getItemStack().setAmount(Math.max(1, Math.min(time, 64)));
|
||||
|
||||
Supplier<Integer> getter = redstoneSubPhase.place ? redstoneSubPhase.phase::getTickOffset : redstoneSubPhase.phase::getLifetime;
|
||||
Consumer<Integer> setter = redstoneSubPhase.place ? redstoneSubPhase.phase::setTickOffset : redstoneSubPhase.phase::setLifetime;
|
||||
return new SWItem[] {
|
||||
new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
redstone,
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(getter.get() < max ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
setter.accept(Math.min(max, getter.get() + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), redstone,
|
||||
new SWItem(SWItem.getDye(getter.get() > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
||||
setter.accept(Math.max(min, getter.get() - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Activation", clickType -> {
|
||||
new SimulatorRedstonePhaseSettingsGui(player, simulator, this.redstone, redstoneSubPhase.phase, this).open();
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),
|
||||
};
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWItem[] lastColumn() {
|
||||
return new SWItem[]{
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
|
||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
};
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.REDSTONE, "§eRedstone§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
|
||||
}
|
||||
|
||||
private void addNewPhase(boolean shift) {
|
||||
RedstonePhase lastElement = redstone.getPhases().get(redstone.getPhases().size() - 1);
|
||||
RedstonePhase newPhase = new RedstonePhase(lastElement.getTickOffset() + lastElement.getLifetime() + 1);
|
||||
if (shift) newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||
if (shift)
|
||||
newPhase.setTickOffset(newPhase.getTickOffset() + 5);
|
||||
scroll += 2;
|
||||
redstone.add(newPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
|
||||
+42
-37
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstonePhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.core.Core;
|
||||
@@ -39,7 +37,8 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
|
||||
private final RedstonePhase redstone;
|
||||
private final SimulatorBaseGui back;
|
||||
|
||||
public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone, SimulatorBaseGui back) {
|
||||
public SimulatorRedstonePhaseSettingsGui(Player player, Simulator simulator, RedstoneElement redstoneElement, RedstonePhase redstone,
|
||||
SimulatorBaseGui back) {
|
||||
super(player, simulator, 5 * 9);
|
||||
this.redstoneElement = redstoneElement;
|
||||
this.redstone = redstone;
|
||||
@@ -72,7 +71,7 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
redstoneElement.getPhases().remove(redstone);
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
int index = redstoneElement.getPhases().indexOf(redstone);
|
||||
@@ -95,18 +94,19 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
|
||||
maxOffset = Integer.MAX_VALUE - 5;
|
||||
}
|
||||
|
||||
//Tick Offset
|
||||
// Tick Offset
|
||||
int offset = redstone.getTickOffset();
|
||||
inventory.setItem(10, new SWItem(SWItem.getDye(offset < maxOffset ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.setTickOffset(Math.min(maxOffset, offset + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
redstone.setTickOffset(Math.min(Math.max(integer, min), maxOffset));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -115,21 +115,22 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(28, new SWItem(SWItem.getDye(offset > min ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.setTickOffset(Math.max(min, offset - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Lifetime
|
||||
// Lifetime
|
||||
int lifetime = redstone.getLifetime();
|
||||
inventory.setItem(11, new SWItem(SWItem.getDye(lifetime < maxLifetime ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.setLifetime(Math.min(maxLifetime, lifetime + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eActivation Time§8:§7 " + lifetime, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Activation Time", lifetime + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
redstone.setLifetime(Math.min(integer, maxLifetime));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.CLOCK).open();
|
||||
});
|
||||
@@ -138,32 +139,36 @@ public class SimulatorRedstonePhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.setLifetime(Math.max(0, lifetime - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Order
|
||||
// Order
|
||||
int order = redstone.getOrder();
|
||||
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(13,
|
||||
new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
|
||||
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eActivation Order§8:§7 " + order, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Activation Order", order + "", Integer::parseInt, integer -> {
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
redstone.setOrder(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
|
||||
});
|
||||
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
|
||||
inventory.setItem(22, orderItem);
|
||||
|
||||
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(31,
|
||||
new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+28
-29
@@ -1,27 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.redstone.RedstoneElement;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -67,13 +65,14 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
|
||||
int baseTicks = redstone.getBaseTick();
|
||||
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
redstone.changeBaseTicks(integer - baseTicks);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -85,58 +84,58 @@ public class SimulatorRedstoneSettingsGui extends SimulatorBaseGui {
|
||||
} else {
|
||||
redstone.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos X
|
||||
// Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + redstone.getPosition().getBlockX(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "X", redstone.getPosition().getBlockX() + "", Integer::parseInt, i -> {
|
||||
redstone.getPosition().setX(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Y
|
||||
// Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.move(0, clickType.isShiftClick() ? 5 : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + redstone.getPosition().getBlockY(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Y", redstone.getPosition().getBlockY() + "", Integer::parseInt, i -> {
|
||||
redstone.getPosition().setY(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.move(0, clickType.isShiftClick() ? -5 : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Z
|
||||
// Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
redstone.move(0, 0, clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + redstone.getPosition().getBlockZ(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Z", redstone.getPosition().getBlockZ() + "", Integer::parseInt, i -> {
|
||||
redstone.getPosition().setZ(i);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
redstone.move(0, 0, clickType.isShiftClick() ? -5 : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+31
-31
@@ -1,26 +1,24 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
@@ -55,50 +53,52 @@ public class SimulatorSettingsGui extends SimulatorBaseGui {
|
||||
new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
|
||||
}));
|
||||
|
||||
//AutoTrace
|
||||
inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> {
|
||||
simulator.setAutoTrace(!simulator.isAutoTrace());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER, "§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> {
|
||||
simulator.setAutoTestblock(!simulator.isAutoTestblock());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}));
|
||||
// AutoTrace
|
||||
inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK,
|
||||
"§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> {
|
||||
simulator.setAutoTrace(!simulator.isAutoTrace());
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER,
|
||||
"§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> {
|
||||
simulator.setAutoTestblock(!simulator.isAutoTestblock());
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
|
||||
//Pos X
|
||||
// Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Y
|
||||
// Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Pos Z
|
||||
// Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
|
||||
}));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+51
-53
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorGroup;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.execute.SimulatorStabGenerator;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
@@ -60,7 +58,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
public void headerAndFooter() {
|
||||
if (tnt.getPhases().isEmpty()) {
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,7 +85,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
tnt.getPhases().clear();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
// Material Chooser
|
||||
@@ -98,16 +96,18 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
inventory.setItem(47, new SWItem(Material.REPEATER, "§eSettings", clickType -> {
|
||||
new SimulatorTNTSettingsGui(player, simulator, tnt, this).open();
|
||||
}).setCustomModelData(CMDs.Simulator.SETTINGS));
|
||||
inventory.setItem(48, new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
tnt.setDisabled(!tnt.isDisabled());
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
inventory.setItem(48,
|
||||
new SWItem(tnt.isDisabled() ? Material.ENDER_PEARL : Material.ENDER_EYE, tnt.isDisabled() ? "§cDisabled" : "§aEnabled", clickType -> {
|
||||
tnt.setDisabled(!tnt.isDisabled());
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.ENABLED_OR_DISABLED));
|
||||
if (Core.getVersion() > 19) {
|
||||
inventory.setItem(49, new SWItem(Material.CALIBRATED_SCULK_SENSOR, "§eCreate Stab", click -> {
|
||||
new SimulatorAnvilGui<>(player, "Depth Limit", "", Integer::parseInt, depthLimit -> {
|
||||
if (depthLimit <= 0) return false;
|
||||
if (depthLimit <= 0)
|
||||
return false;
|
||||
simulator.setStabGenerator(new SimulatorStabGenerator(Region.getRegion(player.getLocation()), simulator, tnt, depthLimit));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, null).open();
|
||||
}).setCustomModelData(CMDs.Simulator.CREATE_STAB));
|
||||
@@ -117,7 +117,7 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
tntElement.add(new TNTPhase());
|
||||
parent.add(tntElement);
|
||||
new SimulatorGroupGui(player, simulator, parent, new SimulatorGui(player, simulator)).open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.MAKE_GROUP));
|
||||
inventory.setItem(51, new SWItem(Material.LEAD, "§eJoin Group", clickType -> {
|
||||
new SimulatorGroupChooserGui(player, simulator, tnt, tnt.getGroup(simulator), this).open();
|
||||
@@ -126,52 +126,50 @@ public class SimulatorTNTGui extends SimulatorScrollGui<TNTPhase> {
|
||||
|
||||
@Override
|
||||
public SWItem[] column(TNTPhase tntSetting, int index) {
|
||||
SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(), Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "", "§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"), "§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "", "§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"), false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.tnt.getPhases().remove(tntSetting);
|
||||
SimulatorWatcher.update(simulator);
|
||||
} else {
|
||||
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
|
||||
}
|
||||
});
|
||||
SWItem tnt = new SWItem(Material.TNT, "§eTNT§8:§7 " + tntSetting.getCount(),
|
||||
Arrays.asList("§7Tick§8: §e" + tntSetting.getTickOffset(), "§7Fuse§8:§e " + tntSetting.getLifetime(), "",
|
||||
"§7Order§8:§e " + tntSetting.getOrder(), "", "§7X-Jump§8: " + (tntSetting.isXJump() ? "§aOn" : "§cOff"),
|
||||
"§7Y-Jump§8: " + (tntSetting.isYJump() ? "§aOn" : "§cOff"), "§7Z-Jump§8: " + (tntSetting.isZJump() ? "§aOn" : "§cOff"), "",
|
||||
"§7Click§8:§e Edit", "§7Middle-Click§8:§e Remove"),
|
||||
false, clickType -> {
|
||||
if (clickType == ClickType.MIDDLE) {
|
||||
this.tnt.getPhases().remove(tntSetting);
|
||||
SimulatorRenderer.update(simulator);
|
||||
} else {
|
||||
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
|
||||
}
|
||||
});
|
||||
tnt.getItemStack().setAmount(Math.min(tntSetting.getCount(), 64));
|
||||
|
||||
return new SWItem[]{
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
tnt,
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
tntSetting.setCount(tntSetting.getCount() + (clickType.isShiftClick() ? 5 : 1));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), tnt,
|
||||
new SWItem(SWItem.getDye(tntSetting.getCount() > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8:§e -5"), false, clickType -> {
|
||||
tntSetting.setCount(Math.max(1, tntSetting.getCount() - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> {
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED), new SWItem(Material.ANVIL, "§eEdit Phase", clickType -> {
|
||||
new SimulatorTNTPhaseSettingsGui(player, simulator, this.tnt, tntSetting, this).open();
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),
|
||||
};
|
||||
}).setCustomModelData(CMDs.Simulator.EDIT_ACTIVATION),};
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWItem[] lastColumn() {
|
||||
return new SWItem[]{
|
||||
new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED),
|
||||
new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE),
|
||||
new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),
|
||||
};
|
||||
return new SWItem[] {new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8:§e +5"), false, clickType -> {
|
||||
addNewPhase(clickType.isShiftClick());
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED), new SWItem(Material.GUNPOWDER, "§eTNT§8:§a New Phase", clickType -> {
|
||||
addNewPhase(false);
|
||||
}).setCustomModelData(CMDs.Simulator.NEW_PHASE), new SWItem(SWItem.getDye(8), "§7", clickType -> {
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED),};
|
||||
}
|
||||
|
||||
private void addNewPhase(boolean shift) {
|
||||
TNTPhase lastElement = tnt.getPhases().get(tnt.getPhases().size() - 1);
|
||||
TNTPhase newPhase = new TNTPhase(lastElement.getTickOffset() + 1);
|
||||
if (shift) newPhase.setCount(newPhase.getCount() + 5);
|
||||
if (shift)
|
||||
newPhase.setCount(newPhase.getCount() + 5);
|
||||
scroll++;
|
||||
tnt.add(newPhase);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}
|
||||
}
|
||||
|
||||
+64
-56
@@ -1,29 +1,27 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.SimulatorPhase;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTPhase;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.core.Core;
|
||||
@@ -68,25 +66,26 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
|
||||
new SimulatorMaterialGui(player, simulator, tntElement::getMaterial, tntElement::setMaterial, this).open();
|
||||
}));
|
||||
|
||||
//Delete
|
||||
// Delete
|
||||
inventory.setItem(8, new SWItem(Material.BARRIER, "§eDelete", clickType -> {
|
||||
tntElement.getPhases().remove(tnt);
|
||||
back.open();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DELETE));
|
||||
|
||||
//Count
|
||||
// Count
|
||||
int count = tnt.getCount();
|
||||
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.setCount(count + (clickType.isShiftClick() ? 5 : 1));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem countItem = new SWItem(Material.TNT, "§eCount§8:§7 " + count, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Count", count + "", Integer::parseInt, integer -> {
|
||||
if (integer < 1) return false;
|
||||
if (integer < 1)
|
||||
return false;
|
||||
tnt.setCount(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.TNT).open();
|
||||
});
|
||||
@@ -95,21 +94,22 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(27, new SWItem(SWItem.getDye(count > 1 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
tnt.setCount(Math.max(1, count - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Tick Offset
|
||||
// Tick Offset
|
||||
int offset = tnt.getTickOffset();
|
||||
inventory.setItem(10, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.setTickOffset(offset + (clickType.isShiftClick() ? 5 : 1));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem offsetItem = new SWItem(Material.REPEATER, "§eStart at§8:§7 " + offset, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Start at", offset + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
tnt.setTickOffset(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -118,21 +118,22 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(28, new SWItem(SWItem.getDye(offset > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
tnt.setTickOffset(Math.max(0, offset - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Lifetime
|
||||
// Lifetime
|
||||
int lifetime = tnt.getLifetime();
|
||||
inventory.setItem(11, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.setLifetime(lifetime + (clickType.isShiftClick() ? 5 : 1));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
SWItem lifetimeItem = new SWItem(Material.CLOCK, "§eLifetime§8:§7 " + lifetime, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Lifetime", lifetime + "", Integer::parseInt, integer -> {
|
||||
if (integer < 1) return false;
|
||||
if (integer < 1)
|
||||
return false;
|
||||
tnt.setLifetime(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.CLOCK).open();
|
||||
});
|
||||
@@ -141,56 +142,63 @@ public class SimulatorTNTPhaseSettingsGui extends SimulatorBaseGui {
|
||||
|
||||
inventory.setItem(29, new SWItem(SWItem.getDye(lifetime > 0 ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
tnt.setLifetime(Math.max(1, lifetime - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Order
|
||||
// Order
|
||||
int order = tnt.getOrder();
|
||||
inventory.setItem(13, new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(13,
|
||||
new SWItem(SWItem.getDye(order < SimulatorPhase.ORDER_LIMIT ? 10 : 8), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.setOrder(Math.min(SimulatorPhase.ORDER_LIMIT, order + (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
|
||||
Material negativeNumbers = Material.getMaterial(Core.getVersion() >= 19 ? "RECOVERY_COMPASS" : "FIREWORK_STAR");
|
||||
SWItem orderItem = new SWItem(order >= 0 ? Material.COMPASS : negativeNumbers, "§eCalculation Order§8:§7 " + order, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Calculation Order", order + "", Integer::parseInt, integer -> {
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT) return false;
|
||||
if (integer < -SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
if (integer > SimulatorPhase.ORDER_LIMIT)
|
||||
return false;
|
||||
tnt.setOrder(integer);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(order >= 0 ? Material.COMPASS : negativeNumbers).open();
|
||||
});
|
||||
orderItem.getItemStack().setAmount(Math.max(1, Math.min(Math.abs(order), 30)));
|
||||
inventory.setItem(22, orderItem);
|
||||
|
||||
inventory.setItem(31, new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorWatcher.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
inventory.setItem(31,
|
||||
new SWItem(SWItem.getDye(order > -SimulatorPhase.ORDER_LIMIT ? 1 : 8), "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
|
||||
tnt.setOrder(Math.max(-SimulatorPhase.ORDER_LIMIT, order - (clickType.isShiftClick() ? 5 : 1)));
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
//Jump
|
||||
SWItem jumpX = new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setXJump(!tnt.isXJump());
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
// Jump
|
||||
SWItem jumpX =
|
||||
new SWItem(tnt.isXJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump X§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setXJump(!tnt.isXJump());
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
inventory.setItem(33, jumpX);
|
||||
|
||||
SWItem jumpY = new SWItem(tnt.isYJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setYJump(!tnt.isYJump());
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
SWItem jumpY =
|
||||
new SWItem(tnt.isYJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Y§8: " + (tnt.isYJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setYJump(!tnt.isYJump());
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
inventory.setItem(16, jumpY);
|
||||
|
||||
SWItem jumpZ = new SWItem(tnt.isZJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setZJump(!tnt.isZJump());
|
||||
SimulatorWatcher.update(simulator);
|
||||
});
|
||||
SWItem jumpZ =
|
||||
new SWItem(tnt.isZJump() ? Material.LIME_WOOL : Material.RED_WOOL, "§7TNT §eJump Z§8: " + (tnt.isZJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setZJump(!tnt.isZJump());
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
inventory.setItem(35, jumpZ);
|
||||
|
||||
SWItem jumpAll = new SWItem(Material.TNT, "§7TNT §eJump §8: " + (tnt.hasJump() ? "§aon" : "§coff"), clickType -> {
|
||||
tnt.setJump(!tnt.hasJump());
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
inventory.setItem(25, jumpAll);
|
||||
}
|
||||
|
||||
+39
-36
@@ -1,27 +1,25 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.data.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorAnvilGui;
|
||||
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
|
||||
import de.steamwar.data.CMDs;
|
||||
@@ -76,13 +74,14 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
|
||||
int baseTicks = tnt.getBaseTick();
|
||||
inventory.setItem(9, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
|
||||
tnt.changeBaseTicks(clickType.isShiftClick() ? 5 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
SWItem baseTick = new SWItem(Material.REPEATER, "§eTicks§8:§7 " + baseTicks, clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Ticks", baseTicks + "", Integer::parseInt, integer -> {
|
||||
if (integer < 0) return false;
|
||||
if (integer < 0)
|
||||
return false;
|
||||
tnt.changeBaseTicks(integer - baseTicks);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).setItem(Material.REPEATER).open();
|
||||
});
|
||||
@@ -94,42 +93,46 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
|
||||
} else {
|
||||
tnt.changeBaseTicks(clickType.isShiftClick() ? -5 : -1);
|
||||
}
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
// Subpixel Alignment
|
||||
inventory.setItem(21, new SWItem(Material.SUNFLOWER, "§7Align§8: §eCenter", clickType -> {
|
||||
tnt.alignX(0);
|
||||
tnt.alignZ(0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
|
||||
// Z
|
||||
SWItem negativZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §eNegativ Z", clickType -> {
|
||||
if (tnt.getAlignment().getZ() != -1) tnt.alignZ(-1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
if (tnt.getAlignment().getZ() != -1)
|
||||
tnt.alignZ(-1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
negativZItem.setEnchanted(tnt.getAlignment().getZ() == -1);
|
||||
inventory.setItem(20, negativZItem);
|
||||
|
||||
SWItem positivZItem = new SWItem(Material.OAK_BUTTON, "§7Align§8: §ePositiv Z", clickType -> {
|
||||
if (tnt.getAlignment().getZ() != 1) tnt.alignZ(1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
if (tnt.getAlignment().getZ() != 1)
|
||||
tnt.alignZ(1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
positivZItem.setEnchanted(tnt.getAlignment().getZ() == 1);
|
||||
inventory.setItem(22, positivZItem);
|
||||
|
||||
// X
|
||||
SWItem negativXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §eNegativ X", clickType -> {
|
||||
if (tnt.getAlignment().getX() != -1) tnt.alignX(-1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
if (tnt.getAlignment().getX() != -1)
|
||||
tnt.alignX(-1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
negativXItem.setEnchanted(tnt.getAlignment().getX() == -1);
|
||||
inventory.setItem(12, negativXItem);
|
||||
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
if(tnt.getAlignment().getX() != 1) tnt.alignX(1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SWItem positivXItem = new SWItem(Material.STONE_BUTTON, "§7Align§8: §ePositiv X", clickType -> {
|
||||
if (tnt.getAlignment().getX() != 1)
|
||||
tnt.alignX(1);
|
||||
SimulatorRenderer.update(simulator);
|
||||
});
|
||||
positivXItem.setEnchanted(tnt.getAlignment().getX() == 1);
|
||||
inventory.setItem(30, positivXItem);
|
||||
@@ -137,52 +140,52 @@ public class SimulatorTNTSettingsGui extends SimulatorBaseGui {
|
||||
// Pos X
|
||||
inventory.setItem(15, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
|
||||
tnt.move(clickType.isShiftClick() ? 0.0625 : 1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(24, new SWItem(Material.PAPER, "§eX§8:§7 " + tnt.getPosition().getX(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "X", tnt.getPosition().getX() + "", Double::parseDouble, d -> {
|
||||
tnt.getPosition().setX(d);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(33, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
|
||||
tnt.move(clickType.isShiftClick() ? -0.0625 : -1, 0, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
// Pos Y
|
||||
inventory.setItem(16, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
|
||||
tnt.move(0, clickType.isShiftClick() ? 0.0625 : 1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(25, new SWItem(Material.PAPER, "§eY§8:§7 " + tnt.getPosition().getY(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Y", tnt.getPosition().getY() + "", Double::parseDouble, d -> {
|
||||
tnt.getPosition().setY(d);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(34, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
|
||||
tnt.move(0, clickType.isShiftClick() ? -0.0625 : -1, 0);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
|
||||
// Pos Z
|
||||
inventory.setItem(17, new SWItem(SWItem.getDye(10), "§e+1", Arrays.asList("§7Shift§8: §e+0.0625"), false, clickType -> {
|
||||
tnt.move(0, 0, clickType.isShiftClick() ? 0.0625 : 1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
|
||||
inventory.setItem(26, new SWItem(Material.PAPER, "§eZ§8:§7 " + tnt.getPosition().getZ(), clickType -> {
|
||||
new SimulatorAnvilGui<>(player, "Z", tnt.getPosition().getZ() + "", Double::parseDouble, d -> {
|
||||
tnt.getPosition().setZ(d);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
return true;
|
||||
}, this).open();
|
||||
}));
|
||||
inventory.setItem(35, new SWItem(SWItem.getDye(1), "§e-1", Arrays.asList("§7Shift§8: §e-0.0625"), false, clickType -> {
|
||||
tnt.move(0, 0, clickType.isShiftClick() ? -0.0625 : -1);
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
|
||||
}
|
||||
}
|
||||
|
||||
+14
-21
@@ -1,26 +1,24 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
* Copyright (C) 2025 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 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.
|
||||
* 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/>.
|
||||
* 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.base;
|
||||
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
|
||||
import de.steamwar.bausystem.features.simulator.data.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.display.SimulatorRenderer;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
@@ -45,7 +43,8 @@ public abstract class SimulatorBaseGui {
|
||||
}
|
||||
|
||||
public final void open() {
|
||||
if (!shouldOpen()) return;
|
||||
if (!shouldOpen())
|
||||
return;
|
||||
|
||||
String newTitle = title();
|
||||
String originalTitle = player.getOpenInventory().getTitle();
|
||||
@@ -58,7 +57,6 @@ public abstract class SimulatorBaseGui {
|
||||
setup();
|
||||
if (player.getOpenInventory().getTopInventory() != inv) {
|
||||
inventory.open();
|
||||
SimulatorWatcher.watch(player, simulator, this::open);
|
||||
}
|
||||
if (Core.getVersion() > 19) {
|
||||
player.getOpenInventory().setTitle(title());
|
||||
@@ -70,7 +68,6 @@ public abstract class SimulatorBaseGui {
|
||||
}
|
||||
if (player.getOpenInventory().getTopInventory() == inv) {
|
||||
inventory.open();
|
||||
SimulatorWatcher.watch(player, simulator, this::open);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -82,11 +79,7 @@ public abstract class SimulatorBaseGui {
|
||||
return inv;
|
||||
});
|
||||
setup();
|
||||
inventory.addCloseCallback(clickType -> {
|
||||
SimulatorWatcher.watch(player, null, null);
|
||||
});
|
||||
|
||||
SimulatorWatcher.watch(player, simulator, this::open);
|
||||
if (simulator != null && simulator.getStabGenerator() != null) {
|
||||
populateStabGenerator();
|
||||
} else {
|
||||
@@ -98,7 +91,7 @@ public abstract class SimulatorBaseGui {
|
||||
private void populateStabGenerator() {
|
||||
inventory.setItem(22, new SWItem(Material.BARRIER, "§cCancel Stab Generator", click -> {
|
||||
simulator.getStabGenerator().cancel();
|
||||
SimulatorWatcher.update(simulator);
|
||||
SimulatorRenderer.update(simulator);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class YAPIONFormatSimulatorLoader implements SimulatorLoader {
|
||||
}
|
||||
|
||||
String name = file.getName().substring(0, file.getName().length() - 7);
|
||||
SteamwarUser steamwarUser = SteamwarUser.byId(Integer.parseInt(name));
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(Integer.parseInt(name));
|
||||
|
||||
List<Simulator> simulators = new ArrayList<>();
|
||||
for (String s : yapionObject.getKeys()) {
|
||||
|
||||
@@ -87,7 +87,6 @@ public class MaterialLazyInit {
|
||||
Block block = Bukkit.getWorlds().get(0).getBlockAt(0, 0, 0);
|
||||
block.setType(material);
|
||||
unmoveable = block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getState() instanceof TileState;
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
if (material.isItem() && material != Material.AIR) {
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class AntiBauAddMemberFix implements Listener {
|
||||
}
|
||||
if (BauweltMember.getBauMember(BauServer.getInstance().getOwner(), event.getPlayer().getUniqueId()) == null) {
|
||||
event.getPlayer().kickPlayer("");
|
||||
throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.byId(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!");
|
||||
throw new SecurityException("The player " + event.getPlayer().getName() + " joined on the server of " + SteamwarUser.get(BauServer.getInstance().getOwnerID()).getUserName() + " without being added!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
package de.steamwar.bausystem.utils.cursor;
|
||||
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Getter
|
||||
public abstract class Cursor {
|
||||
private final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final REntityServer targetServer;
|
||||
private final REntityServer cursorServer;
|
||||
|
||||
private final Player owner;
|
||||
private final Material highlightMaterial;
|
||||
|
||||
private RFallingBlockEntity cursorEntity;
|
||||
|
||||
private Location cursorLocation;
|
||||
private boolean isHittingEntity = false;
|
||||
|
||||
@Setter
|
||||
private Material cursorMaterial;
|
||||
@Setter
|
||||
private List<CursorMode> allowedCursorModes;
|
||||
private boolean visible = true;
|
||||
|
||||
|
||||
|
||||
protected Cursor(REntityServer targetServer, Player owner, Material highlightMaterial, Material cursorMaterial, List<CursorMode> allowedModes) {
|
||||
this.targetServer = targetServer;
|
||||
this.owner = owner;
|
||||
this.highlightMaterial = highlightMaterial;
|
||||
this.cursorMaterial = cursorMaterial;
|
||||
this.allowedCursorModes = allowedModes;
|
||||
|
||||
cursorServer = new REntityServer();
|
||||
cursorServer.addPlayer(owner);
|
||||
|
||||
CursorManager.getInstance().registerCursor(this);
|
||||
}
|
||||
|
||||
public void render() {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
RayTraceUtils.RRayTraceResult rayTraceResult = RayTraceUtils.traceREntity(owner, owner.getLocation(), targetServer.getEntities());
|
||||
if (rayTraceResult == null) {
|
||||
if (cursorEntity != null)
|
||||
cursorEntity.die();
|
||||
cursorEntity = null;
|
||||
return;
|
||||
}
|
||||
|
||||
REntity hitEntity = rayTraceResult.getHitEntity() == cursorEntity ? null : rayTraceResult.getHitEntity();
|
||||
|
||||
|
||||
Material activeCursorMaterial = hitEntity == null ? cursorMaterial : highlightMaterial;
|
||||
CursorMode activeCursorMode = allowedCursorModes.stream().filter((mode) -> mode.isActive.test(owner)).min(Comparator.comparingInt(a -> a.priority))
|
||||
.orElse(CursorMode.BLOCK_ALIGNED);
|
||||
|
||||
Location activeCursorLocation = hitEntity == null ? activeCursorMode.positionTransform.apply(owner, rayTraceResult).toLocation(WORLD)
|
||||
: new Vector(hitEntity.getX(), hitEntity.getY(), hitEntity.getZ()).toLocation(WORLD);
|
||||
|
||||
cursorLocation = activeCursorLocation;
|
||||
isHittingEntity = hitEntity != null;
|
||||
|
||||
if (cursorEntity == null) {
|
||||
cursorEntity = new RFallingBlockEntity(cursorServer, activeCursorLocation, activeCursorMaterial);
|
||||
cursorEntity.setNoGravity(true);
|
||||
} else if (cursorEntity.getMaterial() == activeCursorMaterial) {
|
||||
cursorEntity.move(activeCursorLocation);
|
||||
} else {
|
||||
cursorEntity.die();
|
||||
cursorEntity = new RFallingBlockEntity(cursorServer, activeCursorLocation, activeCursorMaterial);
|
||||
cursorEntity.setNoGravity(true);
|
||||
if (activeCursorMaterial == highlightMaterial) {
|
||||
cursorEntity.setGlowing(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
visible = false;
|
||||
if (cursorEntity != null) {
|
||||
cursorEntity.die();
|
||||
cursorEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
visible = true;
|
||||
}
|
||||
|
||||
final void handleClick(Action action) {
|
||||
if (!visible)
|
||||
return;
|
||||
|
||||
onClick(Optional.ofNullable(this.cursorLocation), isHittingEntity, action);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
cursorServer.close();
|
||||
CursorManager.getInstance().unregisterCursor(this);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum CursorMode {
|
||||
FREE(1, (player, rayTraceResult) -> {
|
||||
Vector pos = rayTraceResult.getHitPosition();
|
||||
|
||||
BlockFace face = rayTraceResult.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (face.getModY() == 0 && player.isSneaking()) {
|
||||
pos.setY(pos.getY() - 0.49);
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}, (player) -> player.isSneaking()),
|
||||
|
||||
BLOCK_ALIGNED(0, (player, rayTraceResult) -> {
|
||||
Vector pos = rayTraceResult.getHitPosition();
|
||||
|
||||
BlockFace face = rayTraceResult.getHitBlockFace();
|
||||
if (face != null) {
|
||||
switch (face) {
|
||||
case DOWN:
|
||||
pos.setY(pos.getY() - 0.98);
|
||||
break;
|
||||
case EAST:
|
||||
pos.setX(pos.getX() + 0.49);
|
||||
break;
|
||||
case WEST:
|
||||
pos.setX(pos.getX() - 0.49);
|
||||
break;
|
||||
case NORTH:
|
||||
pos.setZ(pos.getZ() - 0.49);
|
||||
break;
|
||||
case SOUTH:
|
||||
pos.setZ(pos.getZ() + 0.49);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.setX(pos.getBlockX() + 0.5);
|
||||
if (pos.getY() - pos.getBlockY() != 0 && face == BlockFace.UP) {
|
||||
pos.setY(pos.getBlockY() + 1.0);
|
||||
} else {
|
||||
pos.setY(pos.getBlockY());
|
||||
}
|
||||
pos.setZ(pos.getBlockZ() + 0.5);
|
||||
return pos;
|
||||
}, (player) -> true);
|
||||
|
||||
|
||||
private final int priority;
|
||||
private final BiFunction<Player, RayTraceUtils.RRayTraceResult, Vector> positionTransform;
|
||||
private final Predicate<Player> isActive;
|
||||
}
|
||||
|
||||
public abstract void onClick(Optional<Location> cursorLocation, boolean didHitEntity, Action action);
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package de.steamwar.bausystem.utils.cursor;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
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.PlayerQuitEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Linked
|
||||
public class CursorManager implements Listener {
|
||||
@Getter
|
||||
private static CursorManager instance;
|
||||
|
||||
private final Set<Player> calculationActive = new HashSet<>();
|
||||
private final Map<Player, List<Cursor>> activeCursors = new HashMap<>();
|
||||
|
||||
public CursorManager() {
|
||||
if (instance == null) {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
BiFunction<Player, Object, Object> function = (player, object) -> {
|
||||
updateCursors(player);
|
||||
return object;
|
||||
};
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
Set<Player> playersWithActiveCursor = activeCursors.keySet();
|
||||
|
||||
playersWithActiveCursor.forEach(this::updateCursors);
|
||||
}, 0);
|
||||
|
||||
Class<?> positionPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos");
|
||||
Class<?> lookPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot");
|
||||
Class<?> positionLookPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot");
|
||||
|
||||
TinyProtocol.instance.addFilter(positionPacketClass, function);
|
||||
TinyProtocol.instance.addFilter(lookPacketClass, function);
|
||||
TinyProtocol.instance.addFilter(positionLookPacketClass, function);
|
||||
}
|
||||
|
||||
void registerCursor(Cursor cursor) {
|
||||
List<Cursor> cursorsOfPlayer = activeCursors.getOrDefault(cursor.getOwner(), new ArrayList<>());
|
||||
cursorsOfPlayer.add(cursor);
|
||||
activeCursors.put(cursor.getOwner(), cursorsOfPlayer);
|
||||
}
|
||||
|
||||
void unregisterCursor(Cursor cursor) {
|
||||
List<Cursor> cursorsOfPlayer = activeCursors.get(cursor.getOwner());
|
||||
if (cursorsOfPlayer != null) {
|
||||
cursorsOfPlayer.remove(cursor);
|
||||
if (cursorsOfPlayer.isEmpty()) {
|
||||
activeCursors.remove(cursor.getOwner());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void closeCursorsOf(Player player) {
|
||||
List<Cursor> cursorsOfPlayer = activeCursors.remove(player);
|
||||
if (cursorsOfPlayer != null) {
|
||||
new ArrayList<>(cursorsOfPlayer).forEach(Cursor::close);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void updateCursors(Player player) {
|
||||
if (!activeCursors.containsKey(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (calculationActive) {
|
||||
if (calculationActive.contains(player)) {
|
||||
return;
|
||||
} else {
|
||||
calculationActive.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
List<Cursor> cursors = activeCursors.get(player);
|
||||
|
||||
if (cursors != null) {
|
||||
cursors.forEach(Cursor::render);
|
||||
}
|
||||
|
||||
synchronized (calculationActive) {
|
||||
calculationActive.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void handlePlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
List<Cursor> cursorsOfPlayer = activeCursors.get(player);
|
||||
if (cursorsOfPlayer != null) {
|
||||
cursorsOfPlayer.forEach(cursor -> cursor.handleClick(event.getAction()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void handlePlayerQuit(PlayerQuitEvent event) {
|
||||
closeCursorsOf(event.getPlayer());
|
||||
}
|
||||
}
|
||||
+1
-6
@@ -84,12 +84,7 @@ public class FixedFlagStorage implements FlagStorage {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (Flag flag : Flag.getFlags()) {
|
||||
if (flag == Flag.TESTBLOCK) continue;
|
||||
if (flag == Flag.COLOR) continue;
|
||||
if (flag == Flag.CHANGED) continue;
|
||||
flagMap.remove(flag);
|
||||
}
|
||||
flagMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-6
@@ -91,12 +91,7 @@ public class FixedGlobalFlagStorage implements FlagStorage {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
for (Flag flag : Flag.getFlags()) {
|
||||
if (flag == Flag.TESTBLOCK) continue;
|
||||
if (flag == Flag.COLOR) continue;
|
||||
if (flag == Flag.CHANGED) continue;
|
||||
flagMap.remove(flag);
|
||||
}
|
||||
flagMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,6 +50,5 @@ tasks.register<DevServer>("DevBau21") {
|
||||
description = "Run a 1.21 Dev Bau"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":BauSystem:shadowJar")
|
||||
dependsOn(":SchematicSystem:shadowJar")
|
||||
template = "Bau21"
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.hamcrest)
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||
annotationProcessor(project(":CommandFramework:CommandFrameworkBase", "default"))
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
de.steamwar.command.annotationprocessor.impl.CachedAnnotationProcessor
|
||||
de.steamwar.command.annotationprocessor.impl.MapperAnnotationProcessor
|
||||
de.steamwar.command.annotationprocessor.impl.RegisterAnnotationProcessor
|
||||
de.steamwar.command.annotationprocessor.impl.SupplierAnnotationProcessor
|
||||
de.steamwar.command.annotationprocessor.impl.ValidatorAnnotationProcessor
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import java.util.List;
|
||||
|
||||
public class HandlerForExecutableElement implements Handler.MethodWrapper {
|
||||
|
||||
@Getter
|
||||
private final ExecutableElement method;
|
||||
private final Types types;
|
||||
private final Elements elements;
|
||||
|
||||
public HandlerForExecutableElement(ExecutableElement method, Types types, Elements elements) {
|
||||
this.method = method;
|
||||
this.types = types;
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return method.getSimpleName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParameterCount() {
|
||||
return method.getParameters().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler.TypeWrapper getReturnType() {
|
||||
return new HandlerForTypeMirror(method.getReturnType(), types, elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler.ParameterWrapper[] getParameters() {
|
||||
Handler.ParameterWrapper[] parameters = new Handler.ParameterWrapper[method.getParameters().size()];
|
||||
List<? extends VariableElement> variableElements = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
VariableElement variableElement = variableElements.get(i);
|
||||
parameters[i] = new HandlerForVariableElement(variableElement, types, elements, i == parameters.length - 1 && method.isVarArgs());
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
|
||||
public class HandlerForTypeMirror implements Handler.TypeWrapper {
|
||||
|
||||
private final TypeMirror type;
|
||||
private final Types types;
|
||||
private final Elements elements;
|
||||
|
||||
public HandlerForTypeMirror(TypeMirror type, Types types, Elements elements) {
|
||||
this.type = type;
|
||||
this.types = types;
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableTo(Class<?> clazz) {
|
||||
return types.isAssignable(types.erasure(type), types.erasure(elements.getTypeElement(clazz.getTypeName()).asType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableTo(Handler.TypeWrapper type) {
|
||||
if (type instanceof ForClass) {
|
||||
return isAssignableTo(((ForClass) type).getClazz());
|
||||
} else if (type instanceof HandlerForTypeMirror) {
|
||||
return types.isAssignable(types.erasure(this.type), types.erasure(((HandlerForTypeMirror) type).type));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimitive() {
|
||||
return type.getKind().isPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArray() {
|
||||
return type instanceof ArrayType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
if (type.getKind() != TypeKind.DECLARED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DeclaredType declaredType = (DeclaredType) type;
|
||||
Element element = declaredType.asElement();
|
||||
|
||||
return element.getKind() == ElementKind.ENUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Class<?> clazz) {
|
||||
if (type.getKind() == TypeKind.VOID && clazz == Void.TYPE) {
|
||||
return true;
|
||||
} else if (type.getKind().isPrimitive() && clazz.isPrimitive()) {
|
||||
return type.toString().equals(clazz.getTypeName());
|
||||
} else if (!type.getKind().isPrimitive() && !clazz.isPrimitive()) {
|
||||
return types.isSameType(types.erasure(type), types.erasure(elements.getTypeElement(clazz.getTypeName()).asType()));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Handler.TypeWrapper type) {
|
||||
if (type instanceof ForClass) {
|
||||
return is(((ForClass) type).getClazz());
|
||||
} else if (type instanceof HandlerForTypeMirror) {
|
||||
return types.isSameType(types.erasure(this.type), types.erasure(((HandlerForTypeMirror) type).type));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler.TypeWrapper getComponentType() {
|
||||
if (type instanceof ArrayType) {
|
||||
return new HandlerForTypeMirror(((ArrayType) type).getComponentType(), types, elements);
|
||||
} else {
|
||||
return new HandlerForTypeMirror(null, types, elements);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return type.toString();
|
||||
}
|
||||
}
|
||||
-151
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command;
|
||||
|
||||
import de.steamwar.command.utils.Pair;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HandlerForVariableElement implements Handler.ParameterWrapper {
|
||||
|
||||
@Getter
|
||||
private final VariableElement parameter;
|
||||
private final Types types;
|
||||
private final Elements elements;
|
||||
private final boolean varArgs;
|
||||
|
||||
public HandlerForVariableElement(VariableElement variableElement, Types types, Elements elements, boolean varArgs) {
|
||||
this.parameter = variableElement;
|
||||
this.types = types;
|
||||
this.elements = elements;
|
||||
this.varArgs = varArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handler.TypeWrapper getType() {
|
||||
return new HandlerForTypeMirror(parameter.asType(), types, elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarArgs() {
|
||||
return varArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
|
||||
return parameter.getAnnotation(annotation) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends Annotation> Handler.AnnotationWrapper<A> getAnnotation(Class<A> annotation) {
|
||||
A ann = parameter.getAnnotation(annotation);
|
||||
AnnotationMirror annMirror = parameter.getAnnotationMirrors()
|
||||
.stream()
|
||||
.filter(am -> new HandlerForTypeMirror(am.getAnnotationType(), types, elements).is(annotation))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
return new HandlerForAnnotationMirror<>(ann, annMirror);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return parameter.getSimpleName().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Handler.AnnotationWrapper<?>> getAnnotations() {
|
||||
return parameter.getAnnotationMirrors()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(Function.identity(), annotationMirror -> {
|
||||
Class<?> clazz = getClass(annotationMirror.getAnnotationType().toString());
|
||||
if (clazz == null) return null;
|
||||
return parameter.getAnnotation((Class<? extends Annotation>) clazz);
|
||||
}))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() != null)
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> {
|
||||
Annotation annotation = entry.getValue();
|
||||
try {
|
||||
Method method = annotation.annotationType().getMethod("value");
|
||||
Class<?> returnType = method.getReturnType();
|
||||
if (!returnType.isArray()) {
|
||||
return List.of(annotation);
|
||||
}
|
||||
Class<?> innerReturnType = returnType.getComponentType();
|
||||
if (!(innerReturnType.isAnnotation() && innerReturnType.isAnnotationPresent(Repeatable.class))) {
|
||||
return List.of(annotation);
|
||||
}
|
||||
Repeatable repeatable = innerReturnType.getAnnotation(Repeatable.class);
|
||||
Class<? extends Annotation> containerType = repeatable.value();
|
||||
if (containerType == returnType) {
|
||||
throw new UnsupportedOperationException("Repeatable annotation must have a container annotation");
|
||||
}
|
||||
try {
|
||||
return Arrays.asList((Annotation[]) method.invoke(annotation));
|
||||
} catch (Exception e) {
|
||||
return List.of(annotation);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
return List.of(annotation);
|
||||
}
|
||||
}))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.flatMap(entry -> {
|
||||
return entry.getValue()
|
||||
.stream()
|
||||
.map(annotation -> new Pair<AnnotationMirror, Annotation>(entry.getKey(), annotation));
|
||||
})
|
||||
.filter(pair -> pair.b.annotationType().isAnnotationPresent(Handler.Implementation.class))
|
||||
.map(pair -> new HandlerForAnnotationMirror<>(pair.b, pair.a))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Class<?> getClass(String name) {
|
||||
try {
|
||||
return Class.forName(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Ignore
|
||||
}
|
||||
if (!name.contains(".")) return null;
|
||||
Class<?> outerClass = getClass(name.substring(0, name.lastIndexOf('.')));
|
||||
if (outerClass == null) return null;
|
||||
name = name.substring(name.lastIndexOf('.') + 1);
|
||||
for (Class<?> declaredClass : outerClass.getDeclaredClasses()) {
|
||||
if (declaredClass.getSimpleName().equals(name)) {
|
||||
return declaredClass;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-156
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.HandlerForAnnotationMirror;
|
||||
import de.steamwar.command.HandlerForExecutableElement;
|
||||
import de.steamwar.command.HandlerForVariableElement;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import javax.tools.Diagnostic;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractAnnotationProcessor extends AbstractProcessor {
|
||||
|
||||
private Messager messager;
|
||||
private Types types;
|
||||
private Elements elements;
|
||||
|
||||
public abstract Class<? extends Annotation> getAnnotationClass();
|
||||
|
||||
@Override
|
||||
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||
super.init(processingEnv);
|
||||
this.messager = processingEnv.getMessager();
|
||||
this.types = processingEnv.getTypeUtils();
|
||||
this.elements = processingEnv.getElementUtils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedAnnotationTypes() {
|
||||
return Collections.singleton(this.getAnnotationClass().getCanonicalName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceVersion getSupportedSourceVersion() {
|
||||
return SourceVersion.latestSupported();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
List<ExecutableElement> elements = roundEnv.getElementsAnnotatedWith(getAnnotationClass())
|
||||
.stream()
|
||||
.filter(element -> element.getKind() == ElementKind.METHOD)
|
||||
.map(ExecutableElement.class::cast)
|
||||
.collect(Collectors.toList());
|
||||
if (elements.isEmpty()) return false;
|
||||
elements.forEach(element -> {
|
||||
checkMethodAnnotation(element, element.getAnnotation(getAnnotationClass()));
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
private Handler getHandler(Annotation annotation, Element element) {
|
||||
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||
if (implementation == null) return null;
|
||||
try {
|
||||
return implementation.value().getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException e) {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, "Handler " + implementation.value().getName() + " cannot be used to check the argument validity", element);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMethodAnnotation(ExecutableElement method, Annotation annotation) {
|
||||
Handler handler = getHandler(annotation, method);
|
||||
if (handler == null) return;
|
||||
if (!(handler instanceof Handler.HandlerMethod)) {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, "Handler " + handler.getClass().getName() + " is not a HandlerMethod", method);
|
||||
return;
|
||||
}
|
||||
Handler.HandlerMethod handlerMethod = (Handler.HandlerMethod) handler;
|
||||
try {
|
||||
handlerMethod.check(new HandlerForAnnotationMirror(annotation, null), new HandlerForExecutableElement(method, types, elements), DataCheckableImpl.INSTANCE);
|
||||
} catch (Handler.HandlerException e) {
|
||||
Handler.CodePlace codePlace = e.getCodePlace();
|
||||
AnnotationMirror[] annotationMirrors = new AnnotationMirror[0];
|
||||
if (codePlace.getAnnotations().length > 0) {
|
||||
annotationMirrors = Arrays.stream(codePlace.getAnnotations())
|
||||
.map(annotationWrapper -> (HandlerForAnnotationMirror) annotationWrapper)
|
||||
.map(HandlerForAnnotationMirror::getAnnotationMirror)
|
||||
.toArray(AnnotationMirror[]::new);
|
||||
}
|
||||
Element element = null;
|
||||
if (codePlace.getMethod() != null) {
|
||||
element = ((HandlerForExecutableElement) codePlace.getMethod()).getMethod();
|
||||
} else if (codePlace.getParameter() != null) {
|
||||
element = ((HandlerForVariableElement) codePlace.getParameter()).getParameter();
|
||||
}
|
||||
|
||||
if (annotationMirrors.length > 0) {
|
||||
for (int i = 0; i < annotationMirrors.length; i++) {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage(), element, annotationMirrors[i]);
|
||||
}
|
||||
} else {
|
||||
messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage(), element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class DataCheckableImpl implements Handler.DataCheckable {
|
||||
|
||||
private static final DataCheckableImpl INSTANCE = new DataCheckableImpl();
|
||||
|
||||
@Override
|
||||
public boolean hasExecutorMapper(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMapper(String key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValidator(String key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSupplier(String key) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor.impl;
|
||||
|
||||
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||
import de.steamwar.command.annotations.Cached;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class CachedAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Cached.class;
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor.impl;
|
||||
|
||||
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||
import de.steamwar.command.annotations.Mapper;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class MapperAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Mapper.class;
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor.impl;
|
||||
|
||||
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||
import de.steamwar.command.annotations.Register;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class RegisterAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Register.class;
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor.impl;
|
||||
|
||||
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||
import de.steamwar.command.annotations.Supplier;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class SupplierAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Supplier.class;
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 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.command.annotationprocessor.impl;
|
||||
|
||||
import de.steamwar.command.annotationprocessor.AbstractAnnotationProcessor;
|
||||
import de.steamwar.command.annotations.Validator;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class ValidatorAnnotationProcessor extends AbstractAnnotationProcessor {
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Validator.class;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
@@ -1,216 +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.command;
|
||||
|
||||
import de.steamwar.command.graph.NodeData;
|
||||
import de.steamwar.command.graph.RootNode;
|
||||
import de.steamwar.command.utils.Pair;
|
||||
import de.steamwar.command.utils.Triple;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractCommand<T> {
|
||||
|
||||
private static final Map<Class<? extends AbstractCommand<?>>, Map<Class<?>, Function<?, ?>>> EXECUTOR_MAPPER = new HashMap<>();
|
||||
|
||||
public static <E, T> void addExecutorMapper(Class<? extends AbstractCommand<E>> wrapper, Class<T> executorType, Function<E, T> mapper) {
|
||||
EXECUTOR_MAPPER.computeIfAbsent(wrapper, __ -> new HashMap<>())
|
||||
.putIfAbsent(executorType, mapper);
|
||||
}
|
||||
|
||||
protected final String command;
|
||||
protected final String permission;
|
||||
private final Consumer<CommandLoader<T>> initializer;
|
||||
protected final String[] aliases;
|
||||
protected final List<String> descriptions = new ArrayList<>();
|
||||
|
||||
private boolean initialized = false;
|
||||
protected final RootNode<T> rootNode = new RootNode<>();
|
||||
|
||||
private final Map<String, AbstractTypeMapper<T, ?>> localTypeMapper = new HashMap<>();
|
||||
private final Map<String, AbstractTypeValidator<T, ?>> localValidators = new HashMap<>();
|
||||
private final Map<String, AbstractTypeSupplier<T, ?>> localSupplier = new HashMap<>();
|
||||
|
||||
protected AbstractCommand(String command, Consumer<CommandLoader<T>> initializer, String... aliases) {
|
||||
this(command, null, initializer, aliases);
|
||||
}
|
||||
|
||||
protected AbstractCommand(String command, String permission, Consumer<CommandLoader<T>> initializer, String... aliases) {
|
||||
this.command = command;
|
||||
this.permission = permission;
|
||||
this.initializer = initializer;
|
||||
this.aliases = aliases;
|
||||
initCommand();
|
||||
unregister();
|
||||
register();
|
||||
}
|
||||
|
||||
protected synchronized void initCommand() {
|
||||
}
|
||||
|
||||
public abstract void unregister();
|
||||
|
||||
public abstract void register();
|
||||
|
||||
protected void commandSystemError(T sender, CommandFrameworkException e) {
|
||||
Logger.getGlobal().log(Level.WARNING, "An unexpected error occurred", e);
|
||||
}
|
||||
|
||||
protected void sendMessage(T sender, String message, Object[] args) {
|
||||
}
|
||||
|
||||
public final void execute(T sender, String alias, String[] args) {
|
||||
initialize();
|
||||
List<Runnable> errors = new ArrayList<>();
|
||||
try {
|
||||
boolean executed = rootNode.execute(sender, new NodeData(alias, fixArgs(args, true), (s, args1) -> {
|
||||
errors.add(() -> sendMessage(sender, s, args1));
|
||||
}));
|
||||
if (executed) return;
|
||||
if (!errors.isEmpty()) {
|
||||
errors.forEach(Runnable::run);
|
||||
return;
|
||||
}
|
||||
descriptions.forEach(s -> sendMessage(sender, s, new Object[0]));
|
||||
} catch (CommandFrameworkException e) {
|
||||
commandSystemError(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
public final List<String> tabComplete(T sender, String alias, String[] args) throws IllegalArgumentException {
|
||||
initialize();
|
||||
List<Collection<String>> tabCompletes = new ArrayList<>();
|
||||
rootNode.tabComplete(sender, new NodeData(alias, fixArgs(args, false), (s, args1) -> {}), tabCompletes);
|
||||
return tabCompletes.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(s -> !s.isEmpty())
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private String[] fixArgs(String[] args, boolean allowEmpty) {
|
||||
int removedCount = 0;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (arg.isEmpty() && i != args.length - 1) {
|
||||
removedCount++;
|
||||
continue;
|
||||
}
|
||||
args[i] = args[i - removedCount];
|
||||
}
|
||||
if (removedCount != 0) {
|
||||
args = Arrays.copyOf(args, args.length - removedCount);
|
||||
}
|
||||
if (args.length == 0 && !allowEmpty) {
|
||||
return new String[]{""};
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
private synchronized void initialize() {
|
||||
if (initialized) return;
|
||||
|
||||
List<Object> commandObjects = new ArrayList<>();
|
||||
initializer.accept(new CommandLoader<>() {
|
||||
@Override
|
||||
public AbstractCommand<T> get() {
|
||||
return AbstractCommand.this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Object command) {
|
||||
commandObjects.add(command);
|
||||
}
|
||||
});
|
||||
|
||||
List<Pair<DataImpl, Method>> methods = new ArrayList<>();
|
||||
for (Object commandObject : commandObjects) {
|
||||
DataImpl dataImpl = new DataImpl(this, commandObject, rootNode, EXECUTOR_MAPPER.getOrDefault(this.getClass(), Collections.emptyMap()), (Map) localTypeMapper, CommandUtils.MAPPER_FUNCTIONS, (Map) localValidators, CommandUtils.VALIDATOR_FUNCTIONS, (Map) localSupplier, CommandUtils.SUPPLIER_FUNCTIONS);
|
||||
methods(commandObject).stream()
|
||||
.filter(method -> Arrays.stream(method.getAnnotations()).anyMatch(anno -> anno.annotationType().isAnnotationPresent(Handler.Implementation.class)))
|
||||
.forEach(method -> methods.add(new Pair<>(dataImpl, method)));
|
||||
}
|
||||
|
||||
Map<Integer, Map<Triple<DataImpl, Method, Annotation>, List<Handler.HandlerMethod<Annotation>>>> handlerMap = new HashMap<>();
|
||||
for (Pair<DataImpl, Method> commandMethod : methods) {
|
||||
List<Annotation> annotations = CommandUtils.getAnnotations(commandMethod.b);
|
||||
for (Annotation annotation : annotations) {
|
||||
Handler.Implementation handler = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||
Handler handlerObject;
|
||||
try {
|
||||
handlerObject = handler.value().getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException e) {
|
||||
throw new UnsupportedOperationException("Handler " + handler.value().getName() + " cannot be used to check the argument validity", e);
|
||||
}
|
||||
if (!(handlerObject instanceof Handler.HandlerMethod)) {
|
||||
throw new UnsupportedOperationException("Handler " + handlerObject.getClass().getName() + " is not a HandlerMethod");
|
||||
}
|
||||
handlerMap.computeIfAbsent(((Handler.HandlerMethod<?>) handlerObject).getRunPriority(), k -> new LinkedHashMap<>())
|
||||
.computeIfAbsent(new Triple<>(commandMethod.a, commandMethod.b, annotation), k -> new ArrayList<>())
|
||||
.add((Handler.HandlerMethod<Annotation>) handlerObject);
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> runPriorities = new ArrayList<>(handlerMap.keySet());
|
||||
runPriorities.sort(Comparator.naturalOrder());
|
||||
for (int runPriority : runPriorities) {
|
||||
handlerMap.get(runPriority).forEach((dataMethodAnnotationTriple, handlerMethods) -> {
|
||||
handlerMethods.forEach(annotationHandlerMethod -> {
|
||||
try {
|
||||
annotationHandlerMethod.check(new Handler.AnnotationWrapper.ForAnnotation<>(dataMethodAnnotationTriple.c), new Handler.MethodWrapper.ForMethod(dataMethodAnnotationTriple.b), dataMethodAnnotationTriple.a);
|
||||
} catch (Exception e) {
|
||||
throw new UnsupportedOperationException("Method check failed for " + dataMethodAnnotationTriple.b.getName(), e);
|
||||
}
|
||||
annotationHandlerMethod.run(dataMethodAnnotationTriple.c, dataMethodAnnotationTriple.b, dataMethodAnnotationTriple.a);
|
||||
});
|
||||
});
|
||||
}
|
||||
rootNode.sort();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
// TODO: Implement this when Message System is ready
|
||||
/*
|
||||
public void addDefaultHelpMessage(String message) {
|
||||
defaultHelpMessages.add(message);
|
||||
}
|
||||
*/
|
||||
|
||||
private List<Method> methods(Object commandObject) {
|
||||
List<Method> methods = new ArrayList<>();
|
||||
Class<?> current = commandObject.getClass();
|
||||
while (current != null) {
|
||||
methods.addAll(Arrays.asList(current.getDeclaredMethods()));
|
||||
current = current.getSuperclass();
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +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.command;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface AbstractTypeMapper<K, T> {
|
||||
|
||||
/**
|
||||
* The CommandSender can be null!
|
||||
*/
|
||||
T map(K sender, PreviousArguments previousArguments, String s);
|
||||
|
||||
Collection<String> tabComplete(K sender, PreviousArguments previousArguments, String s);
|
||||
|
||||
/**
|
||||
* @return true if the next element should be appended to the current tab complete.
|
||||
*/
|
||||
default boolean appendNextElementTabCompletions() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the cache key by sender and user provided argument. <br>
|
||||
* Note: The CommandSender can be null if the cache is defined as a global cache!<br>
|
||||
* Returning null and the empty string are equivalent.
|
||||
*/
|
||||
default String normalize(K sender, String s) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command;
|
||||
|
||||
public interface AbstractTypeSupplier<K, T> {
|
||||
|
||||
T get(K sender, PreviousArguments previousArguments);
|
||||
}
|
||||
-62
@@ -1,62 +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.command;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AbstractTypeValidator<K, T> {
|
||||
|
||||
/**
|
||||
* Validates the given value.
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param value The value to validate or null if mapping returned null.
|
||||
* @param messageSender The message sender to send messages to the player. Never send messages directly to the player.
|
||||
* @return The result of the validation.
|
||||
*/
|
||||
boolean validate(K sender, T value, MessageSender messageSender);
|
||||
|
||||
default AbstractTypeValidator<K, T> and(AbstractTypeValidator<K, T> other) {
|
||||
return (sender, value, messageSender) -> validate(sender, value, messageSender) && other.validate(sender, value, messageSender);
|
||||
}
|
||||
|
||||
default AbstractTypeValidator<K, T> or(AbstractTypeValidator<K, T> other) {
|
||||
return (sender, value, messageSender) -> validate(sender, value, messageSender) || other.validate(sender, value, messageSender);
|
||||
}
|
||||
|
||||
default AbstractTypeValidator<K, T> not() {
|
||||
return (sender, value, messageSender) -> !validate(sender, value, messageSender);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface MessageSender {
|
||||
void send(String s, Object... args);
|
||||
|
||||
default boolean send(boolean condition, String s, Object... args) {
|
||||
if (condition) send(s, args);
|
||||
return condition;
|
||||
}
|
||||
|
||||
default boolean send(BooleanSupplier condition, String s, Object... args) {
|
||||
return send(condition.getAsBoolean(), s, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
-93
@@ -1,93 +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.command;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CommandFrameworkException extends RuntimeException {
|
||||
|
||||
private Function causeMessage;
|
||||
private Throwable cause;
|
||||
private Function stackTraceExtractor;
|
||||
private String extraStackTraces;
|
||||
|
||||
private String message;
|
||||
|
||||
public CommandFrameworkException(InvocationTargetException invocationTargetException, String alias, String[] args) {
|
||||
this(e -> {
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append(e.getCause().getClass().getTypeName());
|
||||
if (e.getCause().getMessage() != null) {
|
||||
st.append(": ").append(e.getCause().getMessage());
|
||||
}
|
||||
if (alias != null && !alias.isEmpty()) {
|
||||
st.append("\n").append("Performed command: " + alias + " " + String.join(" ", args));
|
||||
}
|
||||
return st.toString();
|
||||
}, invocationTargetException, e -> {
|
||||
StackTraceElement[] stackTraceElements = e.getCause().getStackTrace();
|
||||
return Arrays.stream(stackTraceElements).limit(stackTraceElements.length - e.getStackTrace().length);
|
||||
}, null);
|
||||
}
|
||||
|
||||
private <T extends Throwable> CommandFrameworkException(Function<T, String> causeMessage, T cause, Function<T, Stream<StackTraceElement>> stackTraceExtractor, String extraStackTraces) {
|
||||
super(causeMessage.apply(cause), cause);
|
||||
this.causeMessage = causeMessage;
|
||||
this.cause = cause;
|
||||
this.stackTraceExtractor = stackTraceExtractor;
|
||||
this.extraStackTraces = extraStackTraces;
|
||||
}
|
||||
|
||||
public synchronized String getBuildStackTrace() {
|
||||
if (message != null) {
|
||||
return message;
|
||||
}
|
||||
StringBuilder st = new StringBuilder();
|
||||
st.append(causeMessage.apply(cause)).append("\n");
|
||||
((Stream<StackTraceElement>) stackTraceExtractor.apply(cause)).forEach(stackTraceElement -> {
|
||||
st.append("\tat ").append(stackTraceElement.toString()).append("\n");
|
||||
});
|
||||
if (extraStackTraces != null) {
|
||||
st.append("\tat ").append(extraStackTraces).append("\n");
|
||||
}
|
||||
message = st.toString();
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStackTrace() {
|
||||
printStackTrace(System.err);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStackTrace(PrintStream s) {
|
||||
s.print(getBuildStackTrace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printStackTrace(PrintWriter s) {
|
||||
s.print(getBuildStackTrace());
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command;
|
||||
|
||||
public interface CommandLoader<T> {
|
||||
|
||||
AbstractCommand<T> get();
|
||||
void add(Object command);
|
||||
}
|
||||
@@ -1,148 +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.command;
|
||||
|
||||
import de.steamwar.command.mapper.BooleanMapper;
|
||||
import de.steamwar.command.mapper.NumberMapper;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
@UtilityClass
|
||||
public class CommandUtils {
|
||||
|
||||
final Map<String, AbstractTypeMapper<?, ?>> MAPPER_FUNCTIONS = new HashMap<>();
|
||||
|
||||
final Map<String, AbstractTypeValidator<?, ?>> VALIDATOR_FUNCTIONS = new HashMap<>();
|
||||
|
||||
final Map<String, AbstractTypeSupplier<?, ?>> SUPPLIER_FUNCTIONS = new HashMap<>();
|
||||
|
||||
static final AbstractTypeMapper<Object, String> STRING_MAPPER = new AbstractTypeMapper<>() {
|
||||
@Override
|
||||
public String map(Object sender, PreviousArguments previousArguments, String s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabComplete(Object sender, PreviousArguments previousArguments, String s) {
|
||||
return Collections.singletonList(s);
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
addMapper(boolean.class, Boolean.class, new BooleanMapper());
|
||||
addMapper(int.class, Integer.class, new NumberMapper(Integer::parseInt, false));
|
||||
addMapper(long.class, Long.class, new NumberMapper(Long::parseLong, false));
|
||||
addMapper(float.class, Float.class, new NumberMapper(Float::parseFloat, true));
|
||||
addMapper(double.class, Double.class, new NumberMapper(Double::parseDouble, true));
|
||||
MAPPER_FUNCTIONS.put(String.class.getTypeName(), STRING_MAPPER);
|
||||
}
|
||||
|
||||
private static void addMapper(Class<?> clazz, Class<?> alternativeClazz, AbstractTypeMapper<?, ?> mapper) {
|
||||
MAPPER_FUNCTIONS.put(clazz.getTypeName(), mapper);
|
||||
MAPPER_FUNCTIONS.put(alternativeClazz.getTypeName(), mapper);
|
||||
}
|
||||
|
||||
public static <K, T> void addMapper(Class<T> clazz, AbstractTypeMapper<K, T> mapper) {
|
||||
addMapper(clazz.getTypeName(), mapper);
|
||||
}
|
||||
|
||||
public static <T> void addMapper(String name, AbstractTypeMapper<T, ?> mapper) {
|
||||
MAPPER_FUNCTIONS.putIfAbsent(name, mapper);
|
||||
}
|
||||
|
||||
public static <T> void addValidator(Class<T> clazz, AbstractTypeValidator<T, ?> validator) {
|
||||
addValidator(clazz.getTypeName(), validator);
|
||||
}
|
||||
|
||||
public static <T> void addValidator(String name, AbstractTypeValidator<T, ?> validator) {
|
||||
VALIDATOR_FUNCTIONS.putIfAbsent(name, validator);
|
||||
}
|
||||
|
||||
public static <T> void addSupplier(Class<T> clazz, AbstractTypeSupplier<T, ?> supplier) {
|
||||
addSupplier(clazz.getTypeName(), supplier);
|
||||
}
|
||||
|
||||
public static <T> void addSupplier(String name, AbstractTypeSupplier<T, ?> supplier) {
|
||||
SUPPLIER_FUNCTIONS.putIfAbsent(name, supplier);
|
||||
}
|
||||
|
||||
public static List<Annotation> getAnnotations(AnnotatedElement annotatedElement) {
|
||||
List<Annotation> annotationList = new ArrayList<>();
|
||||
for (Annotation annotation : annotatedElement.getAnnotations()) {
|
||||
try {
|
||||
Method method = annotation.annotationType().getMethod("value");
|
||||
Class<?> returnType = method.getReturnType();
|
||||
if (!returnType.isArray()) {
|
||||
annotationList.add(annotation);
|
||||
continue;
|
||||
}
|
||||
Class<?> innerReturnType = returnType.getComponentType();
|
||||
if (!(innerReturnType.isAnnotation() && innerReturnType.isAnnotationPresent(Repeatable.class))) {
|
||||
annotationList.add(annotation);
|
||||
continue;
|
||||
}
|
||||
Repeatable repeatable = innerReturnType.getAnnotation(Repeatable.class);
|
||||
Class<? extends Annotation> containerType = repeatable.value();
|
||||
if (containerType == returnType) {
|
||||
throw new UnsupportedOperationException("Repeatable annotation must have a container annotation");
|
||||
}
|
||||
try {
|
||||
Annotation[] innerAnnotations = (Annotation[]) method.invoke(annotation);
|
||||
Collections.addAll(annotationList, innerAnnotations);
|
||||
} catch (Exception e) {
|
||||
annotationList.add(annotation);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
annotationList.add(annotation);
|
||||
}
|
||||
}
|
||||
annotationList.removeIf(anno -> !anno.annotationType().isAnnotationPresent(Handler.Implementation.class));
|
||||
return annotationList;
|
||||
}
|
||||
|
||||
public static <T extends Handler> List<Annotation> getAnnotations(AnnotatedElement annotatedElement, Class<T> type) {
|
||||
List<Annotation> annotations = getAnnotations(annotatedElement);
|
||||
annotations.removeIf(annotation -> {
|
||||
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||
return implementation == null || !type.isAssignableFrom(implementation.value());
|
||||
});
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public static ToIntFunction<Number> createComparator(String type, Handler.TypeWrapper clazz, int iValue, long lValue, float fValue, double dValue) {
|
||||
if (clazz.is(int.class) || clazz.is(Integer.class)) {
|
||||
return number -> Integer.compare(number.intValue(), iValue);
|
||||
} else if (clazz.is(long.class) || clazz.is(Long.class)) {
|
||||
return number -> Long.compare(number.longValue(), lValue);
|
||||
} else if (clazz.is(float.class) || clazz.is(Float.class)) {
|
||||
return number -> Float.compare(number.floatValue(), fValue);
|
||||
} else if (clazz.is(double.class) || clazz.is(Double.class)) {
|
||||
return number -> Double.compare(number.doubleValue(), dValue);
|
||||
} else {
|
||||
throw new IllegalArgumentException(type + " annotation is not supported for " + clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command;
|
||||
|
||||
import de.steamwar.command.annotations.Supplier;
|
||||
import de.steamwar.command.graph.*;
|
||||
import de.steamwar.command.handler.GreedyHandler;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
class DataImpl implements Handler.DataCheckable, Handler.DataReadable, Handler.DataWritable {
|
||||
|
||||
private final AbstractCommand<?> container;
|
||||
private final Object self;
|
||||
private final RootNode<?> node;
|
||||
private final Map<Class<?>, Function<?, ?>> executorMapper;
|
||||
private final Map<String, AbstractTypeMapper<?, ?>> mapper;
|
||||
private final Map<String, AbstractTypeMapper<?, ?>> globalMapper;
|
||||
private final Map<String, AbstractTypeValidator<?, ?>> validator;
|
||||
private final Map<String, AbstractTypeValidator<?, ?>> globalValidator;
|
||||
private final Map<String, AbstractTypeSupplier<?, ?>> supplier;
|
||||
private final Map<String, AbstractTypeSupplier<?, ?>> globalSupplier;
|
||||
|
||||
private final Map<Method, Object> cache = new HashMap<>();
|
||||
|
||||
DataImpl(AbstractCommand<?> container, Object self, RootNode<?> node, Map<Class<?>, Function<?, ?>> executorMapper, Map<String, AbstractTypeMapper<?, ?>> mapper, Map<String, AbstractTypeMapper<?, ?>> globalMapper, Map<String, AbstractTypeValidator<?, ?>> validator, Map<String, AbstractTypeValidator<?, ?>> globalValidator, Map<String, AbstractTypeSupplier<?, ?>> supplier, Map<String, AbstractTypeSupplier<?, ?>> globalSupplier) {
|
||||
this.container = container;
|
||||
this.self = self;
|
||||
this.node = node;
|
||||
this.executorMapper = executorMapper;
|
||||
this.mapper = mapper;
|
||||
this.globalMapper = globalMapper;
|
||||
this.validator = validator;
|
||||
this.globalValidator = globalValidator;
|
||||
this.supplier = supplier;
|
||||
this.globalSupplier = globalSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasExecutorMapper(Class<?> clazz) {
|
||||
return getExecutorMapper(clazz) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<?, ?> getExecutorMapper(Class<?> clazz) {
|
||||
for (Map.Entry<Class<?>, Function<?, ?>> entry : executorMapper.entrySet()) {
|
||||
if (entry.getKey().isAssignableFrom(clazz)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMapper(String key) {
|
||||
return mapper.containsKey(key) || globalMapper.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> AbstractTypeMapper<A, B> getMapper(String key) {
|
||||
return (AbstractTypeMapper<A, B>) mapper.getOrDefault(key, globalMapper.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> void addMapper(String key, boolean local, AbstractTypeMapper<A, B> mapper) {
|
||||
if (local) {
|
||||
this.mapper.put(key, mapper);
|
||||
} else {
|
||||
this.globalMapper.putIfAbsent(key, mapper);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValidator(String key) {
|
||||
return validator.containsKey(key) || globalValidator.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> AbstractTypeValidator<A, B> getValidator(String key) {
|
||||
return (AbstractTypeValidator<A, B>) validator.getOrDefault(key, globalValidator.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> void addValidator(String key, boolean local, AbstractTypeValidator<A, B> validator) {
|
||||
if (local) {
|
||||
this.validator.put(key, validator);
|
||||
} else {
|
||||
this.globalValidator.putIfAbsent(key, validator);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSupplier(String key) {
|
||||
return supplier.containsKey(key) || globalSupplier.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> AbstractTypeSupplier<A, B> getSupplier(String key) {
|
||||
return (AbstractTypeSupplier<A, B>) supplier.getOrDefault(key, globalSupplier.get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> void addSupplier(String key, boolean local, AbstractTypeSupplier<A, B> supplier) {
|
||||
if (local) {
|
||||
this.supplier.put(key, supplier);
|
||||
} else {
|
||||
this.globalSupplier.putIfAbsent(key, supplier);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoking the same method twice will result in the exact same result.
|
||||
*/
|
||||
@Override
|
||||
public <T> T invoke(Method method) {
|
||||
return (T) cache.computeIfAbsent(method, m -> {
|
||||
try {
|
||||
return m.invoke(self);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommand(Method method, String[] subCommand, String[] description, boolean noTabComplete) {
|
||||
Node<?> temp = node;
|
||||
container.descriptions.addAll(Arrays.asList(description));
|
||||
if (noTabComplete) {
|
||||
temp = temp.addChild(null, new NoTabCompleteNode<>());
|
||||
}
|
||||
for (int i = 0; i < subCommand.length; i++) {
|
||||
temp = temp.addChild(null, new LiteralNode<>(subCommand[i]));
|
||||
}
|
||||
Parameter[] parameters = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
Parameter parameter = parameters[i];
|
||||
if (i == 0) {
|
||||
temp = temp.addChild(parameter, new ExecutorTypeNode<>(parameter, i, this));
|
||||
continue;
|
||||
}
|
||||
if (parameter.isAnnotationPresent(Supplier.class)) {
|
||||
temp = temp.addChild(parameter, new SupplierNode<>(parameter, this));
|
||||
continue;
|
||||
}
|
||||
Class<?> type = parameter.getType();
|
||||
boolean isArray = parameter.isVarArgs() || type.isArray();
|
||||
if (!isArray) {
|
||||
temp = temp.addChild(parameter, new TypeNode<>(parameter, i, this));
|
||||
continue;
|
||||
}
|
||||
boolean greedy = parameter.isVarArgs() || GreedyHandler.isGreedy(parameter);
|
||||
if (greedy) {
|
||||
temp = temp.addChild(parameter, new GreedyArrayNode<>(parameter, i, this));
|
||||
} else {
|
||||
temp = temp.addChild(parameter, new NonGreedyArrayNode<>(parameter, i, this));
|
||||
}
|
||||
}
|
||||
temp.addChild(null, new ExecuteNode<>(self, method));
|
||||
}
|
||||
}
|
||||
@@ -1,370 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface Handler {
|
||||
|
||||
default Optional<Class<?>> getGenericTypeOfReturn(Method method) {
|
||||
Type type;
|
||||
try {
|
||||
type = method.getGenericReturnType();
|
||||
} catch (Exception e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (!(type instanceof ParameterizedType)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ParameterizedType parameterizedType = (ParameterizedType) type;
|
||||
Type[] generics = parameterizedType.getActualTypeArguments();
|
||||
if (generics.length != 1 && generics.length != 2) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Type genericType = generics[generics.length - 1];
|
||||
try {
|
||||
return Optional.of(Class.forName(genericType.getTypeName()));
|
||||
} catch (Exception e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.ANNOTATION_TYPE)
|
||||
@interface Implementation {
|
||||
Class<? extends Handler> value();
|
||||
}
|
||||
|
||||
class HandlerException extends Exception {
|
||||
@Getter
|
||||
private final CodePlace codePlace;
|
||||
|
||||
public HandlerException(String message, CodePlace codePlace) {
|
||||
super(message);
|
||||
this.codePlace = codePlace;
|
||||
}
|
||||
}
|
||||
|
||||
interface DataCheckable {
|
||||
boolean hasExecutorMapper(Class<?> clazz);
|
||||
|
||||
boolean hasMapper(String key);
|
||||
|
||||
boolean hasValidator(String key);
|
||||
|
||||
boolean hasSupplier(String key);
|
||||
}
|
||||
|
||||
interface DataReadable {
|
||||
Function<?, ?> getExecutorMapper(Class<?> clazz);
|
||||
|
||||
<A, B> AbstractTypeMapper<A, B> getMapper(String key);
|
||||
|
||||
<A, B> AbstractTypeValidator<A, B> getValidator(String key);
|
||||
|
||||
<A, B> AbstractTypeSupplier<A, B> getSupplier(String key);
|
||||
}
|
||||
|
||||
interface DataWritable {
|
||||
Function<?, ?> getExecutorMapper(Class<?> clazz);
|
||||
|
||||
<A, B> void addMapper(String key, boolean local, AbstractTypeMapper<A, B> mapper);
|
||||
|
||||
<A, B> void addValidator(String key, boolean local, AbstractTypeValidator<A, B> validator);
|
||||
|
||||
<A, B> void addSupplier(String key, boolean local, AbstractTypeSupplier<A, B> supplier);
|
||||
|
||||
/**
|
||||
* Invoking the same method twice will result in the exact same result.
|
||||
*/
|
||||
<T> T invoke(Method method);
|
||||
|
||||
void addCommand(Method method, String[] subCommand, String[] description, boolean noTabComplete);
|
||||
}
|
||||
|
||||
interface HandlerMethod<T extends Annotation> extends Handler {
|
||||
void check(AnnotationWrapper<T> annotation, MethodWrapper method, DataCheckable dataCheckable) throws HandlerException;
|
||||
|
||||
int getRunPriority();
|
||||
|
||||
void run(T annotation, Method method, DataWritable dataWritable);
|
||||
}
|
||||
|
||||
interface HandlerParameter<T extends Annotation, A, B> extends Handler {
|
||||
void check(AnnotationWrapper<T> annotation, MethodWrapper methodWrapper, ParameterWrapper parameter, int index, DataCheckable dataCheckable) throws HandlerException;
|
||||
|
||||
default boolean needsParentTypeMapper() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null values are allowed to be returned.
|
||||
*/
|
||||
default AbstractTypeMapper<A, B> getTypeMapper(T annotation, Parameter parameter, int index, DataReadable dataReadable, AbstractTypeMapper<A, B> parentTypeMapper) {
|
||||
return null;
|
||||
}
|
||||
|
||||
default int getValidatorPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null values are allowed to be returned.
|
||||
*/
|
||||
default AbstractTypeValidator<A, B> getValidator(T annotation, Parameter parameter, int index, DataReadable dataReadable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
class CodePlace {
|
||||
|
||||
private final MethodWrapper method;
|
||||
private final ParameterWrapper parameter;
|
||||
private final AnnotationWrapper<?>[] annotations;
|
||||
|
||||
public CodePlace(MethodWrapper method, AnnotationWrapper<?>... annotations) {
|
||||
this.method = method;
|
||||
this.parameter = null;
|
||||
this.annotations = annotations;
|
||||
}
|
||||
|
||||
public CodePlace(ParameterWrapper parameter, AnnotationWrapper<?>... annotations) {
|
||||
this.method = null;
|
||||
this.parameter = parameter;
|
||||
this.annotations = annotations;
|
||||
}
|
||||
}
|
||||
|
||||
interface MethodWrapper {
|
||||
String getName();
|
||||
|
||||
int getParameterCount();
|
||||
|
||||
TypeWrapper getReturnType();
|
||||
|
||||
ParameterWrapper[] getParameters();
|
||||
|
||||
class ForMethod implements MethodWrapper {
|
||||
|
||||
@Getter
|
||||
private final Method method;
|
||||
|
||||
public ForMethod(Method method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return method.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParameterCount() {
|
||||
return method.getParameterCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeWrapper getReturnType() {
|
||||
return new TypeWrapper.ForClass(method.getReturnType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterWrapper[] getParameters() {
|
||||
return Arrays.stream(method.getParameters()).map(ParameterWrapper.ForParameter::new).toArray(ParameterWrapper[]::new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface ParameterWrapper {
|
||||
TypeWrapper getType();
|
||||
|
||||
boolean isVarArgs();
|
||||
|
||||
boolean isAnnotationPresent(Class<? extends Annotation> annotation);
|
||||
|
||||
<A extends Annotation> AnnotationWrapper<A> getAnnotation(Class<A> annotation);
|
||||
|
||||
String getName();
|
||||
|
||||
List<AnnotationWrapper<?>> getAnnotations();
|
||||
|
||||
class ForParameter implements ParameterWrapper {
|
||||
|
||||
@Getter
|
||||
private final Parameter parameter;
|
||||
|
||||
public ForParameter(Parameter parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeWrapper getType() {
|
||||
return new TypeWrapper.ForClass(this.parameter.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVarArgs() {
|
||||
return parameter.isVarArgs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
|
||||
return parameter.isAnnotationPresent(annotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends Annotation> AnnotationWrapper<A> getAnnotation(Class<A> annotation) {
|
||||
return new AnnotationWrapper.ForAnnotation<>(parameter.getAnnotation(annotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return parameter.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationWrapper<?>> getAnnotations() {
|
||||
return CommandUtils.getAnnotations(parameter)
|
||||
.stream()
|
||||
.map(AnnotationWrapper.ForAnnotation::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface TypeWrapper {
|
||||
|
||||
boolean isAssignableTo(Class<?> clazz);
|
||||
|
||||
boolean isAssignableTo(TypeWrapper type);
|
||||
|
||||
boolean isPrimitive();
|
||||
|
||||
boolean isArray();
|
||||
|
||||
boolean isEnum();
|
||||
|
||||
boolean is(Class<?> clazz);
|
||||
|
||||
boolean is(TypeWrapper type);
|
||||
|
||||
TypeWrapper getComponentType();
|
||||
|
||||
String getName();
|
||||
|
||||
String getTypeName();
|
||||
|
||||
class ForClass implements TypeWrapper {
|
||||
@Getter
|
||||
private final Class<?> clazz;
|
||||
|
||||
public ForClass(Class<?> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableTo(Class<?> clazz) {
|
||||
return clazz.isAssignableFrom(this.clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAssignableTo(TypeWrapper type) {
|
||||
if (type instanceof ForClass) {
|
||||
return ((ForClass) type).getClazz().isAssignableFrom(clazz);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimitive() {
|
||||
return clazz.isPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isArray() {
|
||||
return clazz.isArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
return clazz.isEnum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Class<?> clazz) {
|
||||
return this.clazz == clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(TypeWrapper type) {
|
||||
if (type instanceof ForClass) {
|
||||
return ((ForClass) type).getClazz() == this.clazz;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeWrapper getComponentType() {
|
||||
return new TypeWrapper.ForClass(this.clazz.getComponentType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.clazz.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return this.clazz.getTypeName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface AnnotationWrapper<A extends Annotation> {
|
||||
|
||||
A getAnnotation();
|
||||
|
||||
class ForAnnotation<A extends Annotation> implements AnnotationWrapper<A> {
|
||||
|
||||
private A annotation;
|
||||
|
||||
public ForAnnotation(A annotation) {
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public A getAnnotation() {
|
||||
return this.annotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public interface OptionEnum<T extends Enum<T> & OptionEnum<T>> {
|
||||
default List<String> getTabCompletes() {
|
||||
return Arrays.asList("-" + ((T) this).name().toLowerCase());
|
||||
}
|
||||
T[] getRemoved();
|
||||
}
|
||||
@@ -1,96 +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.command;
|
||||
|
||||
import lombok.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PreviousArguments {
|
||||
|
||||
public final String[] userArgs;
|
||||
public final Object[] mappedArgs;
|
||||
public final boolean hasMoreArguments;
|
||||
private final Function<String, Object> getByNameFunction;
|
||||
private boolean usedOptionalValue = false;
|
||||
|
||||
public PreviousArguments(String[] userArgs, Object[] mappedArgs, boolean hasMoreArguments, Function<String, Object> getByNameFunction) {
|
||||
this.userArgs = userArgs;
|
||||
this.mappedArgs = mappedArgs;
|
||||
this.hasMoreArguments = hasMoreArguments;
|
||||
this.getByNameFunction = getByNameFunction;
|
||||
}
|
||||
|
||||
public boolean hasUsedOptionalValue() {
|
||||
return usedOptionalValue;
|
||||
}
|
||||
|
||||
public void usedOptionalValue() {
|
||||
this.usedOptionalValue = true;
|
||||
}
|
||||
|
||||
public String getUserArg(int index) {
|
||||
return userArgs[userArgs.length - index - 1];
|
||||
}
|
||||
|
||||
public <T> T getMappedArg(int index) {
|
||||
return (T) mappedArgs[mappedArgs.length - index - 1];
|
||||
}
|
||||
|
||||
public <T> Optional<T> getFirst(Class<T> clazz) {
|
||||
for (Object o : mappedArgs) {
|
||||
if (clazz.isInstance(o)) {
|
||||
return Optional.of((T) o);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public <T> List<T> getAll(Class<T> clazz) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (Object o : mappedArgs) {
|
||||
if (clazz.isInstance(o)) {
|
||||
list.add((T) o);
|
||||
}
|
||||
if (o == null) {
|
||||
continue;
|
||||
}
|
||||
if (o.getClass().isArray()) {
|
||||
Object[] array = (Object[]) o;
|
||||
if (array.length == 0) {
|
||||
continue;
|
||||
}
|
||||
for (Object o1 : array) {
|
||||
if (clazz.isInstance(o1)) {
|
||||
list.add((T) o1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public <T> T getByName(@NonNull String name) {
|
||||
return (T) getByNameFunction.apply(name);
|
||||
}
|
||||
}
|
||||
-109
@@ -1,109 +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.command;
|
||||
|
||||
import de.steamwar.command.mapper.internal.DelegatingMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@UtilityClass
|
||||
public class TabCompletionCache {
|
||||
|
||||
private final Map<Key, TabCompletions> tabCompletionCache = new ConcurrentHashMap<>();
|
||||
|
||||
Set<AbstractTypeMapper<?, ?>> cached = new HashSet<>();
|
||||
Set<AbstractTypeMapper<?, ?>> global = new HashSet<>();
|
||||
Map<AbstractTypeMapper<?, ?>, Long> cacheDuration = new HashMap<>();
|
||||
|
||||
static {
|
||||
Thread thread = new Thread(() -> {
|
||||
while (true) {
|
||||
Set<Key> toRemove = new HashSet<>();
|
||||
for (Map.Entry<Key, TabCompletions> tabCompletionsEntry : tabCompletionCache.entrySet()) {
|
||||
if (System.currentTimeMillis() - tabCompletionsEntry.getValue().timestamp > cacheDuration.get(tabCompletionsEntry.getKey().typeMapper)) {
|
||||
toRemove.add(tabCompletionsEntry.getKey());
|
||||
}
|
||||
}
|
||||
for (Key key : toRemove) {
|
||||
tabCompletionCache.remove(key);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.setName("TabCompletionCache Invalidator");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void add(AbstractTypeMapper<?, ?> typeMapper, boolean global, long cacheDuration, TimeUnit timeUnit) {
|
||||
TabCompletionCache.cached.add(typeMapper);
|
||||
if (global) TabCompletionCache.global.add(typeMapper);
|
||||
TabCompletionCache.cacheDuration.put(typeMapper, timeUnit.toMillis(cacheDuration));
|
||||
}
|
||||
|
||||
public <A, B> AbstractTypeMapper<A, B> cached(AbstractTypeMapper<A, B> dataMapper, AbstractTypeMapper<A, B> toBeCached) {
|
||||
if (!cached.contains(dataMapper)) return toBeCached;
|
||||
boolean global = TabCompletionCache.global.contains(dataMapper);
|
||||
long cacheDuration = TabCompletionCache.cacheDuration.get(dataMapper);
|
||||
|
||||
return new DelegatingMapper<>(toBeCached, null) {
|
||||
@Override
|
||||
public Collection<String> tabComplete(A sender, PreviousArguments previousArguments, String s) {
|
||||
String normalizedArg = dataMapper.normalize(global ? null : sender, s);
|
||||
if (normalizedArg == null) normalizedArg = "";
|
||||
Key key = new Key(global ? null : sender, normalizedArg, dataMapper);
|
||||
|
||||
TabCompletions tabCompletions = tabCompletionCache.computeIfAbsent(key, ignore -> {
|
||||
return new TabCompletions(System.currentTimeMillis(), toBeCached.tabComplete(sender, previousArguments, s));
|
||||
});
|
||||
|
||||
if (System.currentTimeMillis() - tabCompletions.timestamp > cacheDuration) {
|
||||
tabCompletions.tabCompletions = toBeCached.tabComplete(sender, previousArguments, s);
|
||||
}
|
||||
tabCompletions.timestamp = System.currentTimeMillis();
|
||||
return tabCompletions.tabCompletions;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
private static class Key {
|
||||
private Object sender;
|
||||
private String arg;
|
||||
private AbstractTypeMapper<?, ?> typeMapper;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class TabCompletions {
|
||||
private long timestamp;
|
||||
private Collection<String> tabCompletions;
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.AllowNullHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to allow null values passed to the command.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(AllowNullHandler.Impl.class)
|
||||
public @interface AllowNull {
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ArrayLengthHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a minimum and maximum length the supplied array can have.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(ArrayLengthHandler.Impl.class)
|
||||
public @interface ArrayLength {
|
||||
/**
|
||||
* Inclusive
|
||||
*/
|
||||
int min() default 0;
|
||||
|
||||
/**
|
||||
* Inclusive
|
||||
*/
|
||||
int max() default Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Error message if too few Elements got parsed. There are 2 arguments provided to the message.
|
||||
* The first is the number of elements that got parsed as a number and the second one is how many
|
||||
* should have been parsed, so the min number of elements expected.
|
||||
*/
|
||||
String error() default "";
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.AbstractTypeMapper;
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.CachedHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This annotation is used to register a or {@link Mapper}
|
||||
* on registration as being cached. Only TabCompletions are cached for the duration
|
||||
* denoted by {@link #timeUnit()} and {@link #cacheDuration()} using
|
||||
* {@link TimeUnit#toMillis(long)}. If {@link #global()} is {@code true}, the
|
||||
* cache will not be created per player but for everyone. This is useful for
|
||||
* commands that are not player specific.
|
||||
* <br><br>
|
||||
* To calculate the cache key for a {@link AbstractTypeMapper} the
|
||||
* {@link AbstractTypeMapper#normalize(Object, String)} method is called.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Handler.Implementation(CachedHandler.Impl.class)
|
||||
public @interface Cached {
|
||||
long cacheDuration() default 5;
|
||||
|
||||
TimeUnit timeUnit() default TimeUnit.SECONDS;
|
||||
|
||||
boolean global() default false;
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.AbstractTypeMapper;
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ClassMapperHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation for registering a method as a class mapper.
|
||||
* The annotated method will be executed while {@link #initialize()}
|
||||
* is evaluated. The result of this method will be cached under the
|
||||
* name {@link ClassMapper#value()} converted to a {@link String} using
|
||||
* {@link Class#getTypeName()}. {@link AbstractTypeMapper} will be used
|
||||
* as the default mapper if the type this mapper is registered for is
|
||||
* found as a parameter of any command method annotated with {@link Register}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Handler.Implementation(ClassMapperHandler.Impl.class)
|
||||
@Deprecated
|
||||
@DeprecationInfo("Use @Mapper instead")
|
||||
public @interface ClassMapper {
|
||||
|
||||
/**
|
||||
* The type this mapper is registered for.
|
||||
*/
|
||||
Class<?> value();
|
||||
|
||||
/**
|
||||
* If {@code true}, the mapper will only be used in the current command class.
|
||||
*/
|
||||
boolean local() default true;
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ClassValidatorHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation for registering a method as a class validator.
|
||||
* The annotated method will be executed while {@link #initialize()}
|
||||
* is evaluated. The result of this method will be cached under the
|
||||
* name {@link ClassValidator#value()} converted to a {@link String} using
|
||||
* {@link Class#getTypeName()}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Handler.Implementation(ClassValidatorHandler.Impl.class)
|
||||
@Deprecated
|
||||
@DeprecationInfo("Use @Validator instead")
|
||||
public @interface ClassValidator {
|
||||
|
||||
/**
|
||||
* The type this validator is registered for.
|
||||
*/
|
||||
Class<?> value();
|
||||
|
||||
/**
|
||||
* If {@code true}, the validator will only be used in the current command class.
|
||||
*/
|
||||
boolean local() default true;
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DeprecationInfo {
|
||||
String value();
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.EndsWithHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(EndsWithHandler.Impl.class)
|
||||
public @interface EndsWith {
|
||||
|
||||
String value();
|
||||
|
||||
String error() default "";
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ErrorMessageHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define an error message for a parameter.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(ErrorMessageHandler.Impl.class)
|
||||
public @interface ErrorMessage {
|
||||
/**
|
||||
* Error message to be displayed when the parameter is invalid.
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* This is the short form for 'allowEmptyArrays'.
|
||||
*/
|
||||
@Deprecated
|
||||
@DeprecationInfo("Use @ArrayLength instead of this flag")
|
||||
boolean allowEAs() default true;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.GreedyHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation can have a huge performance impact. Both positive and negative.
|
||||
* You can design your command to be more flexible and allow performance improvements if used correctly.
|
||||
* <br><br>
|
||||
* The more restrictive the underlying array type is, the more performance can be gained.
|
||||
* <br><br>
|
||||
* Using this annotation on the varargs parameter of a command will not have any effect, since they are already treated as greedy arrays.
|
||||
* <br><br>
|
||||
* The {@link #backTrackingDepth()} can be used to limit the amount of backtracking that is done. This can be used to improve performance.
|
||||
* For varargs parameters, this value is defaulted to 0, since they are at the end of the parameter list.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(GreedyHandler.Impl.class)
|
||||
public @interface Greedy {
|
||||
int backTrackingDepth() default Integer.MAX_VALUE;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.LengthHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a minimum and maximum length the supplied string can have.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(LengthHandler.Impl.class)
|
||||
public @interface Length {
|
||||
/**
|
||||
* Inclusive
|
||||
*/
|
||||
int min() default 0;
|
||||
|
||||
/**
|
||||
* Inclusive
|
||||
*/
|
||||
int max() default Integer.MAX_VALUE;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.AbstractTypeMapper;
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.MapperHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation for registering a method as a mapper. The annotated method will
|
||||
* be executed while {@link #initialize()} is evaluated. The result of this
|
||||
* method will be cached under either {@link Mapper#value()} or {@link Mapper#value()}.
|
||||
* If {@link Mapper#type()} is used any parameter using that type will be using
|
||||
* this {@link AbstractTypeMapper} implicitly. While using this annotation on
|
||||
* a method it can be possible to not supply any type. On a parameter you can
|
||||
* only use this annotation using the {@link Mapper#value()} value.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Handler.Implementation(MapperHandler.Impl.class)
|
||||
public @interface Mapper {
|
||||
/**
|
||||
* The name this mapper is registered for.
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The type this mapper is registered for.
|
||||
*/
|
||||
Class<?> type() default void.class;
|
||||
|
||||
/**
|
||||
* If {@code true}, the mapper will only be used in the current command class.
|
||||
*/
|
||||
boolean local() default true;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.MaxHandler;
|
||||
import de.steamwar.command.handler.MaxReferenceHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a maximum number value for a parameter.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(MaxHandler.Impl.class)
|
||||
public @interface Max {
|
||||
int intValue() default Integer.MAX_VALUE;
|
||||
|
||||
long longValue() default Long.MAX_VALUE;
|
||||
|
||||
float floatValue() default Float.MAX_VALUE;
|
||||
|
||||
double doubleValue() default Double.MAX_VALUE;
|
||||
|
||||
boolean inclusive() default true;
|
||||
|
||||
/**
|
||||
* Error message to be displayed when the argument supplied is bigger than this allows.
|
||||
* Two arguments are supplied to the error message. The first is the number that got parsed
|
||||
* and the second is the max this annotation allows.
|
||||
*/
|
||||
String error() default "";
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(MaxReferenceHandler.Impl.class)
|
||||
@interface Reference {
|
||||
String value();
|
||||
|
||||
boolean inclusive() default true;
|
||||
|
||||
/**
|
||||
* Error message to be displayed when the argument supplied is smaller than this allows.
|
||||
* Two arguments are supplied to the error message. The first is the number that got parsed
|
||||
* and the second is the min this annotation allows.
|
||||
*/
|
||||
String error() default "";
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.MinHandler;
|
||||
import de.steamwar.command.handler.MinReferenceHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a minimum number value for a parameter.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(MinHandler.Impl.class)
|
||||
public @interface Min {
|
||||
int intValue() default Integer.MIN_VALUE;
|
||||
|
||||
long longValue() default Long.MIN_VALUE;
|
||||
|
||||
float floatValue() default Float.MIN_VALUE;
|
||||
|
||||
double doubleValue() default Double.MIN_VALUE;
|
||||
|
||||
boolean inclusive() default true;
|
||||
|
||||
/**
|
||||
* Error message to be displayed when the argument supplied is smaller than this allows.
|
||||
* Two arguments are supplied to the error message. The first is the number that got parsed
|
||||
* and the second is the min this annotation allows.
|
||||
*/
|
||||
String error() default "";
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(MinReferenceHandler.Impl.class)
|
||||
@interface Reference {
|
||||
String value();
|
||||
|
||||
boolean inclusive() default true;
|
||||
|
||||
/**
|
||||
* Error message to be displayed when the argument supplied is smaller than this allows.
|
||||
* Two arguments are supplied to the error message. The first is the number that got parsed
|
||||
* and the second is the min this annotation allows.
|
||||
*/
|
||||
String error() default "";
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.OptionalValueHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a default value for a parameter.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(OptionalValueHandler.Impl.class)
|
||||
public @interface OptionalValue {
|
||||
/**
|
||||
* Will pe parsed against the TypeMapper specified by the parameter or annotation.
|
||||
*/
|
||||
String value();
|
||||
|
||||
/**
|
||||
* The method name stands for 'onlyUseIfNoneIsGiven'.
|
||||
*/
|
||||
boolean onlyUINIG() default false;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.RegexHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(RegexHandler.Impl.class)
|
||||
public @interface Regex {
|
||||
|
||||
String value();
|
||||
|
||||
String error() default "";
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.RegisterHandler;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for registering a method as a command.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Repeatable(Register.Registers.class)
|
||||
@Handler.Implementation(RegisterHandler.Impl.class)
|
||||
public @interface Register {
|
||||
|
||||
/**
|
||||
* Identifier of subcommand.
|
||||
*/
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Description of subcommand.
|
||||
*/
|
||||
String[] description() default {};
|
||||
|
||||
/**
|
||||
* If {@code true}, the command will not be tab completed.
|
||||
*/
|
||||
boolean noTabComplete() default false;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
@Handler.Implementation(RegisterHandler.Impl.class)
|
||||
@interface Registers {
|
||||
Register[] value();
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.StartsWithHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(StartsWithHandler.Impl.class)
|
||||
public @interface StartsWith {
|
||||
|
||||
String value();
|
||||
|
||||
String error() default "";
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.StaticValueHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define static values for a parameter like an enum just without the enum.
|
||||
* You can use this annotation on a parameter of type {@link String} or {@link int}, {@link long} and
|
||||
* {@link boolean}. While using an int, the value will represent the index into the value array. While
|
||||
* using a boolean, the {@link #falseValues()} defines which indices are considered {@code false} or
|
||||
* {@code true}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(StaticValueHandler.Impl.class)
|
||||
@Deprecated
|
||||
@DeprecationInfo("Use @Values instead")
|
||||
public @interface StaticValue {
|
||||
String[] value();
|
||||
|
||||
/**
|
||||
* This is the short form for 'allowImplicitSwitchExpressions'
|
||||
* and can be set to true if you want to allow int as well as boolean as annotated parameter types.
|
||||
* The value array needs to be at least 2 long for this flag to be considered.
|
||||
* While using an int, the value will represent the index into the value array.
|
||||
* While using a boolean, the {@link #falseValues()} defines which indices are
|
||||
* considered {@code false} or {@code true}.
|
||||
*/
|
||||
@Deprecated
|
||||
@DeprecationInfo("Dont need to set this to true")
|
||||
boolean allowISE() default false;
|
||||
|
||||
int[] falseValues() default {0};
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.SupplierHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Handler.Implementation(SupplierHandler.Impl.class)
|
||||
public @interface Supplier {
|
||||
/**
|
||||
* The name this supplier is registered for.
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The type this supplier is registered for.
|
||||
*/
|
||||
Class<?> type() default void.class;
|
||||
|
||||
/**
|
||||
* If {@code true}, the supplier will only be used in the current command class.
|
||||
*/
|
||||
boolean local() default true;
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.TabFilterHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation defines per Parameter how the TabCompletions should be filtered and displayed by the client.
|
||||
* There are 3 modes further described by {@link TabFilterType}. If this annotation is not present the default
|
||||
* {@link TabFilterType#STARTS_WITH} is used.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(TabFilterHandler.Impl.class)
|
||||
public @interface TabFilter {
|
||||
TabFilterType value();
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
public enum TabFilterType {
|
||||
|
||||
/**
|
||||
* This value defines that, the starts with tab-completion filter is used.<br>
|
||||
* see: {@link de.steamwar.command.mapper.internal.StartsWithFilter} for more.
|
||||
*/
|
||||
STARTS_WITH,
|
||||
|
||||
/**
|
||||
* This value defines that, the contains tab-completions filter is used.
|
||||
* see: {@link de.steamwar.command.mapper.internal.ContainsFilter} for more.
|
||||
*/
|
||||
CONTAINS,
|
||||
|
||||
/**
|
||||
* This value disables any tab-completion filters and just returns anything you
|
||||
* specified inside the TypeMapper.
|
||||
*/
|
||||
NONE
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.UniqueHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define an array with unique values.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(UniqueHandler.Impl.class)
|
||||
public @interface Unique {
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ValidatorHandler;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation for registering a method as a validator.
|
||||
* The annotated method will be executed while {@link #initialize()}
|
||||
* is evaluated. The result of this method will be cached under the
|
||||
* name {@link ClassValidator#value()} converted to a {@link String} using
|
||||
* {@link Class#getTypeName()}.
|
||||
* This annotation can also be used on parameters to apply a validator to them.
|
||||
* You can leave the {@link #value()} empty here to use the type of the parameter.
|
||||
* For registering you should never leave {@link #value()} empty.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Handler.Implementation(ValidatorHandler.Impl.class)
|
||||
@Repeatable(Validator.Validators.class)
|
||||
public @interface Validator {
|
||||
/**
|
||||
* The name this validator is registered for.
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* The type this validator is registered for.
|
||||
*/
|
||||
Class<?> type() default void.class;
|
||||
|
||||
/**
|
||||
* If {@code true}, the validator will only be used in the current command class.
|
||||
*/
|
||||
boolean local() default true;
|
||||
|
||||
/**
|
||||
* If {@code true}, the validator will be inverted for parameter usage.
|
||||
*/
|
||||
boolean invert() default false;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(ValidatorHandler.Impl.class)
|
||||
@interface Validators {
|
||||
Validator[] value();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.annotations;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.ValuesHandler;
|
||||
import de.steamwar.command.handler.ValuesReferenceHandler;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* This annotation is used to define static values for a parameter like an enum just without the enum.
|
||||
* You can use this annotation on a parameter of type {@link String} or {@link int}, {@link long} and
|
||||
* {@link boolean}. While using an int, the value will represent the index into the value array. While
|
||||
* using a boolean, the {@link #falseValues()} defines which indices are considered {@code false} or
|
||||
* {@code true}.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(ValuesHandler.Impl.class)
|
||||
public @interface Values {
|
||||
String[] value();
|
||||
|
||||
int[] falseValues() default {0};
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
@Handler.Implementation(ValuesReferenceHandler.Impl.class)
|
||||
@interface Reference {
|
||||
String value();
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.handler.ArrayLengthHandler;
|
||||
import de.steamwar.command.handler.UniqueHandler;
|
||||
import de.steamwar.command.utils.Triple;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractArrayNode<E> extends AbstractTypeNode<E> {
|
||||
|
||||
protected final boolean unique;
|
||||
protected final int minArrayLength;
|
||||
protected final int maxArrayLength;
|
||||
protected final String error;
|
||||
|
||||
protected AbstractArrayNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
super(parameter, index, dataReadable);
|
||||
|
||||
this.unique = UniqueHandler.isPresent(parameter);
|
||||
this.minArrayLength = ArrayLengthHandler.getMin(parameter);
|
||||
this.maxArrayLength = ArrayLengthHandler.getMax(parameter);
|
||||
this.error = ArrayLengthHandler.getError(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
|
||||
Object array = Array.newInstance(type, Math.min(nodeData.unparsedArgumentsSize(), maxArrayLength));
|
||||
|
||||
int i = 0;
|
||||
while (!nodeData.hasOneLeft()) {
|
||||
if (i >= minArrayLength) {
|
||||
for (Node<E> child : children) {
|
||||
child.tabComplete(executor, nodeData, completions);
|
||||
}
|
||||
}
|
||||
|
||||
nodeData.add(name, arrayCopy(array, i));
|
||||
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
|
||||
nodeData.remove();
|
||||
|
||||
if (!argument.b) {
|
||||
for (; i > 0; i--) nodeData.unconsume();
|
||||
return;
|
||||
}
|
||||
nodeData.consume();
|
||||
Array.set(array, i, argument.a);
|
||||
i++;
|
||||
}
|
||||
nodeData.add(name, arrayCopy(array, i));
|
||||
if (i < maxArrayLength) {
|
||||
PreviousArguments previousArguments = nodeData.toPreviousArguments();
|
||||
if (unique) {
|
||||
Map<Object, List<String>> mapped = new HashMap<>();
|
||||
for (String s : typeMapper.tabComplete(executor, previousArguments, nodeData.current())) {
|
||||
mapped.computeIfAbsent(typeMapper.map(executor, previousArguments, s), object -> new ArrayList<>())
|
||||
.add(s);
|
||||
}
|
||||
for (int j = 0; j < i; j++) {
|
||||
mapped.remove(Array.get(array, j));
|
||||
}
|
||||
mapped.forEach((object, strings) -> {
|
||||
completions.add(strings);
|
||||
});
|
||||
} else {
|
||||
completions.add(typeMapper.tabComplete(executor, previousArguments, nodeData.current()));
|
||||
}
|
||||
}
|
||||
if (i >= minArrayLength) {
|
||||
for (Node<E> child : children) {
|
||||
child.tabComplete(executor, nodeData, completions);
|
||||
}
|
||||
}
|
||||
nodeData.remove();
|
||||
for (; i > 0; i--) nodeData.unconsume();
|
||||
}
|
||||
|
||||
protected Object arrayCopy(Object array, int newLength) {
|
||||
Object newArray = Array.newInstance(type, newLength);
|
||||
System.arraycopy(array, 0, newArray, 0, Math.min(Array.getLength(array), newLength));
|
||||
return newArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nodeCost() {
|
||||
return minArrayLength * 2 + super.nodeCost();
|
||||
}
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.*;
|
||||
import de.steamwar.command.annotations.TabFilterType;
|
||||
import de.steamwar.command.handler.TabFilterHandler;
|
||||
import de.steamwar.command.mapper.EnumMapper;
|
||||
import de.steamwar.command.mapper.OptionEnumMapper;
|
||||
import de.steamwar.command.mapper.internal.ContainsFilter;
|
||||
import de.steamwar.command.mapper.internal.StartsWithFilter;
|
||||
import de.steamwar.command.utils.Pair;
|
||||
import de.steamwar.command.utils.Triple;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractTypeNode<E> extends AbstractValidationNode<E> {
|
||||
|
||||
protected Class<?> type;
|
||||
protected AbstractTypeMapper<E, Object> typeMapper;
|
||||
|
||||
protected AbstractTypeNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
super(parameter, index, dataReadable);
|
||||
|
||||
type = parameter.getType();
|
||||
if (type.isArray()) type = type.getComponentType();
|
||||
|
||||
initializeTypeMapper(handlerParameters, parameter, index, dataReadable);
|
||||
}
|
||||
|
||||
private AbstractTypeMapper<E, Object> getTypeMapper(Handler.DataReadable dataReadable) {
|
||||
AbstractTypeMapper<E, Object> typeMapper = dataReadable.getMapper(type.getTypeName());
|
||||
if (typeMapper == null && type.isEnum()) {
|
||||
if (OptionEnum.class.isAssignableFrom(type)) {
|
||||
typeMapper = (AbstractTypeMapper) new OptionEnumMapper((Class) type);
|
||||
} else {
|
||||
typeMapper = (AbstractTypeMapper) new EnumMapper((Class) type);
|
||||
}
|
||||
}
|
||||
return typeMapper;
|
||||
}
|
||||
|
||||
private void initializeTypeMapper(List<Pair<Annotation, Handler.HandlerParameter>> pairs, Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
AbstractTypeMapper<E, Object> typeMapper = getTypeMapper(dataReadable);
|
||||
boolean isStillDefault = true;
|
||||
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
|
||||
if (pair.b.needsParentTypeMapper()) {
|
||||
continue;
|
||||
}
|
||||
if (!isStillDefault) {
|
||||
throw new UnsupportedOperationException("Only one HandlerParameter can be used without a parent TypeMapper");
|
||||
}
|
||||
AbstractTypeMapper<E, Object> temp = pair.b.getTypeMapper(pair.a, parameter, index, dataReadable, null);
|
||||
if (temp != null) {
|
||||
typeMapper = temp;
|
||||
isStillDefault = false;
|
||||
}
|
||||
}
|
||||
|
||||
AbstractTypeMapper<E, Object> current = typeMapper;
|
||||
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
|
||||
if (!pair.b.needsParentTypeMapper()) {
|
||||
continue;
|
||||
}
|
||||
AbstractTypeMapper<E, Object> temp = pair.b.getTypeMapper(pair.a, parameter, index, dataReadable, typeMapper);
|
||||
if (temp != null) {
|
||||
typeMapper = temp;
|
||||
}
|
||||
}
|
||||
|
||||
current = TabCompletionCache.cached(current, typeMapper);
|
||||
|
||||
TabFilterType tabFilterType = TabFilterHandler.getTabFilterType(parameter);
|
||||
switch (tabFilterType) {
|
||||
case NONE:
|
||||
this.typeMapper = current;
|
||||
break;
|
||||
case STARTS_WITH:
|
||||
this.typeMapper = new StartsWithFilter<>(current);
|
||||
break;
|
||||
case CONTAINS:
|
||||
this.typeMapper = new ContainsFilter<>(current);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected Triple<Object, Boolean, Boolean> argument(E executor, NodeData nodeData) {
|
||||
Object value;
|
||||
boolean usedOptional;
|
||||
try {
|
||||
PreviousArguments previousArguments = nodeData.toPreviousArguments();
|
||||
value = typeMapper.map(executor, previousArguments, nodeData.current());
|
||||
usedOptional = previousArguments.hasUsedOptionalValue();
|
||||
} catch (Exception e) {
|
||||
return new Triple<>(null, false, false);
|
||||
}
|
||||
if (validate(executor, value, nodeData)) {
|
||||
return new Triple<>(value, true, usedOptional);
|
||||
} else {
|
||||
return new Triple<>(null, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean validate(E executor, Object value, NodeData nodeData) {
|
||||
for (AbstractTypeValidator<E, Object> validator : validators) {
|
||||
try {
|
||||
if (!validator.validate(executor, value, nodeData)) {
|
||||
return false;
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
// Ignore
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
if (!(children instanceof AbstractTypeNode)) {
|
||||
return false;
|
||||
}
|
||||
return super.equals(parameter, children);
|
||||
}
|
||||
}
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.AbstractTypeValidator;
|
||||
import de.steamwar.command.CommandUtils;
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.AllowNullHandler;
|
||||
import de.steamwar.command.utils.Pair;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractValidationNode<E> extends Node<E> {
|
||||
|
||||
private static final AbstractTypeValidator<?, ?> NON_NULL_VALIDATOR = (AbstractTypeValidator<Object, Object>) (sender, value, messageSender) -> value != null;
|
||||
|
||||
protected final List<Annotation> annotations;
|
||||
protected final List<Pair<Annotation, Handler.HandlerParameter>> handlerParameters;
|
||||
protected final List<AbstractTypeValidator<E, Object>> validators = new ArrayList<>();
|
||||
|
||||
protected AbstractValidationNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
super(parameter);
|
||||
annotations = CommandUtils.getAnnotations(parameter, Handler.HandlerParameter.class);
|
||||
List<Pair<Annotation, Handler.HandlerParameter>> pairs = new ArrayList<>();
|
||||
for (Annotation annotation : annotations) {
|
||||
Handler.Implementation implementation = annotation.annotationType().getAnnotation(Handler.Implementation.class);
|
||||
try {
|
||||
pairs.add(new Pair<>(annotation, (Handler.HandlerParameter) implementation.value().getConstructor().newInstance()));
|
||||
} catch (Exception e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
handlerParameters = pairs;
|
||||
|
||||
initializeValidators(handlerParameters, parameter, index, dataReadable);
|
||||
}
|
||||
|
||||
private void initializeValidators(List<Pair<Annotation, Handler.HandlerParameter>> pairs, Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
pairs.sort(Comparator.comparingInt(p -> p.b.getValidatorPriority()));
|
||||
for (Pair<Annotation, Handler.HandlerParameter> pair : pairs) {
|
||||
AbstractTypeValidator<E, Object> validator = pair.b.getValidator(pair.a, parameter, index, dataReadable);
|
||||
if (validator != null) {
|
||||
validators.add(validator);
|
||||
}
|
||||
}
|
||||
|
||||
if (!AllowNullHandler.isPresent(parameter)) {
|
||||
validators.add((AbstractTypeValidator<E, Object>) NON_NULL_VALIDATOR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
if (this.parameter.getType() != parameter.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Annotation[] annotations = this.parameter.getAnnotations();
|
||||
Annotation[] currentAnnotations = parameter.getAnnotations();
|
||||
|
||||
if (annotations.length == 0 && currentAnnotations.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (annotations.length != currentAnnotations.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<Class<?>, Annotation> annotationMap = new HashMap<>();
|
||||
boolean duplicate = false;
|
||||
for (Annotation annotation : annotations) {
|
||||
if (annotationMap.put(annotation.annotationType(), annotation) != null) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (duplicate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Annotation annotation : currentAnnotations) {
|
||||
Annotation other = annotationMap.get(annotation.annotationType());
|
||||
if (!annotation.equals(other)) {
|
||||
continue;
|
||||
}
|
||||
annotationMap.remove(annotation.annotationType());
|
||||
}
|
||||
return annotationMap.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.CommandFrameworkException;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExecuteNode<E> extends Node<E> {
|
||||
|
||||
private final Object self;
|
||||
private final Method method;
|
||||
|
||||
public ExecuteNode(Object self, Method method) {
|
||||
super(null);
|
||||
this.self = self;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(E executor, NodeData nodeData) {
|
||||
for (Node<E> child : children) {
|
||||
if (child.execute(executor, nodeData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nodeData.hasMore()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
method.invoke(self, nodeData.mapped());
|
||||
return true;
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new CommandFrameworkException(e, nodeData.alias(), nodeData.args());
|
||||
} catch (IllegalAccessException | RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
|
||||
for (Node<E> child : children) {
|
||||
child.tabComplete(executor, nodeData, completions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
if (children instanceof ExecuteNode) {
|
||||
String parameters = Arrays.stream(method.getParameters()).map(par -> {
|
||||
String annotations = Arrays.stream(par.getAnnotations())
|
||||
.map(annotation -> "@" + annotation.getClass().getSimpleName())
|
||||
.collect(Collectors.joining(" "));
|
||||
if (par.isVarArgs()) {
|
||||
return annotations + (annotations.isEmpty() ? "" : " ") + par.getType().componentType().getSimpleName() + "...";
|
||||
} else {
|
||||
return annotations + (annotations.isEmpty() ? "" : " ") + par.getType().getSimpleName();
|
||||
}
|
||||
}).collect(Collectors.joining(", "));
|
||||
throw new UnsupportedOperationException("Command with parameters " + parameters + " is already defined in " + self.getClass().getName());
|
||||
}
|
||||
return children instanceof ExecuteNode;
|
||||
}
|
||||
}
|
||||
-95
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.AbstractTypeValidator;
|
||||
import de.steamwar.command.Handler;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ExecutorTypeNode<E> extends AbstractValidationNode<E> {
|
||||
|
||||
protected final Function<E, ?> executorMapper;
|
||||
|
||||
public ExecutorTypeNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
super(parameter, index, dataReadable);
|
||||
this.executorMapper = (Function<E, ?>) dataReadable.getExecutorMapper(parameter.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(E executor, NodeData nodeData) {
|
||||
Object mappedExecutor = executorMapper.apply(executor);
|
||||
if (mappedExecutor == null) return false;
|
||||
for (AbstractTypeValidator<E, Object> validator : validators) {
|
||||
try {
|
||||
if (!validator.validate(executor, executor, nodeData)) {
|
||||
return false;
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
// Ignore
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
nodeData.add(name, mappedExecutor);
|
||||
for (Node<E> child : children) {
|
||||
if (child.execute(executor, nodeData)) return true;
|
||||
}
|
||||
nodeData.remove();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
|
||||
Object mappedExecutor = executorMapper.apply(executor);
|
||||
if (mappedExecutor == null) return;
|
||||
for (AbstractTypeValidator<E, Object> validator : validators) {
|
||||
try {
|
||||
if (!validator.validate(executor, executor, nodeData)) {
|
||||
return;
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
// Ignore
|
||||
} catch (Throwable e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
nodeData.add(name, mappedExecutor);
|
||||
for (Node<E> child : children) {
|
||||
child.tabComplete(executor, nodeData, completions);
|
||||
}
|
||||
nodeData.remove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
if (!(children instanceof ExecutorTypeNode)) {
|
||||
return false;
|
||||
}
|
||||
ExecutorTypeNode other = (ExecutorTypeNode) children;
|
||||
if (executorMapper != other.executorMapper) {
|
||||
return false;
|
||||
}
|
||||
return super.equals(parameter, children);
|
||||
}
|
||||
}
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import de.steamwar.command.Handler;
|
||||
import de.steamwar.command.handler.GreedyHandler;
|
||||
import de.steamwar.command.utils.Triple;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GreedyArrayNode<E> extends AbstractArrayNode<E> {
|
||||
|
||||
protected final int backTrackingDepth;
|
||||
|
||||
public GreedyArrayNode(Parameter parameter, int index, Handler.DataReadable dataReadable) {
|
||||
super(parameter, index, dataReadable);
|
||||
this.backTrackingDepth = GreedyHandler.getBackTrackingDepth(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(E executor, NodeData nodeData) {
|
||||
int min = Math.min(nodeData.unparsedArgumentsSize(), minArrayLength);
|
||||
int max = Math.min(nodeData.unparsedArgumentsSize(), maxArrayLength);
|
||||
if (max < minArrayLength) {
|
||||
nodeData.send(error, 0, minArrayLength);
|
||||
return false;
|
||||
}
|
||||
|
||||
Object array = Array.newInstance(type, max);
|
||||
Set<Object> seen = new HashSet<>();
|
||||
|
||||
int i = 0;
|
||||
for (; i < max; i++) {
|
||||
nodeData.add(name, arrayCopy(array, i));
|
||||
Triple<Object, Boolean, Boolean> argument = argument(executor, nodeData);
|
||||
nodeData.remove();
|
||||
|
||||
if (!argument.b || (unique && !seen.add(argument.a))) {
|
||||
if (i < minArrayLength) {
|
||||
nodeData.send(error, i, minArrayLength);
|
||||
for (; i > 0; i--) nodeData.unconsume();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Array.set(array, i, argument.a);
|
||||
nodeData.consume();
|
||||
}
|
||||
|
||||
int backTrackingDepth = i - this.backTrackingDepth;
|
||||
for (; i >= min; i--) {
|
||||
Object copiedArray = arrayCopy(array, i);
|
||||
nodeData.add(name, copiedArray);
|
||||
if (validate(executor, copiedArray, nodeData)) {
|
||||
for (Node<E> child : children) {
|
||||
if (child.execute(executor, nodeData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
nodeData.remove();
|
||||
if (i <= backTrackingDepth) {
|
||||
break;
|
||||
}
|
||||
if (i > 0) {
|
||||
nodeData.unconsume();
|
||||
}
|
||||
}
|
||||
if (i < minArrayLength) nodeData.send(error, i, minArrayLength);
|
||||
for (; i > 0; i--) nodeData.unconsume();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nodeCost() {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class LiteralNode<E> extends Node<E> {
|
||||
|
||||
protected final String literal;
|
||||
|
||||
public LiteralNode(String literal) {
|
||||
super(null);
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(E executor, NodeData nodeData) {
|
||||
if (!nodeData.hasMore()) return false;
|
||||
if (nodeData.current().equalsIgnoreCase(literal)) {
|
||||
nodeData.consume();
|
||||
for (Node<E> child : children) {
|
||||
if (child.execute(executor, nodeData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
nodeData.unconsume();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
|
||||
if (nodeData.hasOneLeft()) {
|
||||
if (literal.startsWith(nodeData.current())) {
|
||||
completions.add(List.of(literal));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (nodeData.current().equalsIgnoreCase(literal)) {
|
||||
nodeData.consume();
|
||||
for (Node<E> child : children) {
|
||||
child.tabComplete(executor, nodeData, completions);
|
||||
}
|
||||
nodeData.unconsume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
if (!(children instanceof LiteralNode)) {
|
||||
return false;
|
||||
}
|
||||
return literal.equalsIgnoreCase(((LiteralNode) children).literal);
|
||||
}
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.command.graph;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class NoTabCompleteNode<E> extends Node<E> {
|
||||
|
||||
public NoTabCompleteNode() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(E executor, NodeData nodeData) {
|
||||
for (Node<E> child : children) {
|
||||
if (child.execute(executor, nodeData)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tabComplete(E executor, NodeData nodeData, List<Collection<String>> completions) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Parameter parameter, Node<E> children) {
|
||||
return children instanceof NoTabCompleteNode;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user