Jelajahi Sumber

updated hook loading

MasterCake 5 tahun lalu
induk
melakukan
5b96437ba7
2 mengubah file dengan 24 tambahan dan 7 penghapusan
  1. 7 1
      pom.xml
  2. 17 6
      src/xyz/spaceio/customoregen/CustomOreGen.java

+ 7 - 1
pom.xml

@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>xyz.spaceio</groupId>
 	<artifactId>CustomOreGen</artifactId>
-	<version>1.3.21-SNAPSHOT</version>
+	<version>1.3.22-SNAPSHOT</version>
 	<repositories>
 		<!-- Spigot repository -->
 		<repository>
@@ -121,6 +121,12 @@
 			<artifactId>PlotSquared-API</artifactId>
 			<version>4.369-SNAPSHOT</version>
 		</dependency>
+		<!-- PlotSquared Legacy -->
+		<dependency>
+			<groupId>com.plotsquared</groupId>
+			<artifactId>plotsquared-api</artifactId>
+			<version>18.12.21-SNAPSHOT</version>
+		</dependency>
 		<!-- Lands -->
 		<dependency>
 			<groupId>me.angeschossen.lands</groupId>

+ 17 - 6
src/xyz/spaceio/customoregen/CustomOreGen.java

@@ -124,17 +124,28 @@ public class CustomOreGen extends JavaPlugin {
 	 * Acquires the corresponding skyblock hook class
 	 */
 	private void loadHook() {
-		Exception loadException = null;
+		skyblockAPI = getHook(); 
+		skyblockAPICached = new SkyblockAPICached(skyblockAPI);
+	}
+	
+	public SkyblockAPIHook getHook() {
+		NoClassDefFoundError loadException = null;
+		SkyblockAPIHook skyblockAPI = null;
+		
 		for(HookInfo hookInfo : HookInfo.values()) {
 			String pluginName = hookInfo.name().replace("Legacy", "");
 			if(Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName)) {
 				try {
-					skyblockAPI = (SkyblockAPIHook) hookInfo.getHookClass().newInstance();
+					try {
+						skyblockAPI = (SkyblockAPIHook) hookInfo.getHookClass().newInstance();
+					}catch(NoClassDefFoundError e) {
+						loadException = e;
+						continue;
+					}
 					sendConsole(String.format("&aUsing %s as SkyBlock-Plugin, hook class: %s", pluginName, hookInfo.getHookClass().getName()));
 					break;
-				} catch (Exception e) {
-					// TODO Auto-generated catch block
-					loadException = e;
+				} catch (InstantiationException | IllegalAccessException e) {
+					e.printStackTrace();
 				}
 			}
 		}
@@ -146,7 +157,7 @@ public class CustomOreGen extends JavaPlugin {
 			skyblockAPI = new HookVanilla();
 		}
 		
-		skyblockAPICached = new SkyblockAPICached(skyblockAPI);
+		return skyblockAPI;
 	}
 
 	/**