Parcourir la source

changed hook classes

linus il y a 6 ans
Parent
commit
11d9135c3b

+ 13 - 1
pom.xml

@@ -26,7 +26,12 @@
 				<updatePolicy>always</updatePolicy>
 			</snapshots>
 		</repository>
-		<!-- SpaceIO Repository -->
+		<!-- CodeMC repository -->
+		<repository>
+			<id>codemc-repo</id>
+			<url>https://repo.codemc.org/repository/maven-public/</url>
+		</repository>
+		<!-- SpaceIO repository -->
 		<repository>
 			<id>spaceio-snapshots</id>
 			<url>https://hub.spaceio.xyz/repository/maven-snapshots/</url>
@@ -65,6 +70,13 @@
 			<artifactId>uSkyBlock-API</artifactId>
 			<version>2.6.4</version>
 		</dependency>
+		<!-- BentoBox -->
+		<dependency>
+			<groupId>world.bentobox</groupId>
+			<artifactId>bentobox</artifactId>
+			<version>0.9.0-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
 		<!--SpaceIO Metrics -->
 		<dependency>
 			<groupId>de.spaceio</groupId>

+ 15 - 8
src/xyz/spaceio/customoregen/CustomOreGen.java

@@ -5,11 +5,14 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
+
 import org.bukkit.Bukkit;
 import org.bukkit.Location;
 import org.bukkit.Material;
@@ -25,6 +28,7 @@ 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.BentoBoxHook;
 import xyz.spaceio.hooks.SkyblockAPIHook;
 import xyz.spaceio.hooks.uSkyBlockHook;
 
@@ -100,6 +104,9 @@ public class CustomOreGen extends JavaPlugin {
 		} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("uSkyBlock")) {
 			skyblockAPI = new uSkyBlockHook();
 			sendConsole("&aUsing uSkyBlock as SkyBlock-Plugin");
+		} else if (Bukkit.getServer().getPluginManager().isPluginEnabled("BentoBox")) {
+			skyblockAPI = new BentoBoxHook();
+			sendConsole("&aUsing BentoBox as SkyBlock-Plugin");
 		}
 	}
 
@@ -108,12 +115,12 @@ public class CustomOreGen extends JavaPlugin {
 		cachedOregenJsonConfig.saveToDisk(cachedOregenConfigs);
 	}
 
-	public World getActiveWorld() {
-		return Bukkit.getWorld(skyblockAPI.getSkyBlockWorldName());
+	public List<World> getActiveWorlds() {
+		return Arrays.stream(skyblockAPI.getSkyBlockWorldNames()).map(v -> Bukkit.getWorld(v)).collect(Collectors.toList());
 	}
 
-	public int getLevel(UUID uuid) {
-		return skyblockAPI.getIslandLevel(uuid);
+	public int getLevel(UUID uuid, String world) {
+		return skyblockAPI.getIslandLevel(uuid, world);
 	}
 
 	public OfflinePlayer getOwner(Location loc) {
@@ -192,7 +199,7 @@ public class CustomOreGen extends JavaPlugin {
 				}
 			}
 			if (totalChance != 100.0) {
-				sendConsole(String.format("&cConfig error: generator %s does not have a total chance of 100.0! Total chance is: %d", key, totalChance));
+				sendConsole(String.format("&cConfig error: generator %s does not have a total chance of 100.0! Total chance is: %f", key, totalChance));
 			}
 			generatorConfigs.add(gc);
 
@@ -201,7 +208,7 @@ public class CustomOreGen extends JavaPlugin {
 		sendConsole(String.format("&aLoaded &c%d &agenerators!", generatorConfigs.size()));
 	}
 
-	public GeneratorConfig getGeneratorConfigForPlayer(OfflinePlayer p) {
+	public GeneratorConfig getGeneratorConfigForPlayer(OfflinePlayer p, String world) {
 		GeneratorConfig gc = null;
 		int id = 0;
 		if (p == null) {
@@ -209,11 +216,11 @@ public class CustomOreGen extends JavaPlugin {
 			cacheOreGen(p.getUniqueId(), id);
 		} else {
 
-			int islandLevel = getLevel(p.getUniqueId());
+			int islandLevel = getLevel(p.getUniqueId(), world);
 
 			if (p.isOnline()) {
 				Player realP = p.getPlayer();
-				if (skyblockAPI.getSkyBlockWorldName().equals(realP.getWorld().getName())) {
+				if (this.getActiveWorlds().contains(realP.getWorld())) {
 					for (GeneratorConfig gc2 : generatorConfigs) {
 						if (gc2 == null) {
 							continue;

+ 2 - 2
src/xyz/spaceio/customoregen/Events.java

@@ -47,7 +47,7 @@ public class Events implements Listener {
 				OfflinePlayer p = plugin.getOwner(b.getLocation());
 				if (p == null)
 					return;
-				GeneratorConfig gc = plugin.getGeneratorConfigForPlayer(p);
+				GeneratorConfig gc = plugin.getGeneratorConfigForPlayer(p, event.getBlock().getWorld().getName());
 				if (gc == null)
 					return;
 				if (getObject(gc) == null)
@@ -92,7 +92,7 @@ public class Events implements Listener {
 
 	@EventHandler
 	public void onJoin(PlayerJoinEvent e) {
-		plugin.getGeneratorConfigForPlayer(e.getPlayer());
+		plugin.getGeneratorConfigForPlayer(e.getPlayer(), e.getPlayer().getWorld().getName());
 	}
 
 	

+ 7 - 7
src/xyz/spaceio/hooks/ASkyBlockHook.java

@@ -6,16 +6,16 @@ import org.bukkit.Location;
 
 import com.wasteofplastic.askyblock.ASkyBlockAPI;
 
-public class ASkyBlockHook implements SkyblockAPIHook{
-	
+public class ASkyBlockHook implements SkyblockAPIHook {
+
 	private ASkyBlockAPI api;
-	
+
 	public ASkyBlockHook() {
 		api = ASkyBlockAPI.getInstance();
 	}
 
 	@Override
-	public int getIslandLevel(UUID uuid) {
+	public int getIslandLevel(UUID uuid, String world) {
 		return api.getIslandLevel(uuid);
 	}
 
@@ -25,8 +25,8 @@ public class ASkyBlockHook implements SkyblockAPIHook{
 	}
 
 	@Override
-	public String getSkyBlockWorldName() {
-		return api.getIslandWorld().getName();
+	public String[] getSkyBlockWorldNames() {
+		return new String[] { api.getIslandWorld().getName() };
 	}
-	
+
 }

+ 7 - 7
src/xyz/spaceio/hooks/AcidIslandHook.java

@@ -6,16 +6,16 @@ import org.bukkit.Location;
 
 import com.wasteofplastic.askyblock.ASkyBlockAPI;
 
-public class AcidIslandHook implements SkyblockAPIHook{
-	
+public class AcidIslandHook implements SkyblockAPIHook {
+
 	private ASkyBlockAPI api;
-	
+
 	public AcidIslandHook() {
 		api = ASkyBlockAPI.getInstance();
 	}
 
 	@Override
-	public int getIslandLevel(UUID uuid) {
+	public int getIslandLevel(UUID uuid, String world) {
 		return api.getIslandLevel(uuid);
 	}
 
@@ -23,9 +23,9 @@ public class AcidIslandHook implements SkyblockAPIHook{
 	public UUID getIslandOwner(Location loc) {
 		return api.getIslandAt(loc).getOwner();
 	}
-	
+
 	@Override
-	public String getSkyBlockWorldName() {
-		return api.getIslandWorld().getName();
+	public String[] getSkyBlockWorldNames() {
+		return new String[] { api.getIslandWorld().getName() };
 	}
 }

+ 5 - 4
src/xyz/spaceio/hooks/SkyblockAPIHook.java

@@ -10,9 +10,10 @@ public interface SkyblockAPIHook {
 	 * Returns the island level for a defined player uuid
 	 * 
 	 * @param uuid UUID of the island owner
+	 * @param in World world of the island
 	 * @return island level
 	 */
-	public int getIslandLevel(UUID uuid);
+	public int getIslandLevel(UUID uuid, String inWorld);
 	
 	/**
 	 * Gets the owner of an island on a certain location
@@ -23,9 +24,9 @@ public interface SkyblockAPIHook {
 	public UUID getIslandOwner(Location loc);
 	
 	/**
-	 * Obtains the name of the skyblock world
+	 * Obtains the names of the skyblock worlds
 	 * 
-	 * @return the name of the skyblock world
+	 * @return the names of the skyblock worlds
 	 */
-	public String getSkyBlockWorldName();
+	public String[] getSkyBlockWorldNames();
 }

+ 8 - 8
src/xyz/spaceio/hooks/uSkyBlockHook.java

@@ -7,16 +7,16 @@ import org.bukkit.Location;
 
 import us.talabrek.ultimateskyblock.api.uSkyBlockAPI;
 
-public class uSkyBlockHook implements SkyblockAPIHook{
-	
+public class uSkyBlockHook implements SkyblockAPIHook {
+
 	private uSkyBlockAPI api;
-	
+
 	public uSkyBlockHook() {
 		api = (uSkyBlockAPI) Bukkit.getPluginManager().getPlugin("uSkyBlock");
 	}
 
 	@Override
-	public int getIslandLevel(UUID uuid) {
+	public int getIslandLevel(UUID uuid, String world) {
 		return (int) Math.floor(api.getIslandLevel(Bukkit.getPlayer(uuid)));
 	}
 
@@ -25,15 +25,15 @@ public class uSkyBlockHook implements SkyblockAPIHook{
 		String player = api.getIslandInfo(loc).getLeader();
 		if ((Bukkit.getPlayer(player) != null) && (Bukkit.getPlayer(player).getUniqueId() != null)) {
 			return Bukkit.getOfflinePlayer(player).getUniqueId();
-		}else {
+		} else {
 			return null;
 		}
 	}
 
 	@Override
-	public String getSkyBlockWorldName() {
+	public String[] getSkyBlockWorldNames() {
 		api.getConfig().getString("options.general.worldName");
-		return api.getConfig().getString("options.general.worldName");
+		return new String[] { api.getConfig().getString("options.general.worldName") };
 	}
-	
+
 }