Cleanup overlay/underlay mask.

This commit is contained in:
Wizjany 2011-08-13 00:29:28 -04:00
parent af2429467d
commit 9d753c8692
2 changed files with 41 additions and 99 deletions

View File

@ -487,82 +487,36 @@ public class WorldEdit {
|| component.equalsIgnoreCase("#region")
|| component.equalsIgnoreCase("#sel")) {
current = new RegionMask(session.getSelection(player.getWorld()));
}
else {
} else {
throw new UnknownItemException(component);
}
}
else if (component.charAt(0) == '>') {
} else if (component.charAt(0) == '>'
|| component.charAt(0) == '<') {
LocalWorld world = player.getWorld();
boolean over = component.charAt(0) == '>';
Set<Integer> set = new HashSet<Integer>();
String ids = component.replaceAll(">", "");
if(ids.equalsIgnoreCase("*")){
current = new UnderOverlayMask(set,true,true);
}
else{
String[] split = ids.split(",");
for(String sid :split){
String ids = component.replaceAll(">", "").replaceAll("<", "");
if (!(ids.equals("*") || ids.equals(""))) {
for (String sid : ids.split(",")) {
try {
int pid = Integer.parseInt(sid);
if (!world.isValidBlockType(pid)) {
throw new UnknownItemException(sid);
}
else{
set.add(pid);
}
} catch (NumberFormatException e) {
BlockType type = BlockType.lookup(sid);
int id = type.getID();
if (!world.isValidBlockType(id)) {
throw new UnknownItemException(sid);
}
else{
set.add(id);
}
}
current = new UnderOverlayMask(set, true, false);
}
}
}
else if (component.charAt(0) == '<') {
LocalWorld world = player.getWorld();
Set<Integer> set = new HashSet<Integer>();
String ids = component.replaceAll("<", "");
if(ids.equalsIgnoreCase("*")){
current = new UnderOverlayMask(set,false,true);
}
else{
String[] split = ids.split(",");
for(String sid :split){
try{
int pid = Integer.parseInt(sid);
if(!world.isValidBlockType(pid)){
throw new UnknownItemException(sid);
}
else{
set.add(pid);
}
}catch(NumberFormatException e){
BlockType type = BlockType.lookup(sid);
int id = type.getID();
if(!world.isValidBlockType(id)){
throw new UnknownItemException(sid);
}
else{
set.add(id);
}
}
current = new UnderOverlayMask(set, false, false);
}
}
}
else {
current = new UnderOverlayMask(set, over);
} else {
if (component.charAt(0) == '!' && component.length() > 1) {
current = new InvertedBlockTypeMask(
getBlockIDs(player, component.substring(1), true));

View File

@ -1,4 +1,3 @@
package com.sk89q.worldedit.masks;
import java.util.HashSet;
@ -6,41 +5,30 @@ import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
/**
*
* @author 1337
*/
public class UnderOverlayMask implements Mask {
boolean overlay;
boolean wildcard;
Set<Integer> ids = new HashSet<Integer>();
public UnderOverlayMask(Set<Integer> ids,boolean overlay,boolean wildcard){
public UnderOverlayMask(Set<Integer> ids, boolean overlay) {
addAll(ids);
this.overlay = overlay;
this.wildcard = wildcard;
}
public void addAll(Set<Integer> ids){
this.ids.addAll(ids);
}
public boolean matches(EditSession editSession, Vector pos) {
if(!wildcard){
int id = editSession.getBlock(pos.setY(pos.getBlockY() + (overlay ? -1 : 1))).getType();
if(overlay){
return ids.contains(id);
return ids.isEmpty() ? id != BlockID.AIR : ids.contains(id);
}
else if(!overlay){
return ids.contains(id);
}
}
else{
return (overlay ? editSession.getBlock(pos.setY(pos.getBlockY() + 1)).getType() != 0: editSession.getBlock(pos.setY(pos.getBlockY() - 1)).getType() != 0);
}
return false;
}
}