From e1b13663068dcdba5e7ae9bb4aa839001a80b9e4 Mon Sep 17 00:00:00 2001 From: D4rkr34lm Date: Thu, 6 Nov 2025 16:57:20 +0100 Subject: [PATCH] Fixed build errors after merge --- .../src/de/steamwar/bausystem/BauSystem.java | 31 +++++------ .../simulator/SimulatorCursorManager.java | 49 +++++++++-------- .../simulator/display/ASimulatorCursor.java | 54 +++++++++++++++++++ .../display/EmptySimulatorCursor.java | 42 ++------------- .../simulator/display/SimulatorCursor.java | 36 +------------ .../display/SimulatorCursorMode.java | 16 +++--- .../gui/SimulatorCursorSwitcherGui.java | 37 +++++++------ .../features/simulator/gui/SimulatorGui.java | 8 ++- .../de/steamwar/linkage/AbstractLinker.java | 47 ++++++++-------- 9 files changed, 159 insertions(+), 161 deletions(-) create mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/ASimulatorCursor.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index a854f082..6e3fcc28 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -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 . + * You should have received a copy of the GNU Affero General Public License along with this program. + * If not, see . */ package de.steamwar.bausystem; @@ -71,6 +69,7 @@ public class BauSystem extends JavaPlugin implements Listener { @Getter private static BauSystem instance; + @Getter private SpigotLinker linker; @Override @@ -183,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(); @@ -201,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(); @@ -217,4 +218,4 @@ public class BauSystem extends JavaPlugin implements Listener { AtomicReference task = new AtomicReference<>(); task.set(runTaskTimer(plugin, () -> consumer.accept(task.get()), delay, period)); } -} \ No newline at end of file +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursorManager.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursorManager.java index a8a0d45c..82ad4080 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursorManager.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursorManager.java @@ -19,13 +19,11 @@ 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.bausystem.utils.cursor.Cursor; - import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; @@ -42,18 +40,13 @@ import java.util.*; @Linked @MinVersion(19) public class SimulatorCursorManager implements Listener { + public static final SimulatorCursorManager INSTANCE = new SimulatorCursorManager(); - private final Map> activeCursorsByPlayerBySimulator = new HashMap<>(); + private final Map> openCursorsByPlayerBySimulator = new HashMap<>(); + private final Map activeCursorByPlayer = new HashMap<>(); @EventHandler public void onPlayerItemEquip(PlayerItemHeldEvent event) { - ItemStack oldItem = event.getPlayer().getInventory().getItem(event.getPreviousSlot()); - - if (SimulatorUtils.isSimulatorItem(oldItem)) { - Simulator simulator = SimulatorStorage.getSimulator(oldItem); - hideCursor(event.getPlayer(), simulator); - } - ItemStack newItem = event.getPlayer().getInventory().getItem(event.getNewSlot()); if (SimulatorUtils.isSimulatorItem(newItem)) { Simulator simulator = SimulatorStorage.getSimulator(newItem); @@ -66,15 +59,22 @@ public class SimulatorCursorManager implements Listener { * simulator is null. */ public void showCursor(Player player, Simulator simulator) { - var cursorsBySimulator = activeCursorsByPlayerBySimulator.computeIfAbsent(player, __ -> new HashMap<>()); + 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) { - Cursor emptyCursor = new EmptySimulatorCursor(player); + ASimulatorCursor emptyCursor = new EmptySimulatorCursor(player, cursorMode); cursorsBySimulator.put(simulator, emptyCursor); cursor = emptyCursor; } else { - Cursor newCursor = new SimulatorCursor(simulator, player, SimulatorCursorMode.TNT); + ASimulatorCursor newCursor = new SimulatorCursor(simulator, player, cursorMode); cursorsBySimulator.put(simulator, newCursor); cursor = newCursor; } @@ -83,16 +83,19 @@ public class SimulatorCursorManager implements Listener { cursor.show(); } - public void hideCursor(Player player, Simulator simulator) { - var cursorsBySimulator = activeCursorsByPlayerBySimulator.get(player); - if (cursorsBySimulator == null) { - return; - } - - var cursor = cursorsBySimulator.remove(simulator); - if (cursor != null) { - cursor.hide(); + public Optional 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); + } + } } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/ASimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/ASimulatorCursor.java new file mode 100644 index 00000000..e70f8ec3 --- /dev/null +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/ASimulatorCursor.java @@ -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(); + } +} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/EmptySimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/EmptySimulatorCursor.java index bd2d2fc2..f72cdd0e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/EmptySimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/EmptySimulatorCursor.java @@ -1,56 +1,20 @@ package de.steamwar.bausystem.features.simulator.display; -import java.util.List; import java.util.Optional; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerToggleSneakEvent; 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.bausystem.utils.cursor.Cursor; import de.steamwar.entity.REntityServer; import de.steamwar.inventory.SWAnvilInv; -public class EmptySimulatorCursor extends Cursor implements Listener { - private final Player owner; - - private SimulatorCursorMode cursorMode; - - public EmptySimulatorCursor(Player owner) { - super(new REntityServer(), owner, Material.GLASS, Material.TNT, List.of(Cursor.CursorMode.FREE, Cursor.CursorMode.BLOCK_ALIGNED)); - this.cursorMode = SimulatorCursorMode.TNT; - this.owner = owner; - } - - public void swapCursorMode() { - cursorMode = cursorMode.switchType(); - 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(); +public class EmptySimulatorCursor extends ASimulatorCursor { + public EmptySimulatorCursor(Player owner, SimulatorCursorMode cursorMode) { + super(owner, new REntityServer(), cursorMode); } @Override diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursor.java index 68bb0572..7d695baf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursor.java @@ -3,11 +3,8 @@ package de.steamwar.bausystem.features.simulator.display; import java.util.List; import java.util.Optional; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; -import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.util.Vector; import de.steamwar.bausystem.features.simulator.data.Simulator; import de.steamwar.bausystem.features.simulator.data.SimulatorElement; @@ -16,45 +13,16 @@ 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.cursor.Cursor; -public class SimulatorCursor extends Cursor { +public class SimulatorCursor extends ASimulatorCursor { private final Simulator simulator; - private final Player owner; - - private SimulatorCursorMode cursorMode; public SimulatorCursor(Simulator simulator, Player owner, SimulatorCursorMode cursorMode) { - super(SimulatorRenderer.renderSimulator(simulator), owner, Material.LIME_STAINED_GLASS_PANE, Material.RED_STAINED_GLASS_PANE, - cursorMode.getAllowedCursorModes()); + super(owner, SimulatorRenderer.renderSimulator(simulator), cursorMode); this.simulator = simulator; - this.owner = owner; } - public void swapCursorMode() { - SimulatorCursorMode newMode = cursorMode.switchType(); - setCursorMaterial(newMode.getMaterial()); - setAllowedCursorModes(newMode.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(); - } @Override public void onClick(Optional clickedLocation, boolean clickedOnEntity, Action clickAction) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursorMode.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursorMode.java index ff55e8f8..fba95cf5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursorMode.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/display/SimulatorCursorMode.java @@ -18,14 +18,16 @@ import lombok.Getter; @AllArgsConstructor @Getter public enum SimulatorCursorMode { - TNT(Material.TNT, "TNT", vector -> new TNTElement(vector).add(new TNTPhase()), List.of(CursorMode.FREE, CursorMode.BLOCK_ALIGNED)), REDSTONE_BLOCK( - Material.REDSTONE_BLOCK, "Redstone Block", vector -> new RedstoneElement(vector).add(new RedstonePhase()), List.of(CursorMode.BLOCK_ALIGNED)), OBSERVER( - Material.OBSERVER, "Observer", vector -> new ObserverElement(vector).add(new ObserverPhase()), List.of(CursorMode.BLOCK_ALIGNED)); + 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)),; - private Material material; - private String name; - private Function> elementFunction; - private List allowedCursorModes; + public final Material material; + public final Material nonSelectedMaterial; + public final String name; + public final Function> elementFunction; + public final List allowedCursorModes; public SimulatorCursorMode switchType() { if (this == TNT) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorCursorSwitcherGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorCursorSwitcherGui.java index 0344014e..11474afe 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorCursorSwitcherGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorCursorSwitcherGui.java @@ -1,26 +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 . + * You should have received a copy of the GNU Affero General Public License along with this program. + * If not, see . */ package de.steamwar.bausystem.features.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; @@ -30,6 +30,7 @@ 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 +51,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); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java index eb99e964..af20023e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/gui/SimulatorGui.java @@ -17,9 +17,13 @@ package de.steamwar.bausystem.features.simulator.gui; +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; @@ -29,6 +33,8 @@ import org.bukkit.entity.Player; public class SimulatorGui extends SimulatorPageGui { + private final SimulatorCursorManager cursorManager = BauSystem.getInstance().getLinker().get(SimulatorCursorManager.class).orElseThrow(); + public SimulatorGui(Player player, Simulator simulator) { super(player, simulator, 6 * 9, simulator.getGroups()); } @@ -48,7 +54,7 @@ public class SimulatorGui extends SimulatorPageGui { 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(); })); diff --git a/CommonCore/Linkage/src/de/steamwar/linkage/AbstractLinker.java b/CommonCore/Linkage/src/de/steamwar/linkage/AbstractLinker.java index cf88d488..dcd92115 100644 --- a/CommonCore/Linkage/src/de/steamwar/linkage/AbstractLinker.java +++ b/CommonCore/Linkage/src/de/steamwar/linkage/AbstractLinker.java @@ -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 . + * You should have received a copy of the GNU Affero General Public License along with this program. + * If not, see . */ package de.steamwar.linkage; @@ -32,6 +30,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.stream.Collectors; public abstract class AbstractLinker { @@ -52,16 +51,13 @@ public abstract class AbstractLinker { List> classes; try { classes = new BufferedReader(new InputStreamReader(plugin.getClass().getResourceAsStream("/META-INF/annotations/de.steamwar.linkage.Linked"))) - .lines() - .map(s -> { + .lines().map(s -> { try { return Class.forName(s, false, plugin.getClass().getClassLoader()); } catch (ClassNotFoundException | NoClassDefFoundError e) { throw new SecurityException(e.getMessage(), e); } - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + }).filter(Objects::nonNull).collect(Collectors.toList()); } catch (SecurityException e) { Throwable cause = e.getCause(); throw new LinkException(cause.getMessage(), cause); @@ -71,12 +67,15 @@ public abstract class AbstractLinker { classes.forEach(clazz -> { MinVersion minVersion = clazz.getAnnotation(MinVersion.class); MaxVersion maxVersion = clazz.getAnnotation(MaxVersion.class); - if (!versionCheck(clazz, minVersion, maxVersion)) return; + if (!versionCheck(clazz, minVersion, maxVersion)) + return; EventMode eventMode = clazz.getAnnotation(EventMode.class); - if (!eventModeCheck(clazz, eventMode)) return; + if (!eventModeCheck(clazz, eventMode)) + return; PluginCheck[] pluginChecks = clazz.getAnnotationsByType(PluginCheck.class); for (PluginCheck pluginCheck : pluginChecks) { - if (!pluginCheck(clazz, pluginCheck)) return; + if (!pluginCheck(clazz, pluginCheck)) + return; } Object any; @@ -157,12 +156,14 @@ public abstract class AbstractLinker { /** * There is no need in calling {@link Enable#enable()} by this method. */ - protected void linkObject(Object any) { - } + protected void linkObject(Object any) {} /** * There is no need in calling {@link Disable#disable()} ()} by this method. */ - protected void unlinkObject(Object any) { + protected void unlinkObject(Object any) {} + + public final Optional get(Class clazz) { + return Optional.ofNullable((L) instances.get(clazz)); } }