mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
fix: make IdMask thread-safe (#2361)
This commit is contained in:
parent
cdd546ee5e
commit
f65c4743bd
@ -5,9 +5,11 @@ import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
|||||||
import com.sk89q.worldedit.function.mask.Mask;
|
import com.sk89q.worldedit.function.mask.Mask;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class IdMask extends AbstractExtentMask implements ResettableMask {
|
public class IdMask extends AbstractExtentMask implements ResettableMask {
|
||||||
|
|
||||||
private transient int id = -1;
|
private final AtomicInteger id = new AtomicInteger(-1);
|
||||||
|
|
||||||
public IdMask(Extent extent) {
|
public IdMask(Extent extent) {
|
||||||
super(extent);
|
super(extent);
|
||||||
@ -15,12 +17,9 @@ public class IdMask extends AbstractExtentMask implements ResettableMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Extent extent, BlockVector3 vector) {
|
public boolean test(Extent extent, BlockVector3 vector) {
|
||||||
if (id != -1) {
|
int blockID = extent.getBlock(vector).getInternalBlockTypeId();
|
||||||
return extent.getBlock(vector).getInternalBlockTypeId() == id;
|
int testId = id.compareAndExchange(-1, blockID);
|
||||||
} else {
|
return blockID == testId || testId == -1;
|
||||||
id = extent.getBlock(vector).getInternalBlockTypeId();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,12 +29,12 @@ public class IdMask extends AbstractExtentMask implements ResettableMask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.id = -1;
|
this.id.set(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mask copy() {
|
public Mask copy() {
|
||||||
return new IdMask(getExtent());
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user