This commit is contained in:
Jesse Boyd 2016-04-13 20:04:01 +10:00
parent 42654bd784
commit 5b3e0973f2
15 changed files with 122 additions and 82 deletions

View File

@ -10,7 +10,7 @@ buildscript {
}
group = 'com.boydti.fawe'
version = '3.3.6'
version = '3.3.9'
description = """FastAsyncWorldEdit"""
subprojects {

View File

@ -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]

View File

@ -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<br>
* - The queue returned here is used in the SetQueue class (SetQueue handles the implementation specific queue)<br>
* - Block changes are grouped by chunk (as it's more efficient for lighting/packet sending)<br>
* - The FaweQueue returned here will provide the wrapper around the chunk object (FaweChunk)<br>
* - 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<br>
*/
@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<br>
* - The queue returned here is used in the SetQueue class (SetQueue handles the implementation specific queue)<br>
* - Block changes are grouped by chunk (as it's more efficient for lighting/packet sending)<br>
* - The FaweQueue returned here will provide the wrapper around the chunk object (FaweChunk)<br>
* - 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<br>
*/
@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
*/

View File

@ -100,11 +100,6 @@ public class BukkitChunk_1_8 extends FaweChunk<Chunk> {
return this.ids[i];
}
public void clear() {
this.ids = null;
this.biomes = null;
}
public int[][] getBiomeArray() {
return this.biomes;
}

View File

@ -449,10 +449,6 @@ public class BukkitQueue_1_8 extends BukkitQueue_0 {
}
}
}
// Clear
fs.clear();
TaskManager.IMP.later(new Runnable() {
@Override
public void run() {

View File

@ -104,11 +104,6 @@ public class BukkitChunk_1_9 extends FaweChunk<Chunk> {
return this.ids;
}
public void clear() {
this.ids = null;
this.biomes = null;
}
public int[][] getBiomeArray() {
return this.biomes;
}

View File

@ -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]

View File

@ -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<String, FaweLimit> 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;
}

View File

@ -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;

View File

@ -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()) {

View File

@ -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 <T> void objectTask(Collection<T> objects, final RunnableVal<T> task, final Runnable whenDone) {
final Iterator<T> 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);
}
}
});
}
}

View File

@ -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<Vector> 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<Vector>() {
@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;
}

View File

@ -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> T getFacet(Class<? extends T> 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() {

View File

@ -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;

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>FastAsyncWorldEdit</artifactId>
<version>3.3.6</version>
<version>3.3.9</version>
<name>FastAsyncWorldEdit</name>
<packaging>jar</packaging>
<build>