diff --git a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java index 3a24f8a49..5e91ca163 100644 --- a/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java +++ b/src/main/java/com/iridium/iridiumskyblock/IridiumSkyblock.java @@ -10,6 +10,7 @@ import com.iridium.iridiumskyblock.commands.CommandManager; import com.iridium.iridiumskyblock.configs.*; import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.generators.IridiumChunkGenerator; import com.iridium.iridiumskyblock.gui.GUI; import com.iridium.iridiumskyblock.listeners.*; import com.iridium.iridiumskyblock.managers.*; @@ -82,7 +83,7 @@ public class IridiumSkyblock extends IridiumCore { private Placeholders placeholders; private IslandSettings islandSettings; - private ChunkGenerator chunkGenerator; + private IridiumChunkGenerator chunkGenerator; private List bankItemList; private Map permissionList; diff --git a/src/main/java/com/iridium/iridiumskyblock/api/IridiumSkyblockAPI.java b/src/main/java/com/iridium/iridiumskyblock/api/IridiumSkyblockAPI.java index 531a29192..9bbbd2a61 100644 --- a/src/main/java/com/iridium/iridiumskyblock/api/IridiumSkyblockAPI.java +++ b/src/main/java/com/iridium/iridiumskyblock/api/IridiumSkyblockAPI.java @@ -7,6 +7,7 @@ import com.iridium.iridiumskyblock.database.IslandBooster; import com.iridium.iridiumskyblock.database.IslandUpgrade; import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.generators.GeneratorType; import com.iridium.iridiumskyblock.managers.IslandManager; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -319,6 +320,16 @@ public boolean isIslandEnd(@NotNull World world) { return iridiumSkyblock.getIslandManager().isIslandEnd(world); } + /** + * Returns which chunk generator IridiumSkyblock is using for world generation. + * + * @return the generator IridiumSkyblock uses + * @since 3.2.7 + */ + public GeneratorType getGeneratorType() { + return IridiumSkyblock.getInstance().getConfiguration().generatorSettings.generatorType; + } + /** * Returns whether the specified player can visit the provided Island.

* diff --git a/src/main/java/com/iridium/iridiumskyblock/generators/GeneratorType.java b/src/main/java/com/iridium/iridiumskyblock/generators/GeneratorType.java index 7139617e3..e43135a1d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/generators/GeneratorType.java +++ b/src/main/java/com/iridium/iridiumskyblock/generators/GeneratorType.java @@ -11,14 +11,14 @@ public enum GeneratorType { SKYBLOCK(SkyblockGenerator::new), OCEAN(OceanGenerator::new); - private ChunkGenerator chunkGenerator; + private IridiumChunkGenerator chunkGenerator; /** * The default constructor. * * @param chunkGenerator The ChunkGenerator for this generator */ - GeneratorType(Supplier chunkGenerator) { + GeneratorType(Supplier chunkGenerator) { this.chunkGenerator = chunkGenerator.get(); } @@ -27,7 +27,7 @@ public enum GeneratorType { * * @return The ChunkGenerator */ - public ChunkGenerator getChunkGenerator() { + public IridiumChunkGenerator getChunkGenerator() { return chunkGenerator; } diff --git a/src/main/java/com/iridium/iridiumskyblock/generators/IridiumChunkGenerator.java b/src/main/java/com/iridium/iridiumskyblock/generators/IridiumChunkGenerator.java new file mode 100644 index 000000000..31c7f3268 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/generators/IridiumChunkGenerator.java @@ -0,0 +1,32 @@ +package com.iridium.iridiumskyblock.generators; + +import com.iridium.iridiumcore.dependencies.xseries.XMaterial; +import org.bukkit.World; +import org.bukkit.generator.ChunkGenerator; +import org.jetbrains.annotations.Nullable; + +/** + * Base class for all IridiumSkyblock chunk generators. + */ +public abstract class IridiumChunkGenerator extends ChunkGenerator { + + /** + * Returns what a made with this generator is mainly consisting of.

+ * Used for performance improvements. + * + * @param world the world that should be checked + * @return the most used material of the chunk generator in this generator + */ + public abstract XMaterial getMainMaterial(@Nullable World world); + + /** + * Returns whether the main material returned by {@link IridiumChunkGenerator#getMainMaterial(World)} + * should be ignored. + * + * @return if the main material should be ignored + */ + public boolean ignoreMainMaterial() { + return getMainMaterial(null) == XMaterial.AIR; + } + +} diff --git a/src/main/java/com/iridium/iridiumskyblock/generators/OceanGenerator.java b/src/main/java/com/iridium/iridiumskyblock/generators/OceanGenerator.java index 3ba16943e..b2e459da7 100644 --- a/src/main/java/com/iridium/iridiumskyblock/generators/OceanGenerator.java +++ b/src/main/java/com/iridium/iridiumskyblock/generators/OceanGenerator.java @@ -7,10 +7,10 @@ import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Block; -import org.bukkit.generator.ChunkGenerator; import org.bukkit.inventory.InventoryHolder; import org.bukkit.util.noise.SimplexOctaveGenerator; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.Random; @@ -19,7 +19,7 @@ * Class which handles the {@link World} generation of IridiumSkyblock. * Creates an ocean world. */ -public class OceanGenerator extends ChunkGenerator { +public class OceanGenerator extends IridiumChunkGenerator { /** * Generates an ocean. @@ -152,4 +152,18 @@ public boolean canSpawn(@NotNull World world, int x, int z) { return true; } + /** + * Returns what a made with this generator is mainly consisting of.

+ * Used for performance improvements. + * + * @param world the world that should be checked + * @return the most used material of the chunk generator in this generator + */ + @Override + public XMaterial getMainMaterial(@Nullable World world) { + if (world == null) return XMaterial.WATER; + + return world.getEnvironment() == Environment.NETHER ? XMaterial.LAVA : XMaterial.WATER; + } + } diff --git a/src/main/java/com/iridium/iridiumskyblock/generators/SkyblockGenerator.java b/src/main/java/com/iridium/iridiumskyblock/generators/SkyblockGenerator.java index 026f5e3b5..abde78e2e 100755 --- a/src/main/java/com/iridium/iridiumskyblock/generators/SkyblockGenerator.java +++ b/src/main/java/com/iridium/iridiumskyblock/generators/SkyblockGenerator.java @@ -1,9 +1,10 @@ package com.iridium.iridiumskyblock.generators; +import com.iridium.iridiumcore.dependencies.xseries.XMaterial; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; @@ -13,7 +14,7 @@ * Class which handles the {@link World} generation of IridiumSkyblock. * Creates an empty void world. */ -public class SkyblockGenerator extends ChunkGenerator { +public class SkyblockGenerator extends IridiumChunkGenerator { public byte[][] blockSections; @@ -73,4 +74,16 @@ public boolean canSpawn(@NotNull World world, int x, int z) { return Collections.emptyList(); } -} \ No newline at end of file + /** + * Returns what a made with this generator is mainly consisting of.

+ * Used for performance improvements. + * + * @param world the world that should be checked + * @return the most used material of the chunk generator in this generator + */ + @Override + public XMaterial getMainMaterial(@Nullable World world) { + return XMaterial.AIR; + } + +} diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index d94ff8b92..51ee486e1 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -856,14 +856,17 @@ public void recalculateIsland(@NotNull Island island) { private void recalculateIsland(@NotNull Island island, @NotNull List chunks) { chunks.stream().map(chunk -> chunk.getChunkSnapshot(true, false, false)).forEach(chunk -> { World world = Bukkit.getWorld(chunk.getWorldName()); + boolean ignoreMainMaterial = IridiumSkyblock.getInstance().getChunkGenerator().ignoreMainMaterial(); int maxHeight = world == null ? 255 : world.getMaxHeight() - 1; + for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { if (island.isInIsland(x + (chunk.getX() * 16), z + (chunk.getZ() * 16))) { final int maxy = Math.min(maxHeight, chunk.getHighestBlockYAt(x, z)); for (int y = LocationUtils.getMinHeight(world); y <= maxy; y++) { XMaterial material = XMaterial.matchXMaterial(chunk.getBlockType(x, y, z)); - if (material.equals(XMaterial.AIR)) continue; + if (material == XMaterial.AIR) continue; + if (!ignoreMainMaterial && material == IridiumSkyblock.getInstance().getChunkGenerator().getMainMaterial(world)) continue; IslandBlocks islandBlock = IridiumSkyblock.getInstance().getIslandManager().getIslandBlock(island, material); islandBlock.setAmount(islandBlock.getAmount() + 1); @@ -873,10 +876,10 @@ private void recalculateIsland(@NotNull Island island, @NotNull List chun } }); - if (!Bukkit.isPrimaryThread()) { - Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> getAllTileInIsland(island, chunks)); - } else { + if (Bukkit.isPrimaryThread()) { getAllTileInIsland(island, chunks); + } else { + Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> getAllTileInIsland(island, chunks)); } }