Fix changeset NPE

This commit is contained in:
Jesse Boyd 2016-12-29 19:43:27 +11:00
parent 850bb533cb
commit 8a40320a64
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
7 changed files with 84 additions and 4 deletions

View File

@ -29,6 +29,16 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
this.time = System.currentTimeMillis();
}
public RollbackOptimizedHistory(String world, UUID uuid, int index) {
super(world, uuid, index);
this.time = System.currentTimeMillis();
}
public RollbackOptimizedHistory(String world, UUID uuid) {
super(world, uuid);
this.time = System.currentTimeMillis();
}
public long getTime() {
return time;
}

View File

@ -13,6 +13,10 @@ public class NullChangeSet extends FaweChangeSet {
super(world);
}
public NullChangeSet(String world) {
super(world);
}
@Override
public final boolean flush() {
return false;
@ -43,6 +47,11 @@ public class NullChangeSet extends FaweChangeSet {
}
@Override
public void addChangeTask(FaweQueue queue) {
}
@Override
public Iterator<Change> getIterator(BlockBag blockBag, int mode, boolean redo) {
return getIterator(redo);

View File

@ -55,7 +55,16 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
public DiskStorageHistory(World world, UUID uuid) {
super(world);
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.PATHS.HISTORY + File.separator + Fawe.imp().getWorldName(world) + File.separator + uuid);
init(uuid, Fawe.imp().getWorldName(world));
}
public DiskStorageHistory(String world, UUID uuid) {
super(world);
init(uuid, world);
}
private void init(UUID uuid, String worldName) {
File folder = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.PATHS.HISTORY + File.separator + worldName + File.separator + uuid);
int max = 0;
if (folder.exists()) {
for (File file : folder.listFiles()) {
@ -71,6 +80,11 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
init(uuid, ++max);
}
public DiskStorageHistory(String world, UUID uuid, int index) {
super(world);
init(uuid, index);
}
public DiskStorageHistory(World world, UUID uuid, int index) {
super(world);
init(uuid, index);

View File

@ -1,6 +1,7 @@
package com.boydti.fawe.object.changeset;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FaweChunk;
@ -31,7 +32,8 @@ import java.util.concurrent.atomic.AtomicInteger;
public abstract class FaweChangeSet implements ChangeSet {
private final World world;
private World world;
private final String worldName;
private final boolean mainThread;
private final int layers;
private AtomicInteger waitingCombined = new AtomicInteger(0);
@ -47,13 +49,25 @@ public abstract class FaweChangeSet implements ChangeSet {
}
}
public FaweChangeSet(String world) {
this.worldName = world;
this.mainThread = Fawe.get().isMainThread();
this.layers = FaweChunk.HEIGHT >> 4;
}
public FaweChangeSet(World world) {
this.world = world;
this.worldName = Fawe.imp().getWorldName(world);
this.mainThread = Fawe.get().isMainThread();
this.layers = (this.world.getMaxY() + 1) >> 4;
}
public String getWorldName() {
return worldName;
}
public World getWorld() {
if (world == null && worldName != null) world = FaweAPI.getWorld(worldName);
return world;
}

View File

@ -35,9 +35,23 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
this(world, Settings.HISTORY.COMPRESSION_LEVEL, Settings.HISTORY.STORE_REDO, Settings.HISTORY.SMALL_EDITS);
}
public FaweStreamChangeSet(String world) {
this(world, Settings.HISTORY.COMPRESSION_LEVEL, Settings.HISTORY.STORE_REDO, Settings.HISTORY.SMALL_EDITS);
}
public FaweStreamChangeSet(String world, int compression, boolean storeRedo, boolean smallLoc) {
super(world);
this.compression = compression;
init(storeRedo, smallLoc);
}
public FaweStreamChangeSet(World world, int compression, boolean storeRedo, boolean smallLoc) {
super(world);
this.compression = compression;
init(storeRedo, smallLoc);
}
private void init(boolean storeRedo, boolean smallLoc) {
if (storeRedo) {
if (smallLoc) {
mode = 4;

View File

@ -46,6 +46,10 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
super(world);
}
public MemoryOptimizedHistory(String world) {
super(world);
}
@Override
public boolean flush() {
super.flush();

View File

@ -1,5 +1,7 @@
package com.boydti.fawe.util;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
import com.boydti.fawe.object.FaweLimit;
@ -56,11 +58,13 @@ public class EditSessionBuilder {
public EditSessionBuilder(@Nonnull World world){
checkNotNull(world);
this.world = world;
this.worldName = Fawe.imp().getWorldName(world);
}
public EditSessionBuilder(@Nonnull String worldName) {
checkNotNull(worldName);
this.worldName = worldName;
this.world = FaweAPI.getWorld(worldName);
}
public EditSessionBuilder player(@Nullable FawePlayer player) {
@ -91,12 +95,13 @@ public class EditSessionBuilder {
}
public EditSessionBuilder changeSetNull() {
return changeSet(new NullChangeSet(world));
return changeSet(world == null ? new NullChangeSet(worldName) : new NullChangeSet(world));
}
public EditSessionBuilder world(@Nonnull World world) {
checkNotNull(world);
this.world = world;
this.worldName = Fawe.imp().getWorldName(world);
return this;
}
@ -107,7 +112,17 @@ public class EditSessionBuilder {
* @return
*/
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) {
if (disk) {
if (world == null) {
if (disk) {
if (Settings.HISTORY.USE_DATABASE) {
this.changeSet = new RollbackOptimizedHistory(worldName, uuid);
} else {
this.changeSet = new DiskStorageHistory(worldName, uuid);
}
} else {
this.changeSet = new MemoryOptimizedHistory(worldName);
}
} else if (disk) {
if (Settings.HISTORY.USE_DATABASE) {
this.changeSet = new RollbackOptimizedHistory(world, uuid);
} else {