Get chunks asynchronously

This commit is contained in:
MattBDev 2019-08-05 13:33:27 -04:00
parent cc45208605
commit bd51292f4c
4 changed files with 40 additions and 34 deletions

View File

@ -10,14 +10,16 @@ repositories {
mavenLocal() mavenLocal()
} }
apply plugin: "com.github.johnrengelman.shadow"
dependencies { dependencies {
implementation project(':Core') implementation project(':Core')
compile project(':Core') compile project(':Core')
compile 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT' compile 'com.destroystokyo.paper:paper-api:1.14.4-R0.1-SNAPSHOT'
//implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT' //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT'
implementation 'org.spigotmc:spigot-api:1.14.3-R0.1-SNAPSHOT' implementation 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT'
compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0') compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0')
compile "io.papermc:paperlib:1.0.1" compile "io.papermc:paperlib:1.0.2"
compile("net.milkbowl.vault:VaultAPI:1.7") { compile("net.milkbowl.vault:VaultAPI:1.7") {
exclude module: 'bukkit' exclude module: 'bukkit'
} }
@ -47,7 +49,7 @@ shadowJar {
include(dependency('com.squareup.okhttp3:okhttp:3.14.0')) include(dependency('com.squareup.okhttp3:okhttp:3.14.0'))
include(dependency('com.squareup.okio:okio:2.2.2')) include(dependency('com.squareup.okio:okio:2.2.2'))
include(dependency('org.jetbrains.kotlin:kotlin-stdlib:1.3.30')) include(dependency('org.jetbrains.kotlin:kotlin-stdlib:1.3.30'))
include(dependency("io.papermc:paperlib:1.0.1")) include(dependency("io.papermc:paperlib:1.0.2"))
} }
relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib' relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib'
// relocate('org.mcstats', 'com.plotsquared.stats') // relocate('org.mcstats', 'com.plotsquared.stats')

View File

@ -1,11 +1,19 @@
package com.github.intellectualsites.plotsquared.bukkit; package com.github.intellectualsites.plotsquared.bukkit;
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.github.intellectualsites.plotsquared.bukkit.listeners.*; import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener;
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111; import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener;
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents;
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener;
import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener;
import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents;
import com.github.intellectualsites.plotsquared.bukkit.util.*; import com.github.intellectualsites.plotsquared.bukkit.util.*;
import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue; import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue;
import com.github.intellectualsites.plotsquared.bukkit.uuid.*; import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler;
import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.plot.IPlotMain; import com.github.intellectualsites.plotsquared.plot.IPlotMain;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
@ -16,7 +24,12 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
import com.github.intellectualsites.plotsquared.plot.generator.HybridGen; import com.github.intellectualsites.plotsquared.plot.generator.HybridGen;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager; import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager;
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
@ -26,12 +39,9 @@ import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Capability;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Location;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -56,13 +66,6 @@ import java.util.UUID;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.Method;
import java.util.*;
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Getter private static WorldEdit worldEdit; @Getter private static WorldEdit worldEdit;

View File

@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQ
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import io.papermc.lib.PaperLib;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -20,6 +21,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.ExecutionException;
public class BukkitLocalQueue extends BasicLocalBlockQueue { public class BukkitLocalQueue extends BasicLocalBlockQueue {
@ -69,7 +71,8 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
} }
} }
@Override public final void setComponents(LocalChunk lc) { @Override public final void setComponents(LocalChunk lc)
throws ExecutionException, InterruptedException {
setBaseBlocks(lc); setBaseBlocks(lc);
} }
@ -77,14 +80,17 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
return Bukkit.getWorld(getWorld()); return Bukkit.getWorld(getWorld());
} }
public Chunk getChunk(int x, int z) { public Chunk getChunk(int x, int z) throws ExecutionException, InterruptedException {
return getBukkitWorld().getChunkAt(x, z); return PaperLib.getChunkAtAsync(getBukkitWorld(), x, z).get();
} }
public void setBaseBlocks(LocalChunk lc) { public void setBaseBlocks(LocalChunk lc) throws ExecutionException, InterruptedException {
World worldObj = Bukkit.getWorld(getWorld()); World worldObj = Bukkit.getWorld(getWorld());
if (worldObj == null) {
throw new NullPointerException("World cannot be null.");
}
PaperLib.getChunkAtAsync(worldObj, lc.getX(), lc.getZ(), true).get();
Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ()); Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ());
chunk.load(true);
for (int layer = 0; layer < lc.baseblocks.length; layer++) { for (int layer = 0; layer < lc.baseblocks.length; layer++) {
BaseBlock[] blocksLayer = lc.baseblocks[layer]; BaseBlock[] blocksLayer = lc.baseblocks[layer];
if (blocksLayer != null) { if (blocksLayer != null) {

View File

@ -1,19 +1,16 @@
package com.github.intellectualsites.plotsquared.plot.util.block; package com.github.intellectualsites.plotsquared.plot.util.block;
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import lombok.Getter;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ExecutionException;
public abstract class BasicLocalBlockQueue extends LocalBlockQueue { public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
@ -35,7 +32,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
@Override public abstract PlotBlock getBlock(int x, int y, int z); @Override public abstract PlotBlock getBlock(int x, int y, int z);
public abstract void setComponents(LocalChunk lc); public abstract void setComponents(LocalChunk lc)
throws ExecutionException, InterruptedException;
@Override public final String getWorld() { @Override public final String getWorld() {
return world; return world;
@ -62,10 +60,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
return false; return false;
} }
public final boolean execute(final LocalChunk lc) { public final boolean execute(@NotNull LocalChunk lc)
if (lc == null) { throws ExecutionException, InterruptedException {
return false;
}
this.setComponents(lc); this.setComponents(lc);
return true; return true;
} }
@ -154,7 +150,6 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
TaskManager.IMP.sync(new RunnableVal<Object>() { TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override public void run(Object value) { @Override public void run(Object value) {
while (next()) { while (next()) {
;
} }
} }
}); });