3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Deprecate expand/contract(Vector) in favor of varargs versions

This keeps things simpler by not dealing with redundant implementations
for single change and multiple changes.
This also let regions handle related changes in a more efficient way
(for example recalculates region components only when needed).
Dieser Commit ist enthalten in:
aumgn 2012-03-14 11:21:41 +01:00 committet von TomyLobo
Ursprung 1359a7fada
Commit 8506bb437e
6 geänderte Dateien mit 111 neuen und 96 gelöschten Zeilen

Datei anzeigen

@ -259,8 +259,7 @@ public class RegionCommands {
if (args.hasFlag('s')) {
try {
Region region = session.getSelection(player.getWorld());
region.expand(dir.multiply(count));
region.contract(dir.multiply(count));
region.shift(dir.multiply(count));
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
@ -303,8 +302,7 @@ public class RegionCommands {
final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint());
final Vector shiftVector = dir.multiply(count * (Math.abs(dir.dot(size))+1));
region.expand(shiftVector);
region.contract(shiftVector);
region.shift(shiftVector);
session.getRegionSelector(player.getWorld()).learnChanges();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);

Datei anzeigen

@ -266,6 +266,7 @@ public class SelectionCommands {
max = 3
)
@CommandPermissions("worldedit.selection.expand")
@SuppressWarnings("deprecation")
public void expand(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
@ -278,8 +279,9 @@ public class SelectionCommands {
Region region = session.getSelection(player.getWorld());
try {
int oldSize = region.getArea();
region.expand(new Vector(0, (player.getWorld().getMaxY() + 1), 0));
region.expand(new Vector(0, -(player.getWorld().getMaxY() + 1), 0));
region.expand(
new Vector(0, (player.getWorld().getMaxY() + 1), 0),
new Vector(0, -(player.getWorld().getMaxY() + 1), 0));
session.getRegionSelector(player.getWorld()).learnChanges();
int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
@ -341,6 +343,7 @@ public class SelectionCommands {
max = 3
)
@CommandPermissions("worldedit.selection.contract")
@SuppressWarnings("deprecation")
public void contract(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {

Datei anzeigen

@ -52,16 +52,14 @@ public abstract class AbstractRegion implements Region {
this.world = world;
}
public void expand(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
expand(change);
}
@Deprecated
public void expand(Vector change) throws RegionOperationException {
expand(new Vector[] { change });
}
public void contract(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
contract(change);
}
@Deprecated
public void contract(Vector change) throws RegionOperationException {
contract(new Vector[] { change });
}
public void shift(Vector change) throws RegionOperationException {

Datei anzeigen

@ -141,7 +141,8 @@ public class CuboidRegion extends AbstractRegion {
*
* @param change
*/
public void expand(Vector change) {
public void expand(Vector... changes) {
for (Vector change : changes) {
if (change.getX() > 0) {
if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
pos1 = pos1.add(new Vector(change.getX(), 0, 0));
@ -183,6 +184,7 @@ public class CuboidRegion extends AbstractRegion {
pos2 = pos2.add(new Vector(0, 0, change.getZ()));
}
}
}
recalculate();
}
@ -192,7 +194,8 @@ public class CuboidRegion extends AbstractRegion {
*
* @param change
*/
public void contract(Vector change) {
public void contract(Vector... changes) {
for (Vector change : changes) {
if (change.getX() < 0) {
if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) {
pos1 = pos1.add(new Vector(change.getX(), 0, 0));
@ -234,6 +237,7 @@ public class CuboidRegion extends AbstractRegion {
pos2 = pos2.add(new Vector(0, 0, change.getZ()));
}
}
}
recalculate();
}

Datei anzeigen

@ -269,17 +269,21 @@ public class Polygonal2DRegion extends AbstractRegion {
*
* @param change
*/
public void expand(Vector change) throws RegionOperationException {
public void expand(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be expanded vertically.");
}
}
for (Vector change : changes) {
int changeY = change.getBlockY();
if (changeY > 0) {
maxY += changeY;
} else {
minY += changeY;
}
}
recalculate();
}
@ -288,17 +292,21 @@ public class Polygonal2DRegion extends AbstractRegion {
*
* @param change
*/
public void contract(Vector change) throws RegionOperationException {
public void contract(Vector... changes) throws RegionOperationException {
for (Vector change : changes) {
if (change.getBlockX() != 0 || change.getBlockZ() != 0) {
throw new RegionOperationException("Polygons can only be contracted vertically.");
}
}
for (Vector change : changes) {
int changeY = change.getBlockY();
if (changeY > 0) {
minY += changeY;
} else {
maxY += changeY;
}
}
recalculate();
}

Datei anzeigen

@ -75,9 +75,11 @@ public interface Region extends Iterable<BlockVector> {
/**
* Expand the region.
*
* @deprecated will be seamlessly replaced by {@link #expand(Vector...)
* @param change
* @throws RegionOperationException
*/
@Deprecated
public void expand(Vector change) throws RegionOperationException;
/**
@ -91,9 +93,11 @@ public interface Region extends Iterable<BlockVector> {
/**
* Contract the region.
*
* @deprecated will be seamlessly replaced by {@link #contract(Vector...)
* @param change
* @throws RegionOperationException
*/
@Deprecated
public void contract(Vector change) throws RegionOperationException;
/**