mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-02 02:47:11 +00:00
Implement InvertedMask & UnderOverlayMask as decorators
This commit is contained in:
parent
eb14efd2df
commit
30ed049918
@ -614,31 +614,13 @@ public class WorldEdit {
|
||||
|
||||
case '>':
|
||||
case '<':
|
||||
final LocalWorld world = player.getWorld();
|
||||
final boolean over = firstChar == '>';
|
||||
final String idString = component.substring(1);
|
||||
final Set<Integer> ids = new HashSet<Integer>();
|
||||
|
||||
if (!(idString.equals("*") || idString.equals(""))) {
|
||||
for (String sid : idString.split(",")) {
|
||||
try {
|
||||
final int pid = Integer.parseInt(sid);
|
||||
if (!world.isValidBlockType(pid)) {
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
ids.add(pid);
|
||||
} catch (NumberFormatException e) {
|
||||
final BlockType type = BlockType.lookup(sid);
|
||||
final int id = type.getID();
|
||||
if (!world.isValidBlockType(id)) {
|
||||
throw new UnknownItemException(sid);
|
||||
}
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
Mask submask;
|
||||
if (component.length() > 1) {
|
||||
submask = getBlockMaskComponent(player, session, masks, component.substring(1));
|
||||
} else {
|
||||
submask = new ExistingBlockMask();
|
||||
}
|
||||
|
||||
return new UnderOverlayMask(ids, over);
|
||||
return new UnderOverlayMask(submask, firstChar == '>');
|
||||
|
||||
case '$':
|
||||
Set<BiomeType> biomes = new HashSet<BiomeType>();
|
||||
@ -651,7 +633,7 @@ public class WorldEdit {
|
||||
|
||||
case '!':
|
||||
if (component.length() > 1) {
|
||||
return new InvertedBlockTypeMask(getBlockIDs(player, component.substring(1), true));
|
||||
return new InvertedMask(getBlockMaskComponent(player, session, masks, component.substring(1)));
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.worldedit.Vector;
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
@Deprecated
|
||||
public class InvertedBlockTypeMask extends BlockTypeMask {
|
||||
public InvertedBlockTypeMask() {
|
||||
}
|
||||
|
25
src/main/java/com/sk89q/worldedit/masks/InvertedMask.java
Normal file
25
src/main/java/com/sk89q/worldedit/masks/InvertedMask.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.sk89q.worldedit.masks;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
public class InvertedMask implements Mask {
|
||||
|
||||
private Mask mask;
|
||||
|
||||
public InvertedMask(Mask mask) {
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
|
||||
mask.prepare(session, player, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(EditSession editSession, Vector pos) {
|
||||
return !mask.matches(editSession, pos);
|
||||
}
|
||||
|
||||
}
|
@ -19,14 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.masks;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -34,24 +32,37 @@ import com.sk89q.worldedit.blocks.BlockID;
|
||||
*/
|
||||
public class UnderOverlayMask implements Mask {
|
||||
|
||||
boolean overlay;
|
||||
Set<Integer> ids = new HashSet<Integer>();
|
||||
private int yMod;
|
||||
private Mask mask;
|
||||
|
||||
@Deprecated
|
||||
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
|
||||
addAll(ids);
|
||||
this.overlay = overlay;
|
||||
this(new BlockTypeMask(ids), overlay);
|
||||
}
|
||||
|
||||
public UnderOverlayMask(Mask mask, boolean overlay) {
|
||||
this.yMod = overlay ? -1 : 1;
|
||||
this.mask = mask;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addAll(Set<Integer> ids) {
|
||||
this.ids.addAll(ids);
|
||||
if (mask instanceof BlockTypeMask) {
|
||||
BlockTypeMask blockTypeMask = (BlockTypeMask) mask;
|
||||
for (Integer id : ids) {
|
||||
blockTypeMask.add(id);
|
||||
}
|
||||
} else if (mask instanceof ExistingBlockMask) {
|
||||
mask = new BlockTypeMask(ids);
|
||||
}
|
||||
}
|
||||
|
||||
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
|
||||
mask.prepare(session, player, target);
|
||||
}
|
||||
|
||||
public boolean matches(EditSession editSession, Vector pos) {
|
||||
int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 : 1))).getType();
|
||||
return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id);
|
||||
return mask.matches(editSession, pos.add(0, yMod, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user