Created pattern, mask, and block registries.

Deprecated getBlock, getBlockPattern, and so-on in WorldEdit.
This commit is contained in:
sk89q
2014-04-03 17:52:53 -07:00
parent 589c3e9629
commit 9d08f266bf
32 changed files with 2192 additions and 478 deletions

View File

@ -0,0 +1,116 @@
/*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session.request;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld;
import javax.annotation.Nullable;
/**
* Describes the current request using a {@link ThreadLocal}.
*/
public final class Request {
private static final ThreadLocal<Request> threadLocal =
new ThreadLocal<Request>() {
@Override protected Request initialValue() {
return new Request();
}
};
private @Nullable LocalWorld world;
private @Nullable LocalSession session;
private @Nullable EditSession editSession;
private Request() {
}
/**
* Get the request world.
*
* @return the world, which may be null
*/
public @Nullable LocalWorld getWorld() {
return world;
}
/**
* Set the request world.
*
* @param world the world, which may be null
*/
public void setWorld(@Nullable LocalWorld world) {
this.world = world;
}
/**
* Get the request session.
*
* @return the session, which may be null
*/
public @Nullable LocalSession getSession() {
return session;
}
/**
* Get the request session.
*
* @param session the session, which may be null
*/
public void setSession(@Nullable LocalSession session) {
this.session = session;
}
/**
* Get the {@link EditSession}.
*
* @return the edit session, which may be null
*/
public @Nullable EditSession getEditSession() {
return editSession;
}
/**
* Set the {@link EditSession}.
*
* @param editSession the edit session, which may be null
*/
public void setEditSession(@Nullable EditSession editSession) {
this.editSession = editSession;
}
/**
* Get the current request, which is specific to the current thread.
*
* @return the current request
*/
public static Request request() {
return threadLocal.get();
}
/**
* Reset the current request and clear all fields.
*/
public static void reset() {
threadLocal.remove();
}
}

View File

@ -0,0 +1,150 @@
/*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session.request;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.regions.NullRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionOperationException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* A region that mirrors the current selection according to the current
* {@link LocalSession} and {@link LocalWorld} set on the current
* {@link Request}.
* </p>
* If a selection cannot be taken, then the selection will be assumed to be
* that of a {@link NullRegion}.
*/
public class RequestSelection implements Region {
/**
* Get the delegate region.
*
* @return the delegate region
*/
protected Region getRegion() {
LocalSession session = Request.request().getSession();
LocalWorld world = Request.request().getWorld();
if (session != null && world != null) {
try {
return session.getSelection(world);
} catch (IncompleteRegionException ignored) {
}
}
return new NullRegion();
}
@Override
public Vector getMinimumPoint() {
return getRegion().getMinimumPoint();
}
@Override
public Vector getMaximumPoint() {
return getRegion().getMaximumPoint();
}
@Override
public Vector getCenter() {
return getRegion().getCenter();
}
@Override
public int getArea() {
return getRegion().getArea();
}
@Override
public int getWidth() {
return getRegion().getWidth();
}
@Override
public int getHeight() {
return getRegion().getHeight();
}
@Override
public int getLength() {
return getRegion().getLength();
}
@Override
public void expand(Vector... changes) throws RegionOperationException {
getRegion().expand(changes);
}
@Override
public void contract(Vector... changes) throws RegionOperationException {
getRegion().contract(changes);
}
@Override
public void shift(Vector change) throws RegionOperationException {
getRegion().shift(change);
}
@Override
public boolean contains(Vector pt) {
return getRegion().contains(pt);
}
@Override
public Set<Vector2D> getChunks() {
return getRegion().getChunks();
}
@Override
public Set<Vector> getChunkCubes() {
return getRegion().getChunkCubes();
}
@Override
public LocalWorld getWorld() {
return getRegion().getWorld();
}
@Override
public void setWorld(LocalWorld world) {
getRegion().setWorld(world);
}
@Override
public Region clone() {
return this;
}
@Override
public List<BlockVector2D> polygonize(int maxPoints) {
return getRegion().polygonize(maxPoints);
}
@Override
public Iterator<BlockVector> iterator() {
return getRegion().iterator();
}
}