From 5b3e0973f2d60f42dd64cd15dd4c673c62159809 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 13 Apr 2016 20:04:01 +1000 Subject: [PATCH] Fixes #21 --- build.gradle | 2 +- bukkit/build/resources/main/plugin.yml | 2 +- .../com/boydti/fawe/bukkit/FaweBukkit.java | 60 +++++++------------ .../fawe/bukkit/v1_8/BukkitChunk_1_8.java | 5 -- .../fawe/bukkit/v1_8/BukkitQueue_1_8.java | 4 -- .../fawe/bukkit/v1_9/BukkitChunk_1_9.java | 5 -- bukkit/src/main/resources/plugin.yml | 2 +- .../java/com/boydti/fawe/config/Settings.java | 3 + .../object/changeset/DiskStorageHistory.java | 4 -- .../java/com/boydti/fawe/util/SetQueue.java | 2 +- .../com/boydti/fawe/util/TaskManager.java | 24 ++++++++ .../java/com/sk89q/worldedit/EditSession.java | 51 ++++++++++------ .../extent/clipboard/BlockArrayClipboard.java | 36 ++++++++++- .../com/boydti/fawe/forge/SpongeMain.java | 2 +- pom.xml | 2 +- 15 files changed, 122 insertions(+), 82 deletions(-) diff --git a/build.gradle b/build.gradle index 383b2e40..8232ec24 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } group = 'com.boydti.fawe' -version = '3.3.6' +version = '3.3.9' description = """FastAsyncWorldEdit""" subprojects { diff --git a/bukkit/build/resources/main/plugin.yml b/bukkit/build/resources/main/plugin.yml index b11fce19..799ec50b 100644 --- a/bukkit/build/resources/main/plugin.yml +++ b/bukkit/build/resources/main/plugin.yml @@ -1,6 +1,6 @@ name: FastAsyncWorldEdit main: com.boydti.fawe.bukkit.FaweBukkit -version: 3.3.6 +version: 3.3.9 description: Fast Async WorldEdit plugin authors: [Empire92] loadbefore: [WorldEdit] diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index c450a0d9..f692c397 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -148,47 +148,10 @@ public class FaweBukkit extends JavaPlugin implements IFawe, Listener { return new BukkitTaskMan(this); } - @Override - public int[] getVersion() { - try { - final int[] version = new int[3]; - final String[] split = Bukkit.getBukkitVersion().split("-")[0].split("\\."); - version[0] = Integer.parseInt(split[0]); - version[1] = Integer.parseInt(split[1]); - if (split.length == 3) { - version[2] = Integer.parseInt(split[2]); - } - return version; - } catch (final Exception e) { - e.printStackTrace(); - this.debug(StringMan.getString(Bukkit.getBukkitVersion())); - this.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\."))); - return new int[] { Integer.MAX_VALUE, 0, 0 }; - } - } - - /** - * The FaweQueue is a core part of block placement
- * - The queue returned here is used in the SetQueue class (SetQueue handles the implementation specific queue)
- * - Block changes are grouped by chunk (as it's more efficient for lighting/packet sending)
- * - The FaweQueue returned here will provide the wrapper around the chunk object (FaweChunk)
- * - When a block change is requested, the SetQueue will first check if the chunk exists in the queue, or it will create and add it
- */ - @Override - public FaweQueue getNewQueue(String world) { - if (FaweAPI.checkVersion(this.getServerVersion(), 1, 9, 0)) { - try { - return new BukkitQueue_1_9(world); - } catch (final Throwable e) { - e.printStackTrace(); - } - } - return new BukkitQueue_1_8(world); - } - private int[] version; - public int[] getServerVersion() { + @Override + public int[] getVersion() { if (this.version == null) { try { this.version = new int[3]; @@ -208,6 +171,25 @@ public class FaweBukkit extends JavaPlugin implements IFawe, Listener { return this.version; } + /** + * The FaweQueue is a core part of block placement
+ * - The queue returned here is used in the SetQueue class (SetQueue handles the implementation specific queue)
+ * - Block changes are grouped by chunk (as it's more efficient for lighting/packet sending)
+ * - The FaweQueue returned here will provide the wrapper around the chunk object (FaweChunk)
+ * - When a block change is requested, the SetQueue will first check if the chunk exists in the queue, or it will create and add it
+ */ + @Override + public FaweQueue getNewQueue(String world) { + if (FaweAPI.checkVersion(this.getVersion(), 1, 9, 0)) { + try { + return new BukkitQueue_1_9(world); + } catch (final Throwable e) { + e.printStackTrace(); + } + } + return new BukkitQueue_1_8(world); + } + /** * The EditSessionWrapper should have the same functionality as the normal EditSessionWrapper but with some optimizations */ diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java index 9c0cded1..70721c77 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitChunk_1_8.java @@ -100,11 +100,6 @@ public class BukkitChunk_1_8 extends FaweChunk { return this.ids[i]; } - public void clear() { - this.ids = null; - this.biomes = null; - } - public int[][] getBiomeArray() { return this.biomes; } diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java index e924a9da..a2f01864 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue_1_8.java @@ -449,10 +449,6 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 { } } } - - // Clear - fs.clear(); - TaskManager.IMP.later(new Runnable() { @Override public void run() { diff --git a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java index f2eed18f..0e037dc3 100644 --- a/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java +++ b/bukkit/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitChunk_1_9.java @@ -104,11 +104,6 @@ public class BukkitChunk_1_9 extends FaweChunk { return this.ids; } - public void clear() { - this.ids = null; - this.biomes = null; - } - public int[][] getBiomeArray() { return this.biomes; } diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index b11fce19..799ec50b 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: FastAsyncWorldEdit main: com.boydti.fawe.bukkit.FaweBukkit -version: 3.3.6 +version: 3.3.9 description: Fast Async WorldEdit plugin authors: [Empire92] loadbefore: [WorldEdit] diff --git a/core/src/main/java/com/boydti/fawe/config/Settings.java b/core/src/main/java/com/boydti/fawe/config/Settings.java index 8f9aac62..e72fd3f1 100644 --- a/core/src/main/java/com/boydti/fawe/config/Settings.java +++ b/core/src/main/java/com/boydti/fawe/config/Settings.java @@ -26,6 +26,7 @@ public class Settings { public static boolean METRICS = true; public static int CHUNK_WAIT = 0; public static boolean REGION_RESTRICTIONS = true; + public static int ALLOCATE = 0; public static HashMap limits; @@ -71,6 +72,7 @@ public class Settings { options.put("history.chunk-wait-ms", CHUNK_WAIT); options.put("history.buffer-size", BUFFER_SIZE); options.put("region-restrictions", REGION_RESTRICTIONS); + options.put("queue.extra-time-ms", ALLOCATE); options.put("metrics", METRICS); // Default limit @@ -101,6 +103,7 @@ public class Settings { COMPRESSION_LEVEL = config.getInt("history.compression-level", config.getBoolean("history.compress") ? 1 : 0); BUFFER_SIZE = config.getInt("history.buffer-size", BUFFER_SIZE); CHUNK_WAIT = config.getInt("history.chunk-wait-ms"); + ALLOCATE = config.getInt("queue.extra-time-ms"); if (STORE_HISTORY_ON_DISK = config.getBoolean("history.use-disk")) { LocalSession.MAX_HISTORY_SIZE = Integer.MAX_VALUE; } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index 78c145e1..6fd5575c 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -340,10 +340,6 @@ public class DiskStorageHistory implements ChangeSet, FaweChangeSet { flush(); try { if (bdFile.exists()) { - if (nbtfFile.exists()) { - NBTInputStream os = new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))); - NamedTag tag = os.readNamedTag(); - } final NBTInputStream nbtf = nbtfFile.exists() ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbtfFile))) : null; final NBTInputStream nbtt = nbttFile.exists() ? new NBTInputStream(new GZIPInputStream(new FileInputStream(nbttFile))) : null; diff --git a/core/src/main/java/com/boydti/fawe/util/SetQueue.java b/core/src/main/java/com/boydti/fawe/util/SetQueue.java index 8c1c9509..e1b4cb48 100644 --- a/core/src/main/java/com/boydti/fawe/util/SetQueue.java +++ b/core/src/main/java/com/boydti/fawe/util/SetQueue.java @@ -61,7 +61,7 @@ public class SetQueue { return; } } - final long free = 50 + Math.min((50 + SetQueue.this.last) - (SetQueue.this.last = System.currentTimeMillis()), SetQueue.this.last2 - System.currentTimeMillis()); + final long free = Settings.ALLOCATE + 50 + Math.min((50 + SetQueue.this.last) - (SetQueue.this.last = System.currentTimeMillis()), SetQueue.this.last2 - System.currentTimeMillis()); SetQueue.this.time_current.incrementAndGet(); do { if (SetQueue.this.isWaiting()) { diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index 7280b4bb..242bac99 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -1,5 +1,9 @@ package com.boydti.fawe.util; +import com.intellectualcrafters.plot.object.RunnableVal; +import java.util.Collection; +import java.util.Iterator; + public abstract class TaskManager { public static TaskManager IMP; @@ -17,4 +21,24 @@ public abstract class TaskManager { public abstract void laterAsync(final Runnable r, final int delay); public abstract void cancel(final int task); + + public void objectTask(Collection objects, final RunnableVal task, final Runnable whenDone) { + final Iterator iterator = objects.iterator(); + task(new Runnable() { + @Override + public void run() { + long start = System.currentTimeMillis(); + boolean hasNext; + while ((hasNext = iterator.hasNext()) && System.currentTimeMillis() - start < 5) { + task.value = iterator.next(); + task.run(); + } + if (!hasNext) { + later(whenDone, 1); + } else { + later(this, 1); + } + } + }); + } } diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index 2382d22a..e7a2b1a5 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -42,6 +42,7 @@ import com.boydti.fawe.util.Perm; import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; +import com.intellectualcrafters.plot.object.RunnableVal; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockType; @@ -114,6 +115,7 @@ import com.sk89q.worldedit.util.collection.DoubleArrayList; import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -542,15 +544,19 @@ public class EditSession implements Extent { @Override public BaseBlock getLazyBlock(final Vector position) { + return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + } + + public BaseBlock getLazyBlock(int x, int y, int z) { if (limit != null && limit.MAX_CHECKS-- < 0) { return nullBlock; } - int combinedId4Data = queue.getCombinedId4Data(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + int combinedId4Data = queue.getCombinedId4Data(x, y, z); if (!FaweCache.hasNBT(combinedId4Data >> 4)) { return FaweCache.CACHE_BLOCK[combinedId4Data]; } try { - return this.world.getLazyBlock(position); + return this.world.getLazyBlock(new Vector(x, y, z)); } catch (Throwable e) { return FaweCache.CACHE_BLOCK[combinedId4Data]; } @@ -2031,32 +2037,43 @@ public class EditSession implements Extent { * @return number of trees created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeForest(final Vector basePosition, final int size, final double density, final TreeGenerator treeGenerator) throws MaxChangedBlocksException { + public int makeForest(final Vector basePosition, final int size, final double density, final TreeGenerator treeGenerator) { + final ArrayDeque trees = new ArrayDeque<>(); for (int x = basePosition.getBlockX() - size; x <= (basePosition.getBlockX() + size); ++x) { for (int z = basePosition.getBlockZ() - size; z <= (basePosition.getBlockZ() + size); ++z) { // Don't want to be in the ground - if (!this.getBlock(new Vector(x, basePosition.getBlockY(), z)).isAir()) { + if (!this.getLazyBlock(x, basePosition.getBlockY(), z).isAir()) { continue; } // The gods don't want a tree here if (FaweCache.RANDOM.random(65536) >= (density * 65536)) { continue; } // def 0.05 - - for (int y = basePosition.getBlockY(); y >= (basePosition.getBlockY() - 10); --y) { - // Check if we hit the ground - final int t = this.getBlock(new Vector(x, y, z)).getType(); - if ((t == BlockID.GRASS) || (t == BlockID.DIRT)) { - treeGenerator.generate(this, new Vector(x, y + 1, z)); - break; - } else if (t == BlockID.SNOW) { - this.setBlock(new Vector(x, y, z), new BaseBlock(BlockID.AIR)); - } else if (t != BlockID.AIR) { // Trees won't grow on this! - break; - } - } + trees.add(new Vector(x, 0, z)); } } + if (trees.size() > 0) { + TaskManager.IMP.objectTask(trees, new RunnableVal() { + @Override + public void run(Vector vector) { + try { + for (int y = basePosition.getBlockY(); y >= (basePosition.getBlockY() - 10); --y) { + vector = new Vector(vector.getX(), y, vector.getZ()); + final int t = getBlock(vector).getType(); + if ((t == BlockID.GRASS) || (t == BlockID.DIRT)) { + treeGenerator.generate(EditSession.this, new Vector(vector.getX(), y + 1, vector.getZ())); + break; + } else if (t == BlockID.SNOW) { + setBlock(vector, new BaseBlock(BlockID.AIR)); + } else if (t != BlockID.AIR) { // Trees won't grow on this! + break; + } + } + } + catch (MaxChangedBlocksException ignore) {} + } + }, null); + } return this.changes = -1; } diff --git a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index 4a9e3a88..0561ad9a 100644 --- a/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -29,6 +29,7 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; @@ -304,9 +305,15 @@ public class BlockArrayClipboard implements Clipboard { /** * Stores entity data. */ - private class ClipboardEntity extends StoredEntity { + private class ClipboardEntity implements Entity { + private final Location location; + private final BaseEntity entity; + ClipboardEntity(Location location, BaseEntity entity) { - super(location, entity); + checkNotNull(location); + checkNotNull(entity); + this.location = location; + this.entity = new BaseEntity(entity); } @Override @@ -319,6 +326,31 @@ public class BlockArrayClipboard implements Clipboard { public T getFacet(Class cls) { return null; } + + /** + * Get the entity state. This is not a copy. + * + * @return the entity + */ + BaseEntity getEntity() { + return entity; + } + + @Override + public BaseEntity getState() { + return new BaseEntity(entity); + } + + @Override + public Location getLocation() { + return location; + } + + @Override + public Extent getExtent() { + return location.getExtent(); + } + } public static Class inject() { diff --git a/forge/src/main/java/com/boydti/fawe/forge/SpongeMain.java b/forge/src/main/java/com/boydti/fawe/forge/SpongeMain.java index de4d6da4..0689962b 100644 --- a/forge/src/main/java/com/boydti/fawe/forge/SpongeMain.java +++ b/forge/src/main/java/com/boydti/fawe/forge/SpongeMain.java @@ -13,7 +13,7 @@ import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.profile.GameProfileManager; -@Plugin(id = "com.boydti.fawe", name = "FastAsyncWorldEdit", description = "Lagless WorldEdit, Area restrictions, Memory mangement, Block logging", url = "https://github.com/boy0001/FastAsyncWorldedit", version = "3.3.6") +@Plugin(id = "com.boydti.fawe", name = "FastAsyncWorldEdit", description = "Lagless WorldEdit, Area restrictions, Memory mangement, Block logging", url = "https://github.com/boy0001/FastAsyncWorldedit", version = "3.3.9") public class SpongeMain { public PluginContainer plugin; diff --git a/pom.xml b/pom.xml index 371418fa..052d9af5 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 FastAsyncWorldEdit - 3.3.6 + 3.3.9 FastAsyncWorldEdit jar