Merge remote-tracking branch 'origin/master' into mapping

This commit is contained in:
sk89q
2014-05-01 18:03:53 -07:00
16 changed files with 534 additions and 116 deletions

View File

@ -625,10 +625,6 @@ public class LocalSession {
}
public void handleCUIInitializationMessage(String text) {
if (hasCUISupport()) {
return;
}
String[] split = text.split("\\|");
if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message
setCUISupport(true);

View File

@ -45,7 +45,8 @@ public abstract class LocalWorld extends AbstractWorld {
public static final int ANIMALS = 1 << 2;
public static final int GOLEMS = 1 << 3;
public static final int AMBIENT = 1 << 4;
public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT;
public static final int TAGGED = 1 << 5;
public static final int FRIENDLY = PETS | NPCS | ANIMALS | GOLEMS | AMBIENT | TAGGED;
public static final int WITH_LIGHTNING = 1 << 20;
private KillFlags() {

View File

@ -0,0 +1,80 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.bukkit.selections;
import com.sk89q.worldedit.regions.selector.CylinderRegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CylinderRegion;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* A selection representing a {@link CylinderRegion}
*/
public class CylinderSelection extends RegionSelection {
private CylinderRegion cylRegion;
public CylinderSelection(World world, RegionSelector selector, CylinderRegion region) {
super(world, selector, region);
this.cylRegion = region;
}
public CylinderSelection(World world, BlockVector2D center, BlockVector2D radius, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());
maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
// Create and set up new selector
CylinderRegionSelector sel = new CylinderRegionSelector(lWorld, center, radius, minY, maxY);
// set up selection
cylRegion = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cylRegion);
}
/**
* Returns the center vector of the cylinder
*
* @return the center
*/
public BlockVector2D getCenter() {
return cylRegion.getCenter().toVector2D().toBlockVector2D();
}
/**
* Returns the radius vector of the cylinder
*
* @return the radius
*/
public BlockVector2D getRadius() {
return cylRegion.getRadius().toBlockVector2D();
}
}

View File

@ -281,6 +281,7 @@ public class BrushCommands {
flags.or(KillFlags.GOLEMS , flagString.contains("g"), "worldedit.butcher.golems");
flags.or(KillFlags.ANIMALS , flagString.contains("a"), "worldedit.butcher.animals");
flags.or(KillFlags.AMBIENT , flagString.contains("b"), "worldedit.butcher.ambient");
flags.or(KillFlags.TAGGED , flagString.contains("t"), "worldedit.butcher.tagged");
flags.or(KillFlags.WITH_LIGHTNING, flagString.contains("l"), "worldedit.butcher.lightning");
}
BrushTool tool = session.getBrushTool(player.getItemInHand());

View File

@ -19,27 +19,17 @@
package com.sk89q.worldedit.command;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldedit.world.DataException;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.Console;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.FilenameResolutionException;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.schematic.SchematicFormat;
/**
* Commands related to schematics
*
@ -181,6 +171,37 @@ public class SchematicCommands {
}
}
@Command(
aliases = { "delete", "d" },
usage = "<filename>",
desc = "Delete a schematic from the schematic list",
help = "Delete a schematic from the schematic list",
min = 1,
max = 1
)
@CommandPermissions("worldedit.schematic.delete")
public void delete(CommandContext args, LocalSession session, LocalPlayer player,
EditSession editSession) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
String filename = args.getString(0);
File dir = we.getWorkingDirectoryFile(config.saveDir);
File f = we.getSafeSaveFile(player, dir, filename, "schematic", "schematic");
if (!f.exists()) {
player.printError("Schematic " + filename + " does not exist!");
return;
}
if (!f.delete()) {
player.printError("Deletion of " + filename + " failed! Maybe it is read-only.");
return;
}
player.print(filename + " has been deleted.");
}
@Command(
aliases = {"formats", "listformats", "f"},
desc = "List available schematic formats",
@ -234,7 +255,6 @@ public class SchematicCommands {
if (files == null) {
throw new FilenameResolutionException(dir.getPath(), "Schematics directory invalid or not found.");
}
StringBuilder build = new StringBuilder("Available schematics (Filename (Format)): ");
final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0;
// cleanup file list
@ -253,11 +273,27 @@ public class SchematicCommands {
}
});
player.print("Available schematics (Filename (Format)):");
player.print(listFiles("", files));
}
private String listFiles(String prefix, File[] files) {
StringBuilder build = new StringBuilder();
for (File file : files) {
if (file.isDirectory()) {
build.append(listFiles(prefix + file.getName() + "/", file.listFiles()));
continue;
}
if (!file.isFile()) {
continue;
}
build.append("\n\u00a79");
SchematicFormat format = SchematicFormat.getFormat(file);
build.append(file.getName()).append(": ").append(format == null ? "Unknown" : format.getName());
build.append(prefix).append(file.getName())
.append(": ").append(format == null ? "Unknown" : format.getName());
}
player.print(build.toString());
return build.toString();
}
}

View File

@ -346,7 +346,7 @@ public class UtilityCommands {
@Command(
aliases = { "butcher" },
usage = "[radius]",
flags = "plangbf",
flags = "plangbtf",
desc = "Kill all or nearby mobs",
help =
"Kills nearby mobs, based on radius, if none is given uses default in configuration.\n" +
@ -356,6 +356,7 @@ public class UtilityCommands {
" -g also kills Golems.\n" +
" -a also kills animals.\n" +
" -b also kills ambient mobs.\n" +
" -t also kills mobs with name tags.\n" +
" -f compounds all previous flags.\n" +
" -l strikes lightning on each killed mob.",
min = 0,
@ -391,6 +392,7 @@ public class UtilityCommands {
flags.or(KillFlags.GOLEMS , args.hasFlag('g'), "worldedit.butcher.golems");
flags.or(KillFlags.ANIMALS , args.hasFlag('a'), "worldedit.butcher.animals");
flags.or(KillFlags.AMBIENT , args.hasFlag('b'), "worldedit.butcher.ambient");
flags.or(KillFlags.TAGGED , args.hasFlag('t'), "worldedit.butcher.tagged");
flags.or(KillFlags.WITH_LIGHTNING, args.hasFlag('l'), "worldedit.butcher.lightning");
// If you add flags here, please add them to com.sk89q.worldedit.commands.BrushCommands.butcherBrush() as well

View File

@ -0,0 +1,64 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.math.geom;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.Vector2D;
import java.util.ArrayList;
import java.util.List;
/**
* Helper method for anything related to polygons.
*/
public final class Polygons {
private Polygons() {
}
/**
* Calculates the polygon shape of a cylinder which can then be used for e.g. intersection detection.
*
* @param center the center point of the cylinder
* @param radius the radius of the cylinder
* @param maxPoints max points to be used for the calculation
* @return a list of {@link BlockVector2D} which resemble the shape as a polygon
*/
public static List<BlockVector2D> polygonizeCylinder(Vector2D center, Vector2D radius, int maxPoints) {
int nPoints = (int) Math.ceil(Math.PI*radius.length());
// These strange semantics for maxPoints are copied from the selectSecondary method.
if (maxPoints >= 0 && nPoints >= maxPoints) {
nPoints = maxPoints - 1;
}
final List<BlockVector2D> points = new ArrayList<BlockVector2D>(nPoints);
for (int i = 0; i < nPoints; ++i) {
double angle = i * (2.0 * Math.PI) / nPoints;
final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle));
final BlockVector2D blockVector2D = pos.multiply(radius).add(center).toBlockVector2D();
points.add(blockVector2D);
}
return points;
}
}

View File

@ -20,11 +20,11 @@
package com.sk89q.worldedit.regions;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.math.geom.Polygons;
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
import com.sk89q.worldedit.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -375,22 +375,6 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
@Override
public List<BlockVector2D> polygonize(int maxPoints) {
final Vector2D radius = getRadius();
int nPoints = (int) Math.ceil(Math.PI*radius.length());
// These strange semantics for maxPoints are copied from the selectSecondary method.
if (maxPoints >= 0 && nPoints >= maxPoints) {
nPoints = maxPoints - 1;
}
final List<BlockVector2D> points = new ArrayList<BlockVector2D>(nPoints);
for (int i = 0; i < nPoints; ++i) {
double angle = i * (2.0 * Math.PI) / nPoints;
final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle));
final BlockVector2D blockVector2D = pos.multiply(radius).add(center).toBlockVector2D();
points.add(blockVector2D);
}
return points;
return Polygons.polygonizeCylinder(center, radius, maxPoints);
}
}

View File

@ -206,8 +206,6 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
Collection<Vector> vertices = region.getVertices();
Collection<Triangle> triangles = region.getTriangles();
player.dispatchCUIEvent(new SelectionShapeEvent(getTypeID()));
Map<Vector, Integer> vertexIds = new HashMap<Vector, Integer>(vertices.size());
int lastVertexId = -1;
for (Vector vertex : vertices) {
@ -234,8 +232,6 @@ public class ConvexPolyhedralRegionSelector extends com.sk89q.worldedit.regions.
if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
} else {
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
}
}

View File

@ -237,8 +237,6 @@ public class CylinderRegionSelector extends com.sk89q.worldedit.regions.Cylinder
if (isDefined()) {
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
} else {
session.dispatchCUIEvent(player, new SelectionShapeEvent(getLegacyTypeID()));
}
}

View File

@ -45,9 +45,7 @@ public class MCEditSchematicFormat extends SchematicFormat {
super("MCEdit", "mcedit", "mce");
}
@Override
public CuboidClipboard load(File file) throws IOException, DataException {
FileInputStream stream = new FileInputStream(file);
public CuboidClipboard load(InputStream stream) throws IOException, DataException {
NBTInputStream nbtStream = new NBTInputStream(
new GZIPInputStream(stream));
@ -186,6 +184,11 @@ public class MCEditSchematicFormat extends SchematicFormat {
return clipboard;
}
@Override
public CuboidClipboard load(File file) throws IOException, DataException {
return load(new FileInputStream(file));
}
@Override
public void save(CuboidClipboard clipboard, File file) throws IOException, DataException {
int width = clipboard.getWidth();