From 6ed239a176d314fb1e332292ebc63938616de184 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Thu, 29 Nov 2018 15:53:34 +0100 Subject: [PATCH] Use compile scope for implementations --- library/pom.xml | 2 -- .../worldguardwrapper/WorldGuardWrapper.java | 25 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/library/pom.xml b/library/pom.xml index 7062e6b..b845425 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -24,13 +24,11 @@ ${project.groupId} worldguardwrapper-implementation-v6 1.1.1-SNAPSHOT - runtime ${project.groupId} worldguardwrapper-implementation-v7 1.1.1-SNAPSHOT - runtime diff --git a/library/src/main/java/org/codemc/worldguardwrapper/WorldGuardWrapper.java b/library/src/main/java/org/codemc/worldguardwrapper/WorldGuardWrapper.java index 42fe80d..da8ebf0 100644 --- a/library/src/main/java/org/codemc/worldguardwrapper/WorldGuardWrapper.java +++ b/library/src/main/java/org/codemc/worldguardwrapper/WorldGuardWrapper.java @@ -23,24 +23,23 @@ public class WorldGuardWrapper implements IWorldGuardImplementation { } @Delegate - private IWorldGuardImplementation delegate; - private Listener eventListener; + private IWorldGuardImplementation implementation; + private Listener listener; private WorldGuardWrapper() { - String version; + boolean legacy; try { Class.forName("com.sk89q.worldguard.WorldGuard"); - version = "v7"; + legacy = false; } catch (ClassNotFoundException e) { - version = "v6"; + legacy = true; } - try { - delegate = (IWorldGuardImplementation) Class.forName("org.codemc.worldguardwrapper.implementation." - + version + ".WorldGuardImplementation").newInstance(); - eventListener = (Listener) Class.forName("new org.codemc.worldguardwrapper.implementation." - + version + ".event.EventListener").newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - throw new RuntimeException("Unable to initialize WorldGuard implementation " + version, e); + if (legacy) { + implementation = new org.codemc.worldguardwrapper.implementation.v6.WorldGuardImplementation(); + listener = new org.codemc.worldguardwrapper.implementation.v6.event.EventListener(); + } else { + implementation = new org.codemc.worldguardwrapper.implementation.v7.WorldGuardImplementation(); + listener = new org.codemc.worldguardwrapper.implementation.v7.event.EventListener(); } } @@ -51,7 +50,7 @@ public class WorldGuardWrapper implements IWorldGuardImplementation { * @param plugin the plugin instance */ public void registerEvents(JavaPlugin plugin) { - Bukkit.getPluginManager().registerEvents(eventListener, plugin); + Bukkit.getPluginManager().registerEvents(listener, plugin); } }