Explorar el Código

Added support for another skyblock plugin + implemented PAPI

- Added support for the SuperiorSkyblock2 plugin
- Added placeholders representing the current generator settings of a
player:
%oregen_generator.label% (Name of the generator, set in config)
%oregen_generator.level% (Level of the generator)
%oregen_generator.permission% (Permission of the generator)
- Added the config.yml entry "label" for each generator for placeholders
- Fixed NPE in BentoBox hook
mastercake10 hace 5 años
padre
commit
35b6acaeae

+ 19 - 1
pom.xml

@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>xyz.spaceio</groupId>
 	<artifactId>CustomOreGen</artifactId>
-	<version>1.3.11-SNAPSHOT</version>
+	<version>1.3.12-SNAPSHOT</version>
 	<repositories>
 		<!-- Spigot repository -->
 		<repository>
@@ -31,6 +31,11 @@
 			<id>codemc-repo</id>
 			<url>https://repo.codemc.org/repository/maven-public/</url>
 		</repository>
+		<!-- Placeholder repository -->
+        <repository>
+            <id>placeholderapi</id>
+            <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
+        </repository>
 		<!-- SpaceIO repository -->
 		<repository>
 			<id>spaceio-snapshots</id>
@@ -98,6 +103,13 @@
 			<version>59-SNAPSHOT</version>
 			<scope>provided</scope>
 		</dependency>
+		<!-- SuperiorSkyblock -->
+		<dependency>
+			<groupId>com.bgsoftware</groupId>
+			<artifactId>SuperiorSkyblock</artifactId>
+			<version>0.0.7-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
 		<!-- PlotSquared -->
 		<dependency>
 			<groupId>com.plotsquared</groupId>
@@ -110,6 +122,12 @@
 			<artifactId>Lands</artifactId>
 			<version>2.6.6.2-SNAPSHOT</version>
 		</dependency>
+		<!-- Placeholder API -->
+		<dependency>
+			<groupId>me.clip</groupId>
+			<artifactId>placeholderapi</artifactId>
+			<version>2.0.6</version>
+        </dependency>
 		<!--SpaceIO Metrics -->
 		<dependency>
 			<groupId>de.spaceio</groupId>

+ 3 - 0
src/main/resources/config.yml

@@ -11,6 +11,8 @@
 generators:
   generator1:
     # default generator
+    # name of the generator (does not need to be set, just for placeholders)
+    label: "beginner"
     blocks:
     # Please use Bukkit-Blocknames. List: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
     - STONE:50.0
@@ -22,6 +24,7 @@ generators:
     unlock_islandLevel: 0
   generator2:
     # vip generator, VIPS need generators.vip permission
+    label: "VIP"
     blocks:
     - IRON_ORE:90.0
     - STONE:5.0

+ 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, BentoBox, IslandWorld]
+softdepend: [PlaceholderAPI, ASkyBlock, AcidIsland, uSkyBlock, SkyBlock, BentoBox, IslandWorld, SuperiorSkyblock2]
 main: xyz.spaceio.customoregen.CustomOreGen
 api-version: 1.13
 commands:

+ 1 - 0
src/xyz/spaceio/config/ConfigHandler.java

@@ -65,6 +65,7 @@ public class ConfigHandler {
 						"&cConfig error: generator %s has both a permission and level setup! Be sure to choose one of them!",
 						key));
 			}
+			gc.label = plugin.getConfig().getString("generators." + key + ".label", key);
 
 			for (String raw : plugin.getConfig().getStringList("generators." + key + ".blocks")) {
 				try {

+ 11 - 2
src/xyz/spaceio/customoregen/CustomOreGen.java

@@ -35,7 +35,9 @@ import xyz.spaceio.hooks.HookBentoBox;
 import xyz.spaceio.hooks.HookIslandWorld;
 import xyz.spaceio.hooks.HookPlotSquared;
 import xyz.spaceio.hooks.HookSkyblockEarth;
+import xyz.spaceio.hooks.HookSuperiorSkyblock;
 import xyz.spaceio.hooks.SkyblockAPIHook;
+import xyz.spaceio.misc.NamePlaceholder;
 import xyz.spaceio.hooks.HookuSkyBlock;
 
 public class CustomOreGen extends JavaPlugin {
@@ -110,7 +112,11 @@ public class CustomOreGen extends JavaPlugin {
 			cachedOregenConfigs = new HashMap<UUID, Integer>();
 		}
 		disabledWorlds = getConfig().getStringList("disabled-worlds");
-
+		
+        if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
+        	new NamePlaceholder(this, "oregen").hook();
+        }
+		
 		new Metrics(this);
 	}
 
@@ -139,8 +145,11 @@ public class CustomOreGen extends JavaPlugin {
 		} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("IslandWorld")) {
 			skyblockAPI = new HookIslandWorld();
 			sendConsole("&aUsing IslandWorld as SkyBlock-Plugin");
+		}else if (Bukkit.getServer().getPluginManager().isPluginEnabled("SuperiorSkyblock2")) {
+			skyblockAPI = new HookSuperiorSkyblock();
+			sendConsole("&aUsing SuperiorSkyblock2 as SkyBlock-Plugin");
 		} else {
-			sendConsole("§cYou are not using any Skyblock plugin! This plugin only works in addition with a Skyblock plugin of your choice!");
+			sendConsole("§cYou are not using any skyblock plugin! This plugin only works with a listed skyblock plugin! (check documentations)");
 			Bukkit.getPluginManager().disablePlugin(this);
 		}
 	}

+ 1 - 0
src/xyz/spaceio/customoregen/GeneratorConfig.java

@@ -6,5 +6,6 @@ import java.util.List;
 public class GeneratorConfig {
     public List<GeneratorItem> itemList = new ArrayList<GeneratorItem>();
     public String permission = ";";
+    public String label;
     public int unlock_islandLevel = 0;
 }

+ 2 - 2
src/xyz/spaceio/hooks/HookBentoBox.java

@@ -45,8 +45,8 @@ public class HookBentoBox implements SkyblockAPIHook{
 		Optional<Island> optIsland = api.getIslands().getIslandAt(loc);
 		Optional<UUID> optional = Optional.empty();
 		
-		if(optIsland.isPresent()) {
-			optional = Optional.of(api.getIslands().getIslandAt(loc).get().getOwner());
+		if(optIsland.isPresent() && optIsland.get().getOwner() != null) {
+			optional = Optional.of(optIsland.get().getOwner());
 		}
 		return optional;
 	}

+ 42 - 0
src/xyz/spaceio/hooks/HookSuperiorSkyblock.java

@@ -0,0 +1,42 @@
+package xyz.spaceio.hooks;
+
+import java.util.Optional;
+import java.util.UUID;
+
+import org.bukkit.Location;
+
+import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
+
+
+public class HookSuperiorSkyblock implements SkyblockAPIHook {
+
+
+	public HookSuperiorSkyblock() {
+
+	}
+
+	@Override
+	public int getIslandLevel(UUID uuid, String world) {
+		if(SuperiorSkyblockAPI.getPlayer(uuid) == null || SuperiorSkyblockAPI.getPlayer(uuid).getIsland() == null) {
+			return 0;
+		}else {
+			return 	SuperiorSkyblockAPI.getPlayer(uuid).getIsland().getIslandLevel();
+		}
+	}
+
+	@Override
+	public Optional<UUID> getIslandOwner(Location loc) {
+		if(SuperiorSkyblockAPI.getIslandAt(loc) != null) {
+			return Optional.of(SuperiorSkyblockAPI.getIslandAt(loc).getOwner().getUniqueId());
+		}else {
+			return Optional.empty();
+		}
+	}
+
+	@Override
+	public String[] getSkyBlockWorldNames() {
+		// took from source code of SkyBlock.jar
+		return new String[] {SuperiorSkyblockAPI.getSuperiorSkyblock().getGrid().getSpawnIsland().getCenter().getWorld().getName()};
+	}
+
+}

+ 46 - 0
src/xyz/spaceio/misc/NamePlaceholder.java

@@ -0,0 +1,46 @@
+package xyz.spaceio.misc;
+
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+import me.clip.placeholderapi.external.EZPlaceholderHook;
+import xyz.spaceio.customoregen.CustomOreGen;
+import xyz.spaceio.customoregen.GeneratorConfig;
+
+public class NamePlaceholder extends EZPlaceholderHook {
+	CustomOreGen cog;
+	
+	public NamePlaceholder(Plugin plugin, String placeholderName) {
+		super(plugin, placeholderName);
+		
+		this.cog = (CustomOreGen) plugin;
+	}
+
+	@Override
+	public String onPlaceholderRequest(Player player, String label) {
+		if(!label.startsWith("generator.")) {
+			return null;
+		}
+		
+		GeneratorConfig gc = cog.getCachedGeneratorConfig(player.getUniqueId());
+		if(gc == null) {
+			gc = cog.getGeneratorConfigs().get(0);
+		}
+		
+		switch(label.split("\\.")[1]) {
+			case "label":
+				return gc.label;
+			
+			case "name":
+				return gc.label;
+			
+			case "level":
+				return String.valueOf(gc.unlock_islandLevel);
+				
+			case "permission":
+				return gc.permission;
+		}
+		return null;
+	}
+
+}