Fix changeset NPE
This commit is contained in:
parent
850bb533cb
commit
8a40320a64
@ -29,6 +29,16 @@ public class RollbackOptimizedHistory extends DiskStorageHistory {
|
|||||||
this.time = System.currentTimeMillis();
|
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() {
|
public long getTime() {
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,10 @@ public class NullChangeSet extends FaweChangeSet {
|
|||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NullChangeSet(String world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean flush() {
|
public final boolean flush() {
|
||||||
return false;
|
return false;
|
||||||
@ -43,6 +47,11 @@ public class NullChangeSet extends FaweChangeSet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addChangeTask(FaweQueue queue) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Change> getIterator(BlockBag blockBag, int mode, boolean redo) {
|
public Iterator<Change> getIterator(BlockBag blockBag, int mode, boolean redo) {
|
||||||
return getIterator(redo);
|
return getIterator(redo);
|
||||||
|
@ -55,7 +55,16 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
|
|
||||||
public DiskStorageHistory(World world, UUID uuid) {
|
public DiskStorageHistory(World world, UUID uuid) {
|
||||||
super(world);
|
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;
|
int max = 0;
|
||||||
if (folder.exists()) {
|
if (folder.exists()) {
|
||||||
for (File file : folder.listFiles()) {
|
for (File file : folder.listFiles()) {
|
||||||
@ -71,6 +80,11 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
|||||||
init(uuid, ++max);
|
init(uuid, ++max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DiskStorageHistory(String world, UUID uuid, int index) {
|
||||||
|
super(world);
|
||||||
|
init(uuid, index);
|
||||||
|
}
|
||||||
|
|
||||||
public DiskStorageHistory(World world, UUID uuid, int index) {
|
public DiskStorageHistory(World world, UUID uuid, int index) {
|
||||||
super(world);
|
super(world);
|
||||||
init(uuid, index);
|
init(uuid, index);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.boydti.fawe.object.changeset;
|
package com.boydti.fawe.object.changeset;
|
||||||
|
|
||||||
import com.boydti.fawe.Fawe;
|
import com.boydti.fawe.Fawe;
|
||||||
|
import com.boydti.fawe.FaweAPI;
|
||||||
import com.boydti.fawe.FaweCache;
|
import com.boydti.fawe.FaweCache;
|
||||||
import com.boydti.fawe.config.Settings;
|
import com.boydti.fawe.config.Settings;
|
||||||
import com.boydti.fawe.object.FaweChunk;
|
import com.boydti.fawe.object.FaweChunk;
|
||||||
@ -31,7 +32,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
public abstract class FaweChangeSet implements ChangeSet {
|
public abstract class FaweChangeSet implements ChangeSet {
|
||||||
|
|
||||||
private final World world;
|
private World world;
|
||||||
|
private final String worldName;
|
||||||
private final boolean mainThread;
|
private final boolean mainThread;
|
||||||
private final int layers;
|
private final int layers;
|
||||||
private AtomicInteger waitingCombined = new AtomicInteger(0);
|
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) {
|
public FaweChangeSet(World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.worldName = Fawe.imp().getWorldName(world);
|
||||||
this.mainThread = Fawe.get().isMainThread();
|
this.mainThread = Fawe.get().isMainThread();
|
||||||
this.layers = (this.world.getMaxY() + 1) >> 4;
|
this.layers = (this.world.getMaxY() + 1) >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getWorldName() {
|
||||||
|
return worldName;
|
||||||
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
|
if (world == null && worldName != null) world = FaweAPI.getWorld(worldName);
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,23 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet {
|
|||||||
this(world, Settings.HISTORY.COMPRESSION_LEVEL, Settings.HISTORY.STORE_REDO, Settings.HISTORY.SMALL_EDITS);
|
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) {
|
public FaweStreamChangeSet(World world, int compression, boolean storeRedo, boolean smallLoc) {
|
||||||
super(world);
|
super(world);
|
||||||
this.compression = compression;
|
this.compression = compression;
|
||||||
|
init(storeRedo, smallLoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(boolean storeRedo, boolean smallLoc) {
|
||||||
if (storeRedo) {
|
if (storeRedo) {
|
||||||
if (smallLoc) {
|
if (smallLoc) {
|
||||||
mode = 4;
|
mode = 4;
|
||||||
|
@ -46,6 +46,10 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet {
|
|||||||
super(world);
|
super(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MemoryOptimizedHistory(String world) {
|
||||||
|
super(world);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean flush() {
|
public boolean flush() {
|
||||||
super.flush();
|
super.flush();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.boydti.fawe.util;
|
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.config.Settings;
|
||||||
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
||||||
import com.boydti.fawe.object.FaweLimit;
|
import com.boydti.fawe.object.FaweLimit;
|
||||||
@ -56,11 +58,13 @@ public class EditSessionBuilder {
|
|||||||
public EditSessionBuilder(@Nonnull World world){
|
public EditSessionBuilder(@Nonnull World world){
|
||||||
checkNotNull(world);
|
checkNotNull(world);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.worldName = Fawe.imp().getWorldName(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder(@Nonnull String worldName) {
|
public EditSessionBuilder(@Nonnull String worldName) {
|
||||||
checkNotNull(worldName);
|
checkNotNull(worldName);
|
||||||
this.worldName = worldName;
|
this.worldName = worldName;
|
||||||
|
this.world = FaweAPI.getWorld(worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder player(@Nullable FawePlayer player) {
|
public EditSessionBuilder player(@Nullable FawePlayer player) {
|
||||||
@ -91,12 +95,13 @@ public class EditSessionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder changeSetNull() {
|
public EditSessionBuilder changeSetNull() {
|
||||||
return changeSet(new NullChangeSet(world));
|
return changeSet(world == null ? new NullChangeSet(worldName) : new NullChangeSet(world));
|
||||||
}
|
}
|
||||||
|
|
||||||
public EditSessionBuilder world(@Nonnull World world) {
|
public EditSessionBuilder world(@Nonnull World world) {
|
||||||
checkNotNull(world);
|
checkNotNull(world);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.worldName = Fawe.imp().getWorldName(world);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +112,17 @@ public class EditSessionBuilder {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) {
|
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid, int compression) {
|
||||||
|
if (world == null) {
|
||||||
if (disk) {
|
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) {
|
if (Settings.HISTORY.USE_DATABASE) {
|
||||||
this.changeSet = new RollbackOptimizedHistory(world, uuid);
|
this.changeSet = new RollbackOptimizedHistory(world, uuid);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user