mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-09-29 23:17:26 +02:00
Redid Biome system to be better performing.
This commit is contained in:
parent
51b7896f02
commit
4fdfada273
@ -253,49 +253,35 @@ public class SkyBlock extends SongodaPlugin {
|
||||
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
if (this.userCacheManager != null) {
|
||||
if (this.userCacheManager != null)
|
||||
this.userCacheManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.scoreboardManager != null) {
|
||||
if (this.scoreboardManager != null)
|
||||
this.scoreboardManager.disable();
|
||||
}
|
||||
|
||||
if (this.islandManager != null) {
|
||||
if (this.islandManager != null)
|
||||
this.islandManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.visitManager != null) {
|
||||
if (this.visitManager != null)
|
||||
this.visitManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.banManager != null) {
|
||||
if (this.banManager != null)
|
||||
this.banManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.playerDataManager != null) {
|
||||
if (this.playerDataManager != null)
|
||||
this.playerDataManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.cooldownManager != null) {
|
||||
if (this.cooldownManager != null)
|
||||
this.cooldownManager.onDisable();
|
||||
}
|
||||
|
||||
if (this.hologramTask != null) {
|
||||
if (this.hologramTask != null)
|
||||
this.hologramTask.onDisable();
|
||||
}
|
||||
|
||||
if (this.mobNetherWaterTask != null) {
|
||||
if (this.mobNetherWaterTask != null)
|
||||
this.mobNetherWaterTask.onDisable();
|
||||
}
|
||||
|
||||
if (this.fabledChallenge != null) {
|
||||
if (this.fabledChallenge != null)
|
||||
this.fabledChallenge.onDisable();
|
||||
}
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataLoad() {
|
||||
|
||||
}
|
||||
|
||||
private CoreProtectAPI loadCoreProtect() {
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin("CoreProtect");
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.songoda.skyblock.api.biome;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.songoda.core.compatibility.CompatibleBiome;
|
||||
import com.songoda.skyblock.api.island.Island;
|
||||
import com.songoda.skyblock.island.IslandWorld;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -20,6 +21,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(), IslandWorld.Normal, biome, null);
|
||||
this.biomeManager.setBiome(island.getIsland(), IslandWorld.Normal, CompatibleBiome.getBiome(biome), null);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.skyblock.biome;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleBiome;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.blockscanner.ChunkLoader;
|
||||
@ -21,8 +22,6 @@ import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class BiomeManager {
|
||||
|
||||
final ServerVersion ASYNC_OBFUSCATOR_VERSION = ServerVersion.V1_9;
|
||||
|
||||
private final SkyBlock plugin;
|
||||
private final List<Island> updatingIslands;
|
||||
@ -48,7 +47,7 @@ public class BiomeManager {
|
||||
updatingIslands.remove(island);
|
||||
}
|
||||
|
||||
public void setBiome(Island island, IslandWorld world, Biome biome, CompleteTask task) {
|
||||
public void setBiome(Island island, IslandWorld world, CompatibleBiome biome, CompleteTask task) {
|
||||
addUpdatingIsland(island);
|
||||
|
||||
if (island.getLocation(world, IslandEnvironment.Island) == null) return;
|
||||
@ -59,17 +58,13 @@ public class BiomeManager {
|
||||
|
||||
ChunkLoader.startChunkLoadingPerChunk(island, world, plugin.isPaperAsync(), (futureChunk) -> {
|
||||
Chunk chunk = futureChunk.join();
|
||||
if(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_16)){ // TODO Should be 1.15 but it works fine there
|
||||
setChunkBiome3D(biome, chunk);
|
||||
} else {
|
||||
try {
|
||||
setChunkBiome2D(biome, chunk);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (chunk != null)
|
||||
biome.setBiome(chunk);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
updateBiomePacket(island, chunk);
|
||||
|
||||
|
||||
progress.getAndIncrement();
|
||||
|
||||
if(language.getBoolean("Command.Island.Biome.Progress.Should-Display-Message") &&
|
||||
@ -94,61 +89,6 @@ public class BiomeManager {
|
||||
}));
|
||||
}
|
||||
|
||||
private void setChunkBiome2D(Biome biome, Chunk chunk) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
for(int x = chunk.getX() << 4; x < (chunk.getX()<< 4)+16; x++){
|
||||
for(int z = chunk.getZ() << 4; z < (chunk.getZ()<< 4)+16; z++){
|
||||
World.class.getMethod("setBiome", int.class, int.class, Biome.class).invoke(chunk.getWorld(), x, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do not use - Too laggy
|
||||
private void setChunkBiome3D(Biome biome, Chunk chunk) {
|
||||
for(int x = chunk.getX() << 4; x < (chunk.getX()<< 4)+16; x++){
|
||||
for(int z = chunk.getZ() << 4; z < (chunk.getZ()<< 4)+16; z++){
|
||||
for(int y = 0; y < chunk.getWorld().getMaxHeight(); ++y) {
|
||||
chunk.getWorld().setBiome(x, y, z, biome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateBiomePacket(Island island, Chunk chunk) {
|
||||
Class<?> packetPlayOutMapChunkClass;
|
||||
Class<?> chunkClass;
|
||||
|
||||
packetPlayOutMapChunkClass = NMSUtil.getNMSClass("PacketPlayOutMapChunk");
|
||||
chunkClass = NMSUtil.getNMSClass("Chunk");
|
||||
|
||||
for (Player player : plugin.getIslandManager().getPlayersAtIsland(island, IslandWorld.Normal)) {
|
||||
try {
|
||||
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,
|
||||
packetPlayOutMapChunkClass.getConstructor(chunkClass, int.class).newInstance(player
|
||||
.getLocation().getChunk().getClass().getMethod("getHandle").invoke(chunk),
|
||||
65535));
|
||||
}
|
||||
} else {
|
||||
NMSUtil.sendPacket(player,
|
||||
packetPlayOutMapChunkClass.getConstructor(chunkClass, boolean.class, int.class)
|
||||
.newInstance(player.getLocation().getChunk().getClass().getMethod("getHandle")
|
||||
.invoke(chunk), true, 20));
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface CompleteTask {
|
||||
void onCompleteUpdate();
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class SetBiomeCommand extends SubCommand {
|
||||
} else {
|
||||
if (islandManager.containsIsland(islandOwnerUUID)) {
|
||||
Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID));
|
||||
biomeManager.setBiome(island, world, biome.getBiome(), null);
|
||||
biomeManager.setBiome(island, world, biome, null);
|
||||
if(world.equals(IslandWorld.Normal)) {
|
||||
island.setBiome(biome.getBiome());
|
||||
}
|
||||
@ -106,7 +106,7 @@ public class SetBiomeCommand extends SubCommand {
|
||||
} else {
|
||||
CompatibleBiome finalBiome = biome;
|
||||
IslandWorld finalWorld = world;
|
||||
biomeManager.setBiome(island, world, biome.getBiome(), () -> {
|
||||
biomeManager.setBiome(island, world, biome, () -> {
|
||||
if(finalWorld.equals(IslandWorld.Normal)) {
|
||||
island.setBiome(finalBiome.getBiome());
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ public class GuiBiome extends Gui {
|
||||
}
|
||||
cooldownManager.createPlayer(CooldownType.Biome, player);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
biomeManager.setBiome(island, IslandWorld.Normal, icon.biome.getBiome(), () -> {
|
||||
biomeManager.setBiome(island, IslandWorld.Normal, icon.biome, () -> {
|
||||
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);
|
||||
|
@ -278,10 +278,10 @@ public class IslandManager {
|
||||
} catch (Exception ex) {
|
||||
cBiome = CompatibleBiome.PLAINS;
|
||||
}
|
||||
Biome biome = cBiome.getBiome();
|
||||
final CompatibleBiome compatibleBiome = cBiome;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskLater(plugin, () ->
|
||||
plugin.getBiomeManager().setBiome(island, IslandWorld.Normal, biome, () -> {
|
||||
plugin.getBiomeManager().setBiome(island, IslandWorld.Normal, compatibleBiome, () -> {
|
||||
if (structure.getCommands() != null) {
|
||||
for (String commandList : structure.getCommands()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), commandList.replace("%player", player.getName()));
|
||||
|
@ -34,12 +34,12 @@ public class World implements Listener {
|
||||
break;
|
||||
case NETHER:
|
||||
if(!to.getBlock().getBiome().equals(CompatibleBiome.NETHER_WASTES.getBiome())) {
|
||||
biomeManager.setBiome(island, IslandWorld.Nether, CompatibleBiome.NETHER_WASTES.getBiome(), null);
|
||||
biomeManager.setBiome(island, IslandWorld.Nether, CompatibleBiome.NETHER_WASTES, null);
|
||||
}
|
||||
break;
|
||||
case THE_END:
|
||||
if(!to.getBlock().getBiome().equals(CompatibleBiome.THE_END.getBiome())) {
|
||||
biomeManager.setBiome(island, IslandWorld.End, CompatibleBiome.THE_END.getBiome(), null);
|
||||
biomeManager.setBiome(island, IslandWorld.End, CompatibleBiome.THE_END, null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.songoda.skyblock.menus;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleBiome;
|
||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
@ -135,7 +136,7 @@ public class Biome {
|
||||
SBiome selectedBiomeType = SBiome.getFromGuiIcon(is.getType(), is.getData().getData());
|
||||
|
||||
cooldownManager.createPlayer(CooldownType.Biome, player);
|
||||
biomeManager.setBiome(island,IslandWorld.Normal, selectedBiomeType.getBiome(), null);
|
||||
biomeManager.setBiome(island,IslandWorld.Normal, CompatibleBiome.getBiome(selectedBiomeType.getBiome()), null);
|
||||
island.setBiome(selectedBiomeType.getBiome());
|
||||
island.save();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user