Browse Source

added hooks for each skyblock plugin

linus 6 years ago
parent
commit
e592375f72

+ 2 - 2
pom.xml

@@ -32,14 +32,14 @@
 		<dependency>
 			<groupId>org.spigotmc</groupId>
 			<artifactId>spigot-api</artifactId>
-			<version>1.13.1-R0.1-SNAPSHOT</version>
+			<version>1.12.2-R0.1-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
 		<!-- Bukkit API -->
 		<dependency>
 			<groupId>org.bukkit</groupId>
 			<artifactId>craftbukkit</artifactId>
-			<version>1.13.1-R0.1-SNAPSHOT</version>
+			<version>1.12.2-R0.1-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
 		<!-- ASkyBlock -->

+ 29 - 42
src/xyz/spaceio/customoregen/CustomOreGen.java

@@ -23,7 +23,10 @@ import org.bukkit.plugin.java.JavaPlugin;
 import com.google.gson.reflect.TypeToken;
 
 import de.Linus122.SpaceIOMetrics.Metrics;
-
+import xyz.spaceio.hooks.ASkyBlockHook;
+import xyz.spaceio.hooks.AcidIslandHook;
+import xyz.spaceio.hooks.SkyblockAPIHook;
+import xyz.spaceio.hooks.uSkyBlockHook;
 
 public class CustomOreGen extends JavaPlugin {
 	public static List<GeneratorConfig> generatorConfigs = new ArrayList<GeneratorConfig>();
@@ -36,10 +39,18 @@ public class CustomOreGen extends JavaPlugin {
 	
 	public static String activeInWorldName = "";
 	
+	private SkyblockAPIHook skyblockAPI;
+	
+	@Override
 	public void onEnable() {
 		clogger = getServer().getConsoleSender();
 		PluginManager pm = Bukkit.getPluginManager();
 		pm.registerEvents(new Events(), this);
+		
+		this.loadHook();
+		activeInWorldName = skyblockAPI.getSkyBlockWorldName();
+		
+		
 		Bukkit.getPluginCommand("customoregen").setExecutor(new Cmd(this));
 		try{
 			loadConfig();
@@ -52,21 +63,27 @@ public class CustomOreGen extends JavaPlugin {
 			cachedOregenConfigs = new HashMap<UUID, Integer>();
 		}
 		disabledWorlds = getConfig().getStringList("disabled-worlds");
+		
+		new Metrics(this);
+	}
+
+	/**
+	 * creates a new api hook instance for the used skyblock plugin
+	 */
+	private void loadHook() {
 		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")) {
-			activeInWorldName = com.wasteofplastic.askyblock.ASkyBlock.getIslandWorld().getName();
+			skyblockAPI = new ASkyBlockHook();
 			clogger.sendMessage("§6[CustomOreGen] §aUsing ASkyBlock as SkyBlock-Plugin");
 		}else if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")) {
-			activeInWorldName = com.wasteofplastic.acidisland.ASkyBlock.getIslandWorld().getName();
+			skyblockAPI = new AcidIslandHook();
 			clogger.sendMessage("§6[CustomOreGen] §aUsing AcidIsland as SkyBlock-Plugin");
 		}else if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
-			us.talabrek.ultimateskyblock.api.uSkyBlockAPI api = (us.talabrek.ultimateskyblock.api.uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("uSkyBlock");
-			api.getConfig().getString("options.general.worldName");
-			activeInWorldName = api.getConfig().getString("options.general.worldName");
+			skyblockAPI = new uSkyBlockHook();
 			clogger.sendMessage("§6[CustomOreGen] §aUsing uSkyBlock as SkyBlock-Plugin");
 		}
-		new Metrics(this);
 	}
-
+	
+	@Override
 	public void onDisable() {
 		cachedOregenJsonConfig.saveToDisk(cachedOregenConfigs);
 	}
@@ -75,42 +92,12 @@ public class CustomOreGen extends JavaPlugin {
 		return Bukkit.getWorld(activeInWorldName);
 	}
 
-	public static int getLevel(UUID uuid) {
-		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")) {
-			return com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().getIslandLevel(uuid);
-		}
-		if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")) {
-			return com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().getIslandLevel(uuid);
-		}
-		if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
-			if(Bukkit.getPlayer(uuid) != null){
-				Player p = Bukkit.getPlayer(uuid);
-				us.talabrek.ultimateskyblock.api.g
-				return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandLevel(p));
-			}
-			// Note: The API for getIslandInfo seems to be broken
-			return (int) Math.floor(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandInfo(us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getPlayerInfo(uuid)).getLevel());
-		}
-		return 0;
+	public int getLevel(UUID uuid) {
+		return skyblockAPI.getIslandLevel(uuid);
 	}
 	
-	public static OfflinePlayer getOwner(Location loc) {
-		Set<Location> set = new HashSet<Location>();
-		set.add(loc);
-
-		UUID uuid = null;
-		if(Bukkit.getServer().getPluginManager().isPluginEnabled("ASkyBlock")) {
-			uuid = com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance()
-					.getOwner(com.wasteofplastic.askyblock.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
-		}else if(Bukkit.getServer().getPluginManager().isPluginEnabled("AcidIsland")) {
-			uuid = com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance()
-					.getOwner(com.wasteofplastic.acidisland.ASkyBlockAPI.getInstance().locationIsOnIsland(set, loc));
-		}else if(Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
-			String player = us.talabrek.ultimateskyblock.uSkyBlock.getInstance().getIslandInfo(loc).getLeader();
-			if((Bukkit.getPlayer(player) != null) && (Bukkit.getPlayer(player).getUniqueId() != null)) {
-				uuid = Bukkit.getOfflinePlayer(player).getUniqueId();
-			}
-		}
+	public OfflinePlayer getOwner(Location loc) {
+		UUID uuid = skyblockAPI.getIslandOwner(loc);
 		if(uuid == null){
 			return null;
 		}

+ 32 - 0
src/xyz/spaceio/hooks/ASkyBlockHook.java

@@ -0,0 +1,32 @@
+package xyz.spaceio.hooks;
+
+import java.util.UUID;
+
+import org.bukkit.Location;
+
+import com.wasteofplastic.acidisland.ASkyBlockAPI;
+
+public class ASkyBlockHook implements SkyblockAPIHook{
+	
+	private ASkyBlockAPI api;
+	
+	public ASkyBlockHook() {
+		api = ASkyBlockAPI.getInstance();
+	}
+
+	@Override
+	public int getIslandLevel(UUID uuid) {
+		return api.getIslandLevel(uuid);
+	}
+
+	@Override
+	public UUID getIslandOwner(Location loc) {
+		return api.getIslandAt(loc).getOwner();
+	}
+
+	@Override
+	public String getSkyBlockWorldName() {
+		return api.getIslandWorld().getName();
+	}
+	
+}

+ 31 - 0
src/xyz/spaceio/hooks/AcidIslandHook.java

@@ -0,0 +1,31 @@
+package xyz.spaceio.hooks;
+
+import java.util.UUID;
+
+import org.bukkit.Location;
+
+import com.wasteofplastic.askyblock.ASkyBlockAPI;
+
+public class AcidIslandHook implements SkyblockAPIHook{
+	
+	private ASkyBlockAPI api;
+	
+	public AcidIslandHook() {
+		api = ASkyBlockAPI.getInstance();
+	}
+
+	@Override
+	public int getIslandLevel(UUID uuid) {
+		return api.getIslandLevel(uuid);
+	}
+
+	@Override
+	public UUID getIslandOwner(Location loc) {
+		return api.getIslandAt(loc).getOwner();
+	}
+	
+	@Override
+	public String getSkyBlockWorldName() {
+		return api.getIslandWorld().getName();
+	}
+}

+ 31 - 0
src/xyz/spaceio/hooks/SkyblockAPIHook.java

@@ -0,0 +1,31 @@
+package xyz.spaceio.hooks;
+
+import java.util.UUID;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+
+public interface SkyblockAPIHook {
+	/**
+	 * Returns the island level for a defined player uuid
+	 * 
+	 * @param uuid UUID of the island owner
+	 * @return island level
+	 */
+	public int getIslandLevel(UUID uuid);
+	
+	/**
+	 * Gets the owner of an island on a certain location
+	 * 
+	 * @param loc location to check for island
+	 * @return island owner UUID
+	 */
+	public UUID getIslandOwner(Location loc);
+	
+	/**
+	 * Obtains the name of the skyblock world
+	 * 
+	 * @return the name of the skyblock world
+	 */
+	public String getSkyBlockWorldName();
+}

+ 39 - 0
src/xyz/spaceio/hooks/uSkyBlockHook.java

@@ -0,0 +1,39 @@
+package xyz.spaceio.hooks;
+
+import java.util.UUID;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+
+import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
+
+public class uSkyBlockHook implements SkyblockAPIHook{
+	
+	private uSkyBlockAPI api;
+	
+	public uSkyBlockHook() {
+		api = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("uSkyBlock");
+	}
+
+	@Override
+	public int getIslandLevel(UUID uuid) {
+		return (int) Math.floor(api.getIslandLevel(Bukkit.getPlayer(uuid)));
+	}
+
+	@Override
+	public UUID getIslandOwner(Location loc) {
+		String player = api.getIslandInfo(loc).getLeader();
+		if ((Bukkit.getPlayer(player) != null) && (Bukkit.getPlayer(player).getUniqueId() != null)) {
+			return Bukkit.getOfflinePlayer(player).getUniqueId();
+		}else {
+			return null;
+		}
+	}
+
+	@Override
+	public String getSkyBlockWorldName() {
+		api.getConfig().getString("options.general.worldName");
+		return api.getConfig().getString("options.general.worldName");
+	}
+	
+}