From 338119ac76a8e1b8e9772ad9e6361d81a9ae8080 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sun, 12 Jul 2020 14:44:45 +0200 Subject: [PATCH] Initial support for biome update in other dimensions --- .../skyblock/api/biome/BiomeManager.java | 3 +- .../songoda/skyblock/biome/BiomeManager.java | 8 ++--- .../commands/admin/SetBiomeCommand.java | 32 +++++++++++++++---- .../songoda/skyblock/gui/biome/GuiBiome.java | 2 +- .../skyblock/island/IslandManager.java | 2 +- .../com/songoda/skyblock/menus/Biome.java | 2 +- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java b/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java index c73ad556..b6ebdf0a 100644 --- a/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java +++ b/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java @@ -2,6 +2,7 @@ package com.songoda.skyblock.api.biome; import com.google.common.base.Preconditions; import com.songoda.skyblock.api.island.Island; +import com.songoda.skyblock.island.IslandWorld; import org.bukkit.block.Biome; public class BiomeManager { @@ -19,6 +20,6 @@ public class BiomeManager { Preconditions.checkArgument(island != null, "Cannot set biome to null island"); Preconditions.checkArgument(biome != null, "Cannot set biome to null biome"); - this.biomeManager.setBiome(island.getIsland(), biome, null); + this.biomeManager.setBiome(island.getIsland(), IslandWorld.Normal, biome, null); } } diff --git a/src/main/java/com/songoda/skyblock/biome/BiomeManager.java b/src/main/java/com/songoda/skyblock/biome/BiomeManager.java index 98e9018b..b5727232 100644 --- a/src/main/java/com/songoda/skyblock/biome/BiomeManager.java +++ b/src/main/java/com/songoda/skyblock/biome/BiomeManager.java @@ -49,17 +49,17 @@ public class BiomeManager { updatingIslands.remove(island); } - public void setBiome(Island island, Biome biome, CompleteTask task) { + public void setBiome(Island island, IslandWorld world, Biome biome, CompleteTask task) { addUpdatingIsland(island); - if (island.getLocation(IslandWorld.Normal, IslandEnvironment.Island) == null) return; + if (island.getLocation(world, IslandEnvironment.Island) == null) return; if(plugin.isPaperAsync()){ // We keep it sequentially in order to use less RAM int chunkAmount = (int) Math.ceil(Math.pow(island.getSize()/16d, 2d)); AtomicInteger progress = new AtomicInteger(); - ChunkLoader.startChunkLoadingPerChunk(island, IslandWorld.Normal, plugin.isPaperAsync(), (asyncChunk, syncChunk) -> { + ChunkLoader.startChunkLoadingPerChunk(island, world, plugin.isPaperAsync(), (asyncChunk, syncChunk) -> { Chunk chunk = asyncChunk.join(); if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){ // TODO Should be 1.15 but it works fine there setChunkBiome3D(biome, chunk); // 2D for the moment @@ -95,7 +95,7 @@ public class BiomeManager { } })); } else { - ChunkLoader.startChunkLoading(island, IslandWorld.Normal, plugin.isPaperAsync(), (asyncChunks, syncChunks) -> { + ChunkLoader.startChunkLoading(island, world, plugin.isPaperAsync(), (asyncChunks, syncChunks) -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { int progress = 0; for(Chunk chunk : syncChunks){ diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/SetBiomeCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/SetBiomeCommand.java index e5a6f2af..c42d9856 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/SetBiomeCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/SetBiomeCommand.java @@ -8,6 +8,7 @@ import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -45,9 +46,23 @@ public class SetBiomeCommand extends SubCommand { Config config = fileManager.getConfig(new File(plugin.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - if (args.length == 2) { + if (args.length >= 2) { String biomeName = args[1].toUpperCase().trim(); - + + IslandWorld world = null; + if(args[2] != null) { + String worldName = args[2].toUpperCase().trim(); + for(IslandWorld islandWorld : IslandWorld.values()) { + if(islandWorld.name().equalsIgnoreCase(worldName)) { + world = islandWorld; + } + } + } + + if(world == null) { + world = IslandWorld.Normal; + } + CompatibleBiome biome = null; for (CompatibleBiome cbiome : CompatibleBiome.values()) { if (cbiome.isCompatible() && cbiome.name().equals(biomeName)) { @@ -77,8 +92,10 @@ public class SetBiomeCommand extends SubCommand { } else { if (islandManager.containsIsland(islandOwnerUUID)) { Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); - biomeManager.setBiome(island, biome.getBiome(), null); - island.setBiome(biome.getBiome()); + biomeManager.setBiome(island, world, biome.getBiome(), null); + if(world.equals(IslandWorld.Normal)) { + island.setBiome(biome.getBiome()); + } } else { islandManager.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID)); Island island = islandManager.getIsland(Bukkit.getOfflinePlayer(islandOwnerUUID)); @@ -88,8 +105,11 @@ public class SetBiomeCommand extends SubCommand { soundManager.playSound(sender, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else { CompatibleBiome finalBiome = biome; - biomeManager.setBiome(island, biome.getBiome(), () -> { - island.setBiome(finalBiome.getBiome()); + IslandWorld finalWorld = world; + biomeManager.setBiome(island, world, biome.getBiome(), () -> { + if(finalWorld.equals(IslandWorld.Normal)) { + island.setBiome(finalBiome.getBiome()); + } }); } } diff --git a/src/main/java/com/songoda/skyblock/gui/biome/GuiBiome.java b/src/main/java/com/songoda/skyblock/gui/biome/GuiBiome.java index de566538..ffea945f 100644 --- a/src/main/java/com/songoda/skyblock/gui/biome/GuiBiome.java +++ b/src/main/java/com/songoda/skyblock/gui/biome/GuiBiome.java @@ -189,7 +189,7 @@ public class GuiBiome extends Gui { } cooldownManager.createPlayer(CooldownType.Biome, player); Bukkit.getScheduler().runTask(plugin, () -> { - biomeManager.setBiome(island, icon.biome.getBiome(), () -> { + biomeManager.setBiome(island, IslandWorld.Normal, icon.biome.getBiome(), () -> { if(languageLoad.getBoolean("Command.Island.Biome.Completed.Should-Display-Message")){ messageManager.sendMessage(player, languageLoad.getString("Command.Island.Biome.Completed.Message")); soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_YES.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index ba3e8e6f..65d5dfe8 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -282,7 +282,7 @@ public class IslandManager { Biome biome = cBiome.getBiome(); Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> { - plugin.getBiomeManager().setBiome(island, biome, () -> { + plugin.getBiomeManager().setBiome(island, IslandWorld.Normal, biome, () -> { if (structure.getCommands() != null) { for (String commandList : structure.getCommands()) { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), commandList.replace("%player", player.getName())); diff --git a/src/main/java/com/songoda/skyblock/menus/Biome.java b/src/main/java/com/songoda/skyblock/menus/Biome.java index 2b137c2c..2ba6b24d 100644 --- a/src/main/java/com/songoda/skyblock/menus/Biome.java +++ b/src/main/java/com/songoda/skyblock/menus/Biome.java @@ -135,7 +135,7 @@ public class Biome { SBiome selectedBiomeType = SBiome.getFromGuiIcon(is.getType(), is.getData().getData()); cooldownManager.createPlayer(CooldownType.Biome, player); - biomeManager.setBiome(island, selectedBiomeType.getBiome(), null); + biomeManager.setBiome(island,IslandWorld.Normal, selectedBiomeType.getBiome(), null); island.setBiome(selectedBiomeType.getBiome()); island.save();