2014-04-04 00:52:53 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2014-04-04 00:52:53 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-04 00:52:53 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.extension.input;
|
|
|
|
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
2014-07-09 00:39:33 +00:00
|
|
|
import com.sk89q.worldedit.extension.factory.MaskFactory;
|
2014-04-05 00:54:14 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2014-04-04 00:52:53 +00:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contains contextual information that may be useful when constructing
|
2014-07-09 00:39:33 +00:00
|
|
|
* objects from a registry (such as {@link MaskFactory}).
|
2014-04-04 00:52:53 +00:00
|
|
|
* </p>
|
|
|
|
* By default, {@link #isRestricted()} will return true.
|
|
|
|
*/
|
|
|
|
public class ParserContext {
|
|
|
|
|
|
|
|
private @Nullable Extent extent;
|
|
|
|
private @Nullable LocalSession session;
|
2014-04-05 09:59:38 +00:00
|
|
|
private @Nullable World world;
|
2014-04-05 00:54:14 +00:00
|
|
|
private @Nullable Actor actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
private boolean restricted = true;
|
|
|
|
private boolean preferringWildcard;
|
|
|
|
|
2014-07-07 01:10:30 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*/
|
|
|
|
public ParserContext() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a copy of another instance.
|
|
|
|
*
|
|
|
|
* @param other the other instance
|
|
|
|
*/
|
|
|
|
public ParserContext(ParserContext other) {
|
|
|
|
setExtent(other.getExtent());
|
|
|
|
setSession(other.getSession());
|
|
|
|
setWorld(other.getWorld());
|
|
|
|
setActor(other.getActor());
|
|
|
|
setRestricted(other.isRestricted());
|
|
|
|
setPreferringWildcard(other.isPreferringWildcard());
|
|
|
|
}
|
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* Get the {@link Extent} set on this context.
|
|
|
|
*
|
|
|
|
* @return an extent
|
|
|
|
*/
|
|
|
|
public @Nullable Extent getExtent() {
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the extent.
|
|
|
|
*
|
|
|
|
* @param extent an extent, or null if none is available
|
|
|
|
*/
|
|
|
|
public void setExtent(@Nullable Extent extent) {
|
|
|
|
this.extent = extent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@link LocalSession}.
|
|
|
|
*
|
|
|
|
* @return a session
|
|
|
|
*/
|
|
|
|
public @Nullable LocalSession getSession() {
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the session.
|
|
|
|
*
|
|
|
|
* @param session a session, or null if none is available
|
|
|
|
*/
|
|
|
|
public void setSession(@Nullable LocalSession session) {
|
|
|
|
this.session = session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-05 09:59:38 +00:00
|
|
|
* Get the {@link World} set on this context.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
|
|
|
* @return a world
|
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public @Nullable World getWorld() {
|
2014-04-04 00:52:53 +00:00
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the world.
|
|
|
|
*
|
|
|
|
* @param world a world, or null if none is available
|
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public void setWorld(@Nullable World world) {
|
2014-04-04 00:52:53 +00:00
|
|
|
this.world = world;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-05 00:54:14 +00:00
|
|
|
* Get the {@link Actor} set on this context.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
2014-04-05 00:54:14 +00:00
|
|
|
* @return an actor, or null
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
2014-04-05 00:54:14 +00:00
|
|
|
public @Nullable Actor getActor() {
|
|
|
|
return actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-05 00:54:14 +00:00
|
|
|
* Set the actor.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
2014-04-05 00:54:14 +00:00
|
|
|
* @param actor an actor, or null if none is available
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
2014-04-05 00:54:14 +00:00
|
|
|
public void setActor(@Nullable Actor actor) {
|
|
|
|
this.actor = actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@link Extent} set on this context.
|
|
|
|
*
|
|
|
|
* @return an extent
|
|
|
|
* @throws InputParseException thrown if no {@link Extent} is set
|
|
|
|
*/
|
|
|
|
public Extent requireExtent() throws InputParseException {
|
|
|
|
Extent extent = getExtent();
|
|
|
|
if (extent == null) {
|
|
|
|
throw new InputParseException("No Extent is known");
|
|
|
|
}
|
|
|
|
return extent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@link LocalSession}.
|
|
|
|
*
|
|
|
|
* @return a session
|
|
|
|
* @throws InputParseException thrown if no {@link LocalSession} is set
|
|
|
|
*/
|
|
|
|
public LocalSession requireSession() throws InputParseException {
|
|
|
|
LocalSession session = getSession();
|
|
|
|
if (session == null) {
|
|
|
|
throw new InputParseException("No LocalSession is known");
|
|
|
|
}
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-05 09:59:38 +00:00
|
|
|
* Get the {@link World} set on this context.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
|
|
|
* @return a world
|
2014-04-05 09:59:38 +00:00
|
|
|
* @throws InputParseException thrown if no {@link World} is set
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public World requireWorld() throws InputParseException {
|
|
|
|
World world = getWorld();
|
2014-04-04 00:52:53 +00:00
|
|
|
if (world == null) {
|
|
|
|
throw new InputParseException("No world is known");
|
|
|
|
}
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-05 00:54:14 +00:00
|
|
|
* Get the {@link Actor} set on this context.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
2014-04-05 00:54:14 +00:00
|
|
|
* @return an actor
|
2014-04-05 09:59:38 +00:00
|
|
|
* @throws InputParseException thrown if no {@link Actor} is set
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
2014-04-05 00:54:14 +00:00
|
|
|
public Actor requireActor() throws InputParseException {
|
|
|
|
Actor actor = getActor();
|
|
|
|
if (actor == null) {
|
|
|
|
throw new InputParseException("No actor is known");
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
2014-04-05 00:54:14 +00:00
|
|
|
return actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether there should be restrictions (as a result of
|
|
|
|
* limits or permissions) considered when parsing the input.
|
|
|
|
*
|
|
|
|
* @return true if restricted
|
|
|
|
*/
|
|
|
|
public boolean isRestricted() {
|
|
|
|
return restricted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether there should be restrictions (as a result of
|
|
|
|
* limits or permissions) considered when parsing the input.
|
|
|
|
*
|
|
|
|
* @param restricted true if restricted
|
|
|
|
*/
|
|
|
|
public void setRestricted(boolean restricted) {
|
|
|
|
this.restricted = restricted;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether wildcards are preferred.
|
|
|
|
*
|
|
|
|
* @return true if wildcards are preferred
|
|
|
|
*/
|
|
|
|
public boolean isPreferringWildcard() {
|
|
|
|
return preferringWildcard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether wildcards are preferred.
|
|
|
|
*
|
|
|
|
* @param preferringWildcard true if wildcards are preferred
|
|
|
|
*/
|
|
|
|
public void setPreferringWildcard(boolean preferringWildcard) {
|
|
|
|
this.preferringWildcard = preferringWildcard;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|