mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-05 20:36:42 +00:00
Differentiate passthrough / abstract delegate
AbstractDelegateExtent allows overriding just the basic set/get to change behavior - at performance cost Passthrough passes all operation, so each must be individually overrided.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.boydti.fawe.object.extent;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.PassthroughExtent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
|
@ -2,9 +2,11 @@ package com.boydti.fawe.object.extent;
|
||||
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.PassthroughExtent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ExtentHeightCacher extends AbstractDelegateExtent {
|
||||
public class ExtentHeightCacher extends PassthroughExtent {
|
||||
|
||||
public ExtentHeightCacher(Extent extent) {
|
||||
super(extent);
|
||||
@ -18,15 +20,10 @@ public class ExtentHeightCacher extends AbstractDelegateExtent {
|
||||
}
|
||||
}
|
||||
|
||||
private transient int cacheCenX;
|
||||
private transient int cacheCenZ;
|
||||
private transient int cacheBotX = Integer.MIN_VALUE;
|
||||
private transient int cacheBotZ = Integer.MIN_VALUE;
|
||||
private transient int cacheCenterZ;
|
||||
private transient byte[] cacheHeights;
|
||||
private transient int lastY;
|
||||
private transient boolean foundY;
|
||||
private transient boolean lastValue;
|
||||
|
||||
@Override
|
||||
public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) {
|
||||
|
@ -9,10 +9,11 @@ import com.boydti.fawe.util.WEManager;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.PassthroughExtent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class MemoryCheckingExtent extends AbstractDelegateExtent {
|
||||
public class MemoryCheckingExtent extends PassthroughExtent {
|
||||
private final FawePlayer<?> player;
|
||||
|
||||
public MemoryCheckingExtent(final FawePlayer<?> player, final Extent extent) {
|
||||
@ -21,20 +22,16 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(final BlockVector3 location, final B block) throws WorldEditException {
|
||||
if (super.setBlock(location, block)) {
|
||||
if (MemUtil.isMemoryLimited()) {
|
||||
if (this.player != null) {
|
||||
player.sendMessage(BBC.WORLDEDIT_CANCEL_REASON.format(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY.s()));
|
||||
if (Permission.hasPermission(this.player.toWorldEditPlayer(), "worldedit.fast")) {
|
||||
BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
|
||||
}
|
||||
public Extent getExtent() {
|
||||
if (MemUtil.isMemoryLimited()) {
|
||||
if (this.player != null) {
|
||||
player.sendMessage(BBC.WORLDEDIT_CANCEL_REASON.format(BBC.WORLDEDIT_CANCEL_REASON_LOW_MEMORY.s()));
|
||||
if (Permission.hasPermission(this.player.toWorldEditPlayer(), "worldedit.fast")) {
|
||||
BBC.WORLDEDIT_OOM_ADMIN.send(this.player);
|
||||
}
|
||||
WEManager.IMP.cancelEdit(this, FaweException.LOW_MEMORY);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
WEManager.IMP.cancelEdit(this, FaweException.LOW_MEMORY);
|
||||
}
|
||||
return false;
|
||||
return super.getExtent();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.object.extent;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import com.sk89q.worldedit.extent.PassthroughExtent;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -10,20 +11,33 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class SlowExtent extends AbstractDelegateExtent {
|
||||
private final long sleep;
|
||||
private long THRESHOLD = 50 * 1000000; // 1 tick
|
||||
private final long nanos;
|
||||
private long increment;
|
||||
|
||||
public SlowExtent(Extent extent, long sleep) {
|
||||
public SlowExtent(Extent extent, long nanos) {
|
||||
super(extent);
|
||||
this.sleep = sleep;
|
||||
this.nanos = nanos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
if (!Fawe.isMainThread()) try {
|
||||
Thread.sleep(sleep);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
||||
delay();
|
||||
return super.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
public void delay() {
|
||||
increment += nanos;
|
||||
if (increment >= THRESHOLD) {
|
||||
long wait = increment / 1000000;
|
||||
if (!Fawe.isMainThread()) {
|
||||
try {
|
||||
Thread.sleep(wait);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
increment -= wait * 1000000;
|
||||
}
|
||||
return super.setBlock(location, block);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.boydti.fawe.object.extent;
|
||||
|
||||
import com.sk89q.worldedit.extent.PassthroughExtent;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
@ -10,7 +11,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class TemporalExtent extends AbstractDelegateExtent {
|
||||
public class TemporalExtent extends PassthroughExtent {
|
||||
private int x, y, z = Integer.MAX_VALUE;
|
||||
private BlockStateHolder<?> block = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
|
Reference in New Issue
Block a user