Pārlūkot izejas kodu

added hook for bentobox

mastercake10 6 gadi atpakaļ
vecāks
revīzija
302d8018be
3 mainītis faili ar 28 papildinājumiem un 10 dzēšanām
  1. 10 3
      pom.xml
  2. 1 1
      src/main/resources/plugin.yml
  3. 17 6
      src/xyz/spaceio/hooks/HookBentoBox.java

+ 10 - 3
pom.xml

@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>xyz.spaceio</groupId>
 	<artifactId>CustomOreGen</artifactId>
-	<version>1.3.0-SNAPSHOT</version>
+	<version>1.3.1-SNAPSHOT</version>
 	<repositories>
 		<!-- Spigot repository -->
 		<repository>
@@ -74,10 +74,17 @@
 		<dependency>
 			<groupId>world.bentobox</groupId>
 			<artifactId>bentobox</artifactId>
-			<version>0.9.0-SNAPSHOT</version>
+			<version>0.15.0-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
-		<!-- BentoBox -->
+		<!-- BentoBox LevelAddon -->
+		<dependency>
+			<groupId>world.bentobox</groupId>
+			<artifactId>Level</artifactId>
+			<version>0.1.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+		<!-- SkyBlockEarth -->
 		<dependency>
 			<groupId>me.goodandevil</groupId>
 			<artifactId>skyblockearth</artifactId>

+ 1 - 1
src/main/resources/plugin.yml

@@ -2,7 +2,7 @@ name: CustomOreGen
 version: ${project.version}
 description: Controls the Ore-Generator
 author: Linus122
-softdepend: [ASkyBlock, AcidIsland, uSkyBlock, SkyBlock]
+softdepend: [ASkyBlock, AcidIsland, uSkyBlock, SkyBlock, BentoBox, IslandWorld]
 main: xyz.spaceio.customoregen.CustomOreGen
 api-version: 1.13
 commands:

+ 17 - 6
src/xyz/spaceio/hooks/HookBentoBox.java

@@ -1,11 +1,13 @@
 package xyz.spaceio.hooks;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.UUID;
 
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
+import org.bukkit.World;
 
-import bentobox.addon.level.Level;
 import world.bentobox.bentobox.BentoBox;
 
 public class HookBentoBox implements SkyblockAPIHook{
@@ -13,15 +15,24 @@ public class HookBentoBox implements SkyblockAPIHook{
 	private BentoBox api;
 	
 	public HookBentoBox() {
-		api = BentoBox.getInstance();
+		api = (BentoBox) Bukkit.getPluginManager().getPlugin("BentoBox");
 	}
 
 	@Override
 	public int getIslandLevel(UUID uuid, String onWorld) {
-		int level[] = {0};
+		int level[] = new int[]{0};
+		
+		// TODO: Access the API instead of using reflection
+		
 		api.getAddonsManager().getAddonByName("Level").ifPresent(addon -> {
-		    Level levelAddon = (Level) addon;
-		    level[0] = Math.toIntExact(levelAddon.getIslandLevel(Bukkit.getWorld(onWorld), uuid));
+			try {
+				Method method = addon.getClass().getMethod("getIslandLevel", World.class, UUID.class);
+				long rawLevel = (long) method.invoke(addon, Bukkit.getWorld(onWorld), uuid);
+				level[0] = Math.toIntExact(rawLevel);
+			} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
 		});
 		return level[0];
 	}
@@ -33,7 +44,7 @@ public class HookBentoBox implements SkyblockAPIHook{
 
 	@Override
 	public String[] getSkyBlockWorldNames() {
-		return api.getIWM().getOverWorldNames().stream().toArray(String[]::new);
+		return api.getIWM().getOverWorlds().stream().map(w -> w.getName()).toArray(String[]::new);
 	}
 	
 }