From 8a7f9691b475bcdb5227aaae2c831bfdd8c44715 Mon Sep 17 00:00:00 2001 From: Aya <31237389+tal5@users.noreply.github.com> Date: Wed, 23 Oct 2024 09:00:15 +0100 Subject: [PATCH] Account for conflicting plugin names --- .../depenizen/bukkit/Depenizen.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java index 37ae8caea..2cbad52f8 100644 --- a/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java +++ b/src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java @@ -21,17 +21,19 @@ public class Depenizen extends JavaPlugin { public static Depenizen instance; - public HashMap> allBridges = new HashMap<>(); + public HashMap allBridges = new HashMap<>(); public HashMap loadedBridges = new HashMap<>(); + public record BridgeData(String classCheck, Supplier creator) {} + @Override public void onEnable() { Debug.log("Depenizen loading..."); saveDefaultConfig(); instance = this; registerCoreBridges(); - for (Map.Entry> bridge : allBridges.entrySet()) { + for (Map.Entry bridge : allBridges.entrySet()) { loadBridge(bridge.getKey(), bridge.getValue()); } try { @@ -70,14 +72,23 @@ public void checkLoadClientizenBridge() { } } - public void loadBridge(String name, Supplier bridgeSupplier) { + public void loadBridge(String name, BridgeData bridgeData) { Plugin plugin = Bukkit.getPluginManager().getPlugin(name); if (plugin == null) { return; } + if (bridgeData.classCheck != null) { + try { + Class.forName(bridgeData.classCheck); + } + catch (ClassNotFoundException e) { + Debug.log("Tried loading plugin bridge for '" + name + "', but could not match class '" + bridgeData.classCheck + "'."); + return; + } + } Bridge newBridge; try { - newBridge = bridgeSupplier.get(); + newBridge = bridgeData.creator.get(); } catch (Throwable ex) { Debug.echoError("Cannot load Depenizen bridge for '" + name + "': fundamental loading error:"); @@ -132,7 +143,7 @@ public void registerCoreBridges() { registerBridge("PlotSquared", () -> new PlotSquaredBridge()); registerBridge("PVPArena", () -> new PVPArenaBridge()); registerBridge("PVPStats", () -> new PVPStatsBridge()); - registerBridge("Quests", () -> new QuestsBridge()); + registerBridge("Quests", "me.pikamug.quests.Quests", () -> new QuestsBridge()); registerBridge("Residence", () -> new ResidenceBridge()); registerBridge("Sentinel", () -> new SentinelBridge()); registerBridge("Shopkeepers", () -> new ShopkeepersBridge()); @@ -149,6 +160,10 @@ public void registerCoreBridges() { } public void registerBridge(String name, Supplier bridgeSupplier) { - allBridges.put(name, bridgeSupplier); + registerBridge(name, null, bridgeSupplier); + } + + public void registerBridge(String name, String classCheck, Supplier bridgeSupplier) { + allBridges.put(name, new BridgeData(classCheck, bridgeSupplier)); } }