Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for conflicting plugin names #436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/main/java/com/denizenscript/depenizen/bukkit/Depenizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ public class Depenizen extends JavaPlugin {

public static Depenizen instance;

public HashMap<String, Supplier<Bridge>> allBridges = new HashMap<>();
public HashMap<String, BridgeData> allBridges = new HashMap<>();

public HashMap<String, Bridge> loadedBridges = new HashMap<>();

public record BridgeData(String classCheck, Supplier<Bridge> creator) {}

@Override
public void onEnable() {
Debug.log("Depenizen loading...");
saveDefaultConfig();
instance = this;
registerCoreBridges();
for (Map.Entry<String, Supplier<Bridge>> bridge : allBridges.entrySet()) {
for (Map.Entry<String, BridgeData> bridge : allBridges.entrySet()) {
loadBridge(bridge.getKey(), bridge.getValue());
}
try {
Expand Down Expand Up @@ -70,14 +72,23 @@ public void checkLoadClientizenBridge() {
}
}

public void loadBridge(String name, Supplier<Bridge> 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:");
Expand Down Expand Up @@ -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());
Expand All @@ -149,6 +160,10 @@ public void registerCoreBridges() {
}

public void registerBridge(String name, Supplier<Bridge> bridgeSupplier) {
allBridges.put(name, bridgeSupplier);
registerBridge(name, null, bridgeSupplier);
}

public void registerBridge(String name, String classCheck, Supplier<Bridge> bridgeSupplier) {
allBridges.put(name, new BridgeData(classCheck, bridgeSupplier));
}
}