mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-02-21 06:01:37 +01:00
Disabled /is biome in 1.16 and trying to resolve with a thread pool
This commit is contained in:
parent
b1be709c3c
commit
8602836406
@ -3,6 +3,7 @@ package com.songoda.skyblock;
|
|||||||
import com.songoda.core.SongodaCore;
|
import com.songoda.core.SongodaCore;
|
||||||
import com.songoda.core.SongodaPlugin;
|
import com.songoda.core.SongodaPlugin;
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.compatibility.ServerProject;
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.core.configuration.Config;
|
import com.songoda.core.configuration.Config;
|
||||||
import com.songoda.core.gui.GuiManager;
|
import com.songoda.core.gui.GuiManager;
|
||||||
@ -117,13 +118,10 @@ public class SkyBlock extends SongodaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if(paper = ServerProject.isServer(ServerProject.PAPER)){
|
||||||
Class.forName("com.destroystokyo.paper.PaperConfig");
|
|
||||||
paper = true;
|
|
||||||
paperAsync = Bukkit.spigot().getPaperConfig().getBoolean("settings.async-chunks.enable", false);
|
paperAsync = Bukkit.spigot().getPaperConfig().getBoolean("settings.async-chunks.enable", false);
|
||||||
this.getLogger().info("Enabling Paper hooks");
|
this.getLogger().info("Enabling Paper hooks");
|
||||||
} catch (ClassNotFoundException ignored) {
|
} else {
|
||||||
paper = false;
|
|
||||||
PaperLib.suggestPaper(this);
|
PaperLib.suggestPaper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +227,10 @@ public class SkyBlock extends SongodaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDisable() {
|
public void onPluginDisable() {
|
||||||
|
if (this.biomeManager != null) {
|
||||||
|
this.biomeManager.onDisable();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.userCacheManager != null) {
|
if (this.userCacheManager != null) {
|
||||||
this.userCacheManager.onDisable();
|
this.userCacheManager.onDisable();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,6 @@ public class BiomeManager {
|
|||||||
Preconditions.checkArgument(island != null, "Cannot set biome to null island");
|
Preconditions.checkArgument(island != null, "Cannot set biome to null island");
|
||||||
Preconditions.checkArgument(biome != null, "Cannot set biome to null biome");
|
Preconditions.checkArgument(biome != null, "Cannot set biome to null biome");
|
||||||
|
|
||||||
this.biomeManager.setBiome(island.getIsland(), biome);
|
this.biomeManager.setBiome(island.getIsland(), biome, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,78 +2,143 @@ package com.songoda.skyblock.biome;
|
|||||||
|
|
||||||
import com.songoda.core.compatibility.ServerVersion;
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.skyblock.SkyBlock;
|
import com.songoda.skyblock.SkyBlock;
|
||||||
|
import com.songoda.skyblock.blockscanner.ChunkLoader;
|
||||||
import com.songoda.skyblock.island.Island;
|
import com.songoda.skyblock.island.Island;
|
||||||
import com.songoda.skyblock.island.IslandEnvironment;
|
import com.songoda.skyblock.island.IslandEnvironment;
|
||||||
import com.songoda.skyblock.island.IslandWorld;
|
import com.songoda.skyblock.island.IslandWorld;
|
||||||
import com.songoda.skyblock.blockscanner.ChunkLoader;
|
|
||||||
import com.songoda.skyblock.utils.version.NMSUtil;
|
import com.songoda.skyblock.utils.version.NMSUtil;
|
||||||
import org.bukkit.*;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class BiomeManager {
|
public class BiomeManager {
|
||||||
|
|
||||||
private final SkyBlock skyblock;
|
private final SkyBlock skyblock;
|
||||||
|
private final List<Island> updatingIslands;
|
||||||
|
private final List<ExecutorService> pools;
|
||||||
|
|
||||||
public BiomeManager(SkyBlock skyblock) {
|
public BiomeManager(SkyBlock skyblock) {
|
||||||
this.skyblock = skyblock;
|
this.skyblock = skyblock;
|
||||||
|
this.updatingIslands = new ArrayList<>();
|
||||||
|
this.pools = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiome(Island island, Biome biome) {
|
public boolean isUpdating(Island island) {
|
||||||
|
return updatingIslands.contains(island);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUpdatingIsland(Island island) {
|
||||||
|
updatingIslands.add(island);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUpdatingIsland(Island island) {
|
||||||
|
updatingIslands.remove(island);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBiome(Island island, Biome biome, CompleteTask task) {
|
||||||
|
addUpdatingIsland(island);
|
||||||
|
|
||||||
if (island.getLocation(IslandWorld.Normal, IslandEnvironment.Island) == null) return;
|
if (island.getLocation(IslandWorld.Normal, IslandEnvironment.Island) == null) return;
|
||||||
|
|
||||||
if(skyblock.isPaperAsync()){
|
if(skyblock.isPaperAsync()){
|
||||||
// We keep it sequentially in order to use less RAM
|
// We keep it sequentially in order to use less RAM
|
||||||
|
ExecutorService threadPool = Executors.newFixedThreadPool(4);
|
||||||
|
pools.add(threadPool);
|
||||||
ChunkLoader.startChunkLoadingPerChunk(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunk, syncChunk) -> {
|
ChunkLoader.startChunkLoadingPerChunk(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunk, syncChunk) -> {
|
||||||
Chunk chunk = asyncChunk.join();
|
Chunk chunk = asyncChunk.join();
|
||||||
setChunkBiome(biome, chunk);
|
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){ // TODO Should be 1.15 but it works fine there
|
||||||
updateBiomePacket(island, chunk);
|
setChunkBiome3D(island, biome, chunk, threadPool);
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
ChunkLoader.startChunkLoading(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunks, syncChunks) -> {
|
setChunkBiome2D(island, biome, chunk);
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> {
|
}
|
||||||
syncChunks.forEach(chunk -> {
|
}, (island1 -> {
|
||||||
setChunkBiome(biome, chunk);
|
removeUpdatingIsland(island1);
|
||||||
updateBiomePacket(island, chunk);
|
if(task != null) {
|
||||||
});
|
task.onCompleteUpdate();
|
||||||
});
|
}
|
||||||
});
|
threadPool.shutdown();
|
||||||
|
pools.remove(threadPool);
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
ExecutorService threadPool = Executors.newFixedThreadPool(4);
|
||||||
|
pools.add(threadPool);
|
||||||
|
ChunkLoader.startChunkLoadingPerChunk(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunk, syncChunk) -> {
|
||||||
|
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){ // TODO Should be 1.15 but it works fine there
|
||||||
|
setChunkBiome3D(island, biome, syncChunk, threadPool);
|
||||||
|
} else {
|
||||||
|
setChunkBiome2D(island, biome, syncChunk);
|
||||||
|
}
|
||||||
|
}, (island1 -> {
|
||||||
|
removeUpdatingIsland(island1);
|
||||||
|
if(task != null) {
|
||||||
|
task.onCompleteUpdate();
|
||||||
|
}
|
||||||
|
threadPool.shutdown();
|
||||||
|
pools.remove(threadPool);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChunkBiome(Biome biome, Chunk chunk) {
|
private void setChunkBiome2D(Island island, Biome biome, Chunk chunk) {
|
||||||
for(int xx = 0; xx < 16; xx++){
|
for(int xx = 0; xx < 16; xx++){
|
||||||
for(int zz = 0; zz < 16; zz++){
|
for(int zz = 0; zz < 16; zz++){
|
||||||
//if(ServerVersion.isServerVersionBelow(ServerVersion.V1_15)){
|
if(!chunk.getWorld().getBiome(xx, zz).equals(biome)){
|
||||||
chunk.getBlock(xx, 0, zz).setBiome(biome);
|
chunk.getWorld().setBiome(xx, zz, biome);
|
||||||
//} else {
|
|
||||||
// for(int i = 0; i<256; i+=2){
|
|
||||||
// chunk.getBlock(xx, i, zz).setBiome(biome);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateBiomePacket(island, chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChunkBiome3D(Island island, Biome biome, Chunk chunk, ExecutorService pool) {
|
||||||
|
for(int i = 0; i<256; i+=16){
|
||||||
|
int finalI = i;
|
||||||
|
pool.execute(() -> {
|
||||||
|
for(int x = 0; x < 16; x++){
|
||||||
|
for(int z = 0; z < 16; z++){
|
||||||
|
for(int y = 0; y<16; y++){
|
||||||
|
chunk.getWorld().setBiome(x, y * finalI, z, biome);
|
||||||
|
if(!chunk.getWorld().getBiome(x, y * finalI, z).equals(biome)){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
updateBiomePacket(island, chunk);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private Class<?> packetPlayOutMapChunkClass;
|
|
||||||
private Class<?> chunkClass;
|
|
||||||
|
|
||||||
private void updateBiomePacket(Island island, Chunk chunk) {
|
private void updateBiomePacket(Island island, Chunk chunk) {
|
||||||
if (packetPlayOutMapChunkClass == null) {
|
Class<?> packetPlayOutMapChunkClass;
|
||||||
|
Class<?> chunkClass;
|
||||||
|
|
||||||
packetPlayOutMapChunkClass = NMSUtil.getNMSClass("PacketPlayOutMapChunk");
|
packetPlayOutMapChunkClass = NMSUtil.getNMSClass("PacketPlayOutMapChunk");
|
||||||
chunkClass = NMSUtil.getNMSClass("Chunk");
|
chunkClass = NMSUtil.getNMSClass("Chunk");
|
||||||
}
|
|
||||||
|
|
||||||
for (Player player : skyblock.getIslandManager().getPlayersAtIsland(island, IslandWorld.Normal)) {
|
for (Player player : skyblock.getIslandManager().getPlayersAtIsland(island, IslandWorld.Normal)) {
|
||||||
try {
|
try {
|
||||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||||
|
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) {
|
||||||
|
NMSUtil.sendPacket(player,
|
||||||
|
packetPlayOutMapChunkClass.getConstructor(chunkClass, int.class, boolean.class).newInstance(player
|
||||||
|
.getLocation().getChunk().getClass().getMethod("getHandle").invoke(chunk),
|
||||||
|
65535, true));
|
||||||
|
} else {
|
||||||
NMSUtil.sendPacket(player,
|
NMSUtil.sendPacket(player,
|
||||||
packetPlayOutMapChunkClass.getConstructor(chunkClass, int.class).newInstance(player
|
packetPlayOutMapChunkClass.getConstructor(chunkClass, int.class).newInstance(player
|
||||||
.getLocation().getChunk().getClass().getMethod("getHandle").invoke(chunk),
|
.getLocation().getChunk().getClass().getMethod("getHandle").invoke(chunk),
|
||||||
65535));
|
65535));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
NMSUtil.sendPacket(player,
|
NMSUtil.sendPacket(player,
|
||||||
packetPlayOutMapChunkClass.getConstructor(chunkClass, boolean.class, int.class)
|
packetPlayOutMapChunkClass.getConstructor(chunkClass, boolean.class, int.class)
|
||||||
@ -86,4 +151,14 @@ public class BiomeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
for(ExecutorService pool : pools){
|
||||||
|
pool.shutdownNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface CompleteTask {
|
||||||
|
void onCompleteUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,21 +24,25 @@ public class ChunkLoader extends BukkitRunnable {
|
|||||||
private boolean chunkForChunk;
|
private boolean chunkForChunk;
|
||||||
private boolean paper;
|
private boolean paper;
|
||||||
private World world;
|
private World world;
|
||||||
|
private Island island;
|
||||||
private int x;
|
private int x;
|
||||||
private int z;
|
private int z;
|
||||||
private int minZ;
|
private int minZ;
|
||||||
private int maxX;
|
private int maxX;
|
||||||
private int maxZ;
|
private int maxZ;
|
||||||
private int chunkPerTick;
|
private int chunkPerTick;
|
||||||
|
private CompleteTask completeTask;
|
||||||
|
|
||||||
private ChunkLoader(Island island, IslandWorld islandWorld, boolean paper, boolean chunkForChunk, ChunkForChunkScannerTask chunkTask) {
|
private ChunkLoader(Island island, IslandWorld islandWorld, boolean paper, boolean chunkForChunk, ChunkForChunkScannerTask chunkTask, CompleteTask complete) {
|
||||||
chunkPerTick = SkyBlock.getInstance().getFileManager()
|
chunkPerTick = SkyBlock.getInstance().getFileManager()
|
||||||
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
||||||
.getFileConfiguration().getInt("Island.Performance.ChunkPerTick", 25);
|
.getFileConfiguration().getInt("Island.Performance.ChunkPerTick", 25);
|
||||||
|
|
||||||
|
this.completeTask = complete;
|
||||||
this.chunkTask = chunkTask;
|
this.chunkTask = chunkTask;
|
||||||
this.chunkForChunk = chunkForChunk;
|
this.chunkForChunk = chunkForChunk;
|
||||||
this.paper = paper;
|
this.paper = paper;
|
||||||
|
this.island = island;
|
||||||
Location islandLocation = island.getLocation(islandWorld, IslandEnvironment.Island);
|
Location islandLocation = island.getLocation(islandWorld, IslandEnvironment.Island);
|
||||||
|
|
||||||
if (islandLocation == null) return;
|
if (islandLocation == null) return;
|
||||||
@ -64,14 +68,16 @@ public class ChunkLoader extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChunkLoader(Island island, IslandWorld islandWorld, boolean paper, boolean chunkForChunk, ChunkScannerTask generalTask) {
|
private ChunkLoader(Island island, IslandWorld islandWorld, boolean paper, boolean chunkForChunk, ChunkScannerTask generalTask, CompleteTask complete) {
|
||||||
chunkPerTick = SkyBlock.getInstance().getFileManager()
|
chunkPerTick = SkyBlock.getInstance().getFileManager()
|
||||||
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
.getConfig(new File(SkyBlock.getInstance().getDataFolder(), "config.yml"))
|
||||||
.getFileConfiguration().getInt("Island.Performance.ChunkPerTick", 25);
|
.getFileConfiguration().getInt("Island.Performance.ChunkPerTick", 25);
|
||||||
|
|
||||||
|
this.completeTask = complete;
|
||||||
this.generalTask = generalTask;
|
this.generalTask = generalTask;
|
||||||
this.chunkForChunk = chunkForChunk;
|
this.chunkForChunk = chunkForChunk;
|
||||||
this.paper = paper;
|
this.paper = paper;
|
||||||
|
this.island = island;
|
||||||
Location islandLocation = island.getLocation(islandWorld, IslandEnvironment.Island);
|
Location islandLocation = island.getLocation(islandWorld, IslandEnvironment.Island);
|
||||||
|
|
||||||
if (islandLocation == null) return;
|
if (islandLocation == null) return;
|
||||||
@ -129,18 +135,21 @@ public class ChunkLoader extends BukkitRunnable {
|
|||||||
if(generalTask != null) {
|
if(generalTask != null) {
|
||||||
generalTask.onComplete(asyncPositions, syncPositions);
|
generalTask.onComplete(asyncPositions, syncPositions);
|
||||||
}
|
}
|
||||||
|
if(completeTask != null) {
|
||||||
|
completeTask.onComplete(island);
|
||||||
|
}
|
||||||
this.cancel();
|
this.cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startChunkLoading(Island island, IslandWorld islandWorld, boolean paper, ChunkScannerTask task){
|
public static void startChunkLoading(Island island, IslandWorld islandWorld, boolean paper, ChunkScannerTask task, CompleteTask complete){
|
||||||
new ChunkLoader(island, islandWorld, paper, false, task);
|
new ChunkLoader(island, islandWorld, paper, false, task, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startChunkLoadingPerChunk(Island island, IslandWorld islandWorld, boolean paper, ChunkForChunkScannerTask task){
|
public static void startChunkLoadingPerChunk(Island island, IslandWorld islandWorld, boolean paper, ChunkForChunkScannerTask task, CompleteTask complete){
|
||||||
new ChunkLoader(island, islandWorld, paper, true, task);
|
new ChunkLoader(island, islandWorld, paper, true, task, complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ChunkScannerTask {
|
public interface ChunkScannerTask {
|
||||||
@ -154,4 +163,8 @@ public class ChunkLoader extends BukkitRunnable {
|
|||||||
void onChunkComplete(CompletableFuture<Chunk> asyncChunk, Chunk syncChunk);
|
void onChunkComplete(CompletableFuture<Chunk> asyncChunk, Chunk syncChunk);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface CompleteTask {
|
||||||
|
void onComplete(Island island);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.skyblock.command.commands.admin;
|
package com.songoda.skyblock.command.commands.admin;
|
||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleSound;
|
import com.songoda.core.compatibility.CompatibleSound;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
import com.songoda.skyblock.biome.BiomeManager;
|
import com.songoda.skyblock.biome.BiomeManager;
|
||||||
import com.songoda.skyblock.command.SubCommand;
|
import com.songoda.skyblock.command.SubCommand;
|
||||||
import com.songoda.skyblock.config.FileManager;
|
import com.songoda.skyblock.config.FileManager;
|
||||||
@ -44,6 +45,10 @@ public class SetBiomeCommand extends SubCommand {
|
|||||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
FileConfiguration configLoad = config.getFileConfiguration();
|
FileConfiguration configLoad = config.getFileConfiguration();
|
||||||
|
|
||||||
|
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){
|
||||||
|
messageManager.sendMessage(sender, "&bSkyBlock &8| &6Warning&8: &eThis feature is not supported on this Minecraft version yet. Use at your own risk.");
|
||||||
|
}
|
||||||
|
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
String biomeName = args[1].toUpperCase().trim();
|
String biomeName = args[1].toUpperCase().trim();
|
||||||
|
|
||||||
@ -76,7 +81,7 @@ public class SetBiomeCommand extends SubCommand {
|
|||||||
} else {
|
} else {
|
||||||
if (islandManager.containsIsland(islandOwnerUUID)) {
|
if (islandManager.containsIsland(islandOwnerUUID)) {
|
||||||
Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID));
|
Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID));
|
||||||
biomeManager.setBiome(island, biome.getBiome());
|
biomeManager.setBiome(island, biome.getBiome(), null);
|
||||||
island.setBiome(biome.getBiome());
|
island.setBiome(biome.getBiome());
|
||||||
} else {
|
} else {
|
||||||
islandManager.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID));
|
islandManager.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID));
|
||||||
@ -86,7 +91,7 @@ public class SetBiomeCommand extends SubCommand {
|
|||||||
configLoad.getString("Command.Island.Admin.SetBiome.Island.Data.Message"));
|
configLoad.getString("Command.Island.Admin.SetBiome.Island.Data.Message"));
|
||||||
soundManager.playSound(sender, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
soundManager.playSound(sender, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||||
} else {
|
} else {
|
||||||
biomeManager.setBiome(island, biome.getBiome());
|
biomeManager.setBiome(island, biome.getBiome(), null);
|
||||||
island.setBiome(biome.getBiome());
|
island.setBiome(biome.getBiome());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.songoda.skyblock.command.commands.island;
|
package com.songoda.skyblock.command.commands.island;
|
||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleSound;
|
import com.songoda.core.compatibility.CompatibleSound;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
|
import com.songoda.skyblock.biome.BiomeManager;
|
||||||
import com.songoda.skyblock.command.SubCommand;
|
import com.songoda.skyblock.command.SubCommand;
|
||||||
import com.songoda.skyblock.config.FileManager.Config;
|
import com.songoda.skyblock.config.FileManager.Config;
|
||||||
import com.songoda.skyblock.gui.bank.GuiBank;
|
import com.songoda.skyblock.gui.bank.GuiBank;
|
||||||
@ -26,20 +28,31 @@ public class BiomeCommand extends SubCommand {
|
|||||||
MessageManager messageManager = skyblock.getMessageManager();
|
MessageManager messageManager = skyblock.getMessageManager();
|
||||||
IslandManager islandManager = skyblock.getIslandManager();
|
IslandManager islandManager = skyblock.getIslandManager();
|
||||||
SoundManager soundManager = skyblock.getSoundManager();
|
SoundManager soundManager = skyblock.getSoundManager();
|
||||||
|
BiomeManager biomeManager = skyblock.getBiomeManager();
|
||||||
|
|
||||||
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
FileConfiguration configLoad = config.getFileConfiguration();
|
FileConfiguration configLoad = config.getFileConfiguration();
|
||||||
|
|
||||||
Island island = islandManager.getIsland(player);
|
Island island = islandManager.getIsland(player);
|
||||||
|
|
||||||
|
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){
|
||||||
|
messageManager.sendMessage(player, "&bSkyBlock &8| &cError&8: &eThis feature is not available on this Minecraft version yet.");
|
||||||
|
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (island == null) {
|
if (island == null) {
|
||||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.Owner.Message"));
|
messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.Owner.Message"));
|
||||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F);
|
||||||
} else if ((island.hasRole(IslandRole.Operator, player.getUniqueId())
|
} else if ((island.hasRole(IslandRole.Operator, player.getUniqueId())
|
||||||
&& skyblock.getPermissionManager().hasPermission(island,"Biome", IslandRole.Operator))
|
&& skyblock.getPermissionManager().hasPermission(island,"Biome", IslandRole.Operator))
|
||||||
|| island.hasRole(IslandRole.Owner, player.getUniqueId())) {
|
|| island.hasRole(IslandRole.Owner, player.getUniqueId())) {
|
||||||
|
if(biomeManager.isUpdating(island)){
|
||||||
|
messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.InProgress.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F);
|
||||||
|
} else {
|
||||||
skyblock.getGuiManager().showGUI(player, new GuiBiome(skyblock, player, island, IslandWorld.Normal, null, false)); // TODO Nether and End support
|
skyblock.getGuiManager().showGUI(player, new GuiBiome(skyblock, player, island, IslandWorld.Normal, null, false)); // TODO Nether and End support
|
||||||
soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F);
|
soundManager.playSound(player, CompatibleSound.BLOCK_CHEST_OPEN.getSound(), 1.0F, 1.0F);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.Permission.Message"));
|
messageManager.sendMessage(player, configLoad.getString("Command.Island.Biome.Permission.Message"));
|
||||||
soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F);
|
soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F);
|
||||||
|
@ -175,7 +175,10 @@ public class GuiBiome extends Gui {
|
|||||||
}
|
}
|
||||||
cooldownManager.createPlayer(CooldownType.Biome, player);
|
cooldownManager.createPlayer(CooldownType.Biome, player);
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||||
biomeManager.setBiome(island, icon.biome.getBiome());
|
biomeManager.setBiome(island, icon.biome.getBiome(), () -> {
|
||||||
|
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Biome.Completed.Message"));
|
||||||
|
soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_YES.getSound(), 1.0F, 1.0F);
|
||||||
|
});
|
||||||
island.save();
|
island.save();
|
||||||
});
|
});
|
||||||
island.setBiome(icon.biome.getBiome());
|
island.setBiome(icon.biome.getBiome());
|
||||||
|
@ -4,6 +4,7 @@ import com.bekvon.bukkit.residence.Residence;
|
|||||||
import com.bekvon.bukkit.residence.containers.Flags;
|
import com.bekvon.bukkit.residence.containers.Flags;
|
||||||
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.songoda.core.compatibility.CompatibleBiome;
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
import com.songoda.core.compatibility.CompatibleSound;
|
import com.songoda.core.compatibility.CompatibleSound;
|
||||||
import com.songoda.skyblock.SkyBlock;
|
import com.songoda.skyblock.SkyBlock;
|
||||||
@ -272,23 +273,23 @@ public class IslandManager {
|
|||||||
player.setFallDistance(0.0F);
|
player.setFallDistance(0.0F);
|
||||||
}, configLoad.getInt("Island.Creation.TeleportTimeout") * 20);
|
}, configLoad.getInt("Island.Creation.TeleportTimeout") * 20);
|
||||||
|
|
||||||
String biomeName = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getString("Island.Biome.Default.Type").toUpperCase();
|
/*String biomeName = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getString("Island.Biome.Default.Type").toUpperCase();
|
||||||
SBiome sBiome;
|
CompatibleBiome cBiome;
|
||||||
try {
|
try {
|
||||||
sBiome = SBiome.valueOf(biomeName);
|
cBiome = CompatibleBiome.valueOf(biomeName);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
sBiome = SBiome.PLAINS;
|
cBiome = CompatibleBiome.PLAINS;
|
||||||
}
|
}
|
||||||
Biome biome = sBiome.getBiome();
|
Biome biome = cBiome.getBiome();
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> {
|
Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> {
|
||||||
skyblock.getBiomeManager().setBiome(island, biome);
|
skyblock.getBiomeManager().setBiome(island, biome, null);
|
||||||
if (structure.getCommands() != null) {
|
if (structure.getCommands() != null) {
|
||||||
for (String commandList : structure.getCommands()) {
|
for (String commandList : structure.getCommands()) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), commandList.replace("%player", player.getName()));
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), commandList.replace("%player", player.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 20L);
|
}, 20L);*/
|
||||||
|
|
||||||
// Recalculate island level after 5 seconds
|
// Recalculate island level after 5 seconds
|
||||||
if (configLoad.getBoolean("Island.Levelling.ScanAutomatically"))
|
if (configLoad.getBoolean("Island.Levelling.ScanAutomatically"))
|
||||||
@ -662,7 +663,7 @@ public class IslandManager {
|
|||||||
}
|
}
|
||||||
snapshots.put(world, positions.stream().map(Chunk::getChunkSnapshot).collect(Collectors.toList()));
|
snapshots.put(world, positions.stream().map(Chunk::getChunkSnapshot).collect(Collectors.toList()));
|
||||||
ChunkDeleteSplitter.startDeletion(snapshots);
|
ChunkDeleteSplitter.startDeletion(snapshots);
|
||||||
});
|
}, null);
|
||||||
} else {
|
} else {
|
||||||
ChunkLoader.startChunkLoading(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunks, syncChunks) -> {
|
ChunkLoader.startChunkLoading(island, IslandWorld.Normal, skyblock.isPaperAsync(), (asyncChunks, syncChunks) -> {
|
||||||
Bukkit.getScheduler().runTask(skyblock, () -> {
|
Bukkit.getScheduler().runTask(skyblock, () -> {
|
||||||
@ -671,7 +672,7 @@ public class IslandManager {
|
|||||||
snapshots.put(world, list);
|
snapshots.put(world, list);
|
||||||
ChunkDeleteSplitter.startDeletion(snapshots);
|
ChunkDeleteSplitter.startDeletion(snapshots);
|
||||||
});
|
});
|
||||||
});
|
}, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ public final class IslandScan extends BukkitRunnable {
|
|||||||
snapshots.put(skyblock.getWorldManager().getWorld(world), syncPositions.stream().map(org.bukkit.Chunk::getChunkSnapshot).collect(Collectors.toList()));
|
snapshots.put(skyblock.getWorldManager().getWorld(world), syncPositions.stream().map(org.bukkit.Chunk::getChunkSnapshot).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
task.onComplete();
|
task.onComplete();
|
||||||
});
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface PopulateTask {
|
private interface PopulateTask {
|
||||||
|
@ -136,7 +136,7 @@ public class Biome {
|
|||||||
SBiome selectedBiomeType = SBiome.getFromGuiIcon(is.getType(), is.getData().getData());
|
SBiome selectedBiomeType = SBiome.getFromGuiIcon(is.getType(), is.getData().getData());
|
||||||
|
|
||||||
cooldownManager.createPlayer(CooldownType.Biome, player);
|
cooldownManager.createPlayer(CooldownType.Biome, player);
|
||||||
biomeManager.setBiome(island, selectedBiomeType.getBiome());
|
biomeManager.setBiome(island, selectedBiomeType.getBiome(), null);
|
||||||
island.setBiome(selectedBiomeType.getBiome());
|
island.setBiome(selectedBiomeType.getBiome());
|
||||||
island.save();
|
island.save();
|
||||||
|
|
||||||
|
@ -1,31 +1,43 @@
|
|||||||
package com.songoda.skyblock.world.generator;
|
package com.songoda.skyblock.world.generator;
|
||||||
|
|
||||||
import java.io.File;
|
import com.songoda.core.compatibility.CompatibleBiome;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.compatibility.ServerVersion;
|
||||||
|
import com.songoda.skyblock.SkyBlock;
|
||||||
|
import com.songoda.skyblock.island.IslandWorld;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
import com.songoda.skyblock.SkyBlock;
|
import javax.annotation.Nonnull;
|
||||||
import com.songoda.skyblock.island.IslandWorld;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class VoidGenerator extends ChunkGenerator {
|
public class VoidGenerator extends ChunkGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) {
|
public @Nonnull ChunkData generateChunkData(@Nonnull World world, @Nonnull Random random, int chunkX, int chunkZ, @Nonnull BiomeGrid biomeGrid) {
|
||||||
final ChunkData chunkData = createChunkData(world);
|
final ChunkData chunkData = createChunkData(world);
|
||||||
|
|
||||||
final SkyBlock skyblock = SkyBlock.getInstance();
|
final SkyBlock skyblock = SkyBlock.getInstance();
|
||||||
final Configuration configLoad = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration();
|
final Configuration configLoad = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration();
|
||||||
final ConfigurationSection worldSection = configLoad.getConfigurationSection("Island.World");
|
final ConfigurationSection worldSection = configLoad.getConfigurationSection("Island.World");
|
||||||
|
|
||||||
|
/*if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)) { // TODO Should be 1.15 but it works fine there
|
||||||
|
setChunkBiome3D(CompatibleBiome.valueOf(configLoad
|
||||||
|
.getString("Island.Biome.Default.Type").toUpperCase()).getBiome(), biomeGrid);
|
||||||
|
} else {
|
||||||
|
setChunkBiome2D(CompatibleBiome.valueOf(configLoad
|
||||||
|
.getString("Island.Biome.Default.Type").toUpperCase()).getBiome(), biomeGrid);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
for (IslandWorld worldList : IslandWorld.values()) {
|
for (IslandWorld worldList : IslandWorld.values()) {
|
||||||
if (world.getEnvironment() == World.Environment.NETHER
|
if (world.getEnvironment() == World.Environment.NETHER
|
||||||
|| world.getEnvironment() == World.Environment.NORMAL
|
|| world.getEnvironment() == World.Environment.NORMAL
|
||||||
@ -71,4 +83,26 @@ public class VoidGenerator extends ChunkGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setChunkBiome3D(Biome biome, BiomeGrid grid) {
|
||||||
|
for(int x = 0; x < 16; x++){
|
||||||
|
for(int z = 0; z < 16; z++){
|
||||||
|
for(int y = 0; y<256; y++){
|
||||||
|
if(!grid.getBiome(x, y, z).equals(biome)){
|
||||||
|
grid.setBiome(x, y, z, biome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChunkBiome2D(Biome biome, BiomeGrid grid) {
|
||||||
|
for(int x = 0; x < 16; x++){
|
||||||
|
for(int z = 0; z < 16; z++){
|
||||||
|
if(!grid.getBiome(x, z).equals(biome)){
|
||||||
|
grid.setBiome(x, z, biome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -830,6 +830,10 @@ Command:
|
|||||||
Message: '&f&oOpens the Island Biome menu.'
|
Message: '&f&oOpens the Island Biome menu.'
|
||||||
Permission:
|
Permission:
|
||||||
Message: '&bSkyBlock &8| &cError&8: &eYou do not have the right to change your Island''s biome.'
|
Message: '&bSkyBlock &8| &cError&8: &eYou do not have the right to change your Island''s biome.'
|
||||||
|
InProgress:
|
||||||
|
Message: '&bSkyBlock &8| &cError&8: &eA biome update is still in progress for this Island.'
|
||||||
|
Completed:
|
||||||
|
Message: '&bSkyBlock &8| &aInfo&8: &eThe biome update is now complete'
|
||||||
Owner:
|
Owner:
|
||||||
Message: '&bSkyBlock &8| &cError&8: &eYou are not an Island Owner.'
|
Message: '&bSkyBlock &8| &cError&8: &eYou are not an Island Owner.'
|
||||||
Visitors:
|
Visitors:
|
||||||
|
Loading…
Reference in New Issue
Block a user