mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-24 10:17:39 +00:00
Cleanup and refactorings
This commit is contained in:
parent
feee529095
commit
7812d8f5f8
@ -176,7 +176,7 @@ public class WorldEdit {
|
|||||||
commands.register(UtilityCommands.class);
|
commands.register(UtilityCommands.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Gets the LocalSession for a player name if it exists
|
* Gets the LocalSession for a player name if it exists
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
@ -460,22 +460,23 @@ public class WorldEdit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of blocks as a set. This returns a Pattern.
|
* Returns a Pattern corresponding to the specified pattern string,
|
||||||
|
* as given by the player on the command line.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param list
|
* @param patternString
|
||||||
* @return pattern
|
* @return pattern
|
||||||
* @throws UnknownItemException
|
* @throws UnknownItemException
|
||||||
* @throws DisallowedItemException
|
* @throws DisallowedItemException
|
||||||
*/
|
*/
|
||||||
public Pattern getBlockPattern(LocalPlayer player, String list)
|
public Pattern getBlockPattern(LocalPlayer player, String patternString)
|
||||||
throws UnknownItemException, DisallowedItemException {
|
throws UnknownItemException, DisallowedItemException {
|
||||||
|
|
||||||
String[] items = list.split(",");
|
String[] items = patternString.split(",");
|
||||||
|
|
||||||
// Handle special block pattern types
|
// Handle special block pattern types
|
||||||
if (list.charAt(0) == '#') {
|
if (patternString.charAt(0) == '#') {
|
||||||
if (list.equals("#clipboard") || list.equals("#copy")) {
|
if (patternString.equals("#clipboard") || patternString.equals("#copy")) {
|
||||||
LocalSession session = getSession(player);
|
LocalSession session = getSession(player);
|
||||||
CuboidClipboard clipboard;
|
CuboidClipboard clipboard;
|
||||||
|
|
||||||
@ -488,7 +489,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
return new ClipboardPattern(clipboard);
|
return new ClipboardPattern(clipboard);
|
||||||
} else {
|
} else {
|
||||||
throw new UnknownItemException(list);
|
throw new UnknownItemException(patternString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,71 +533,82 @@ public class WorldEdit {
|
|||||||
*/
|
*/
|
||||||
public Mask getBlockMask(LocalPlayer player, LocalSession session,
|
public Mask getBlockMask(LocalPlayer player, LocalSession session,
|
||||||
String maskString) throws WorldEditException {
|
String maskString) throws WorldEditException {
|
||||||
Mask mask = null;
|
List<Mask> masks = new ArrayList<Mask>();
|
||||||
|
|
||||||
for (String component : maskString.split(" ")) {
|
for (String component : maskString.split(" ")) {
|
||||||
Mask current = null;
|
|
||||||
if (component.length() == 0) {
|
if (component.length() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.charAt(0) == '#') {
|
Mask current = getBlockMaskComponent(player, session, masks, component);
|
||||||
|
|
||||||
|
masks.add(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (masks.size()) {
|
||||||
|
case 0:
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
return masks.get(0);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return new CombinedMask(masks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mask getBlockMaskComponent(LocalPlayer player, LocalSession session, List<Mask> masks, String component) throws IncompleteRegionException, UnknownItemException, DisallowedItemException {
|
||||||
|
final char firstChar = component.charAt(0);
|
||||||
|
switch (firstChar) {
|
||||||
|
case '#':
|
||||||
if (component.equalsIgnoreCase("#existing")) {
|
if (component.equalsIgnoreCase("#existing")) {
|
||||||
current = new ExistingBlockMask();
|
return new ExistingBlockMask();
|
||||||
} else if (component.equalsIgnoreCase("#selection")
|
} else if (component.equalsIgnoreCase("#selection")
|
||||||
|| component.equalsIgnoreCase("#region")
|
|| component.equalsIgnoreCase("#region")
|
||||||
|| component.equalsIgnoreCase("#sel")) {
|
|| component.equalsIgnoreCase("#sel")) {
|
||||||
current = new RegionMask(session.getSelection(player.getWorld()));
|
return new RegionMask(session.getSelection(player.getWorld()));
|
||||||
} else {
|
} else {
|
||||||
throw new UnknownItemException(component);
|
throw new UnknownItemException(component);
|
||||||
}
|
}
|
||||||
} 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(">", "").replaceAll("<", "");
|
|
||||||
|
|
||||||
if (!(ids.equals("*") || ids.equals(""))) {
|
case '>':
|
||||||
for (String sid : ids.split(",")) {
|
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 {
|
try {
|
||||||
int pid = Integer.parseInt(sid);
|
final int pid = Integer.parseInt(sid);
|
||||||
if (!world.isValidBlockType(pid)) {
|
if (!world.isValidBlockType(pid)) {
|
||||||
throw new UnknownItemException(sid);
|
throw new UnknownItemException(sid);
|
||||||
}
|
}
|
||||||
set.add(pid);
|
ids.add(pid);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
BlockType type = BlockType.lookup(sid);
|
final BlockType type = BlockType.lookup(sid);
|
||||||
int id = type.getID();
|
final int id = type.getID();
|
||||||
if (!world.isValidBlockType(id)) {
|
if (!world.isValidBlockType(id)) {
|
||||||
throw new UnknownItemException(sid);
|
throw new UnknownItemException(sid);
|
||||||
}
|
}
|
||||||
set.add(id);
|
ids.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
current = new UnderOverlayMask(set, over);
|
|
||||||
} else {
|
|
||||||
if (component.charAt(0) == '!' && component.length() > 1) {
|
|
||||||
current = new InvertedBlockTypeMask(
|
|
||||||
getBlockIDs(player, component.substring(1), true));
|
|
||||||
} else {
|
|
||||||
current = new BlockTypeMask(getBlockIDs(player, component, true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mask == null) {
|
return new UnderOverlayMask(ids, over);
|
||||||
mask = current;
|
|
||||||
} else if (mask instanceof CombinedMask) {
|
case '!':
|
||||||
((CombinedMask) mask).add(current);
|
if (component.length() > 1) {
|
||||||
} else {
|
return new InvertedBlockTypeMask(getBlockIDs(player, component.substring(1), true));
|
||||||
mask = new CombinedMask(mask);
|
}
|
||||||
((CombinedMask) mask).add(current);
|
|
||||||
|
default:
|
||||||
|
return new BlockTypeMask(getBlockIDs(player, component, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Get a list of blocks as a set.
|
* Get a list of blocks as a set.
|
||||||
*
|
*
|
||||||
|
@ -35,6 +35,10 @@ public class CombinedMask implements Mask {
|
|||||||
masks.add(mask);
|
masks.add(mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CombinedMask(List<Mask> masks) {
|
||||||
|
masks.addAll(masks);
|
||||||
|
}
|
||||||
|
|
||||||
public void add(Mask mask) {
|
public void add(Mask mask) {
|
||||||
masks.add(mask);
|
masks.add(mask);
|
||||||
}
|
}
|
||||||
@ -56,5 +60,4 @@ public class CombinedMask implements Mask {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user