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
|
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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
|
2014-04-04 00:52:53 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +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 General Public License for more details.
|
2014-04-04 00:52:53 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2021-04-04 17:56:57 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-11-11 08:55:53 +00:00
|
|
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
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-07-26 07:29:12 +00:00
|
|
|
*
|
|
|
|
* <p>By default, {@link #isRestricted()} will return true.</p>
|
2014-04-04 00:52:53 +00:00
|
|
|
*/
|
|
|
|
public class ParserContext {
|
|
|
|
|
2020-10-05 17:41:41 +00:00
|
|
|
@Nullable
|
|
|
|
private Extent extent;
|
|
|
|
@Nullable
|
|
|
|
private LocalSession session;
|
|
|
|
@Nullable
|
|
|
|
private World world;
|
|
|
|
@Nullable
|
|
|
|
private Actor actor;
|
2014-04-04 00:52:53 +00:00
|
|
|
private boolean restricted = true;
|
2018-07-23 02:48:11 +00:00
|
|
|
private boolean tryLegacy = true;
|
2014-04-04 00:52:53 +00:00
|
|
|
private boolean preferringWildcard;
|
2019-11-11 08:55:53 +00:00
|
|
|
private InjectedValueAccess injected;
|
2014-04-04 00:52:53 +00:00
|
|
|
|
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());
|
2018-07-23 02:48:11 +00:00
|
|
|
setTryLegacy(other.isTryingLegacy());
|
2014-07-07 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* Get the {@link Extent} set on this context.
|
|
|
|
*
|
|
|
|
* @return an extent
|
|
|
|
*/
|
2020-10-05 17:41:41 +00:00
|
|
|
@Nullable
|
|
|
|
public Extent getExtent() {
|
2014-04-04 00:52:53 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-10-05 17:41:41 +00:00
|
|
|
@Nullable
|
|
|
|
public LocalSession getSession() {
|
2014-04-04 00:52:53 +00:00
|
|
|
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
|
|
|
|
*/
|
2020-10-05 17:41:41 +00:00
|
|
|
@Nullable
|
|
|
|
public 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-07-17 07:08:13 +00:00
|
|
|
setExtent(world);
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2020-10-05 17:41:41 +00:00
|
|
|
@Nullable
|
|
|
|
public Actor getActor() {
|
2014-04-05 00:54:14 +00:00
|
|
|
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) {
|
2021-04-04 17:56:57 +00:00
|
|
|
throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-extent"));
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
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) {
|
2021-04-04 17:56:57 +00:00
|
|
|
throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-session"));
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
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) {
|
2021-04-04 17:56:57 +00:00
|
|
|
throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-world"));
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|
|
|
|
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) {
|
2021-04-04 17:56:57 +00:00
|
|
|
throw new InputParseException(TranslatableComponent.of("worldedit.error.missing-actor"));
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-23 02:48:11 +00:00
|
|
|
/**
|
|
|
|
* Set whether legacy IDs should be attempted.
|
|
|
|
*
|
|
|
|
* @param tryLegacy true if legacy IDs should be attempted
|
|
|
|
*/
|
|
|
|
public void setTryLegacy(boolean tryLegacy) {
|
|
|
|
this.tryLegacy = tryLegacy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get whether legacy IDs should be tried.
|
|
|
|
*
|
|
|
|
* @return true if legacy should be tried
|
|
|
|
*/
|
|
|
|
public boolean isTryingLegacy() {
|
|
|
|
return tryLegacy;
|
|
|
|
}
|
2019-11-11 08:55:53 +00:00
|
|
|
|
|
|
|
public void setInjected(InjectedValueAccess injected) {
|
|
|
|
this.injected = injected;
|
|
|
|
}
|
|
|
|
|
|
|
|
public InjectedValueAccess getInjected() {
|
|
|
|
return injected;
|
|
|
|
}
|
2014-04-04 00:52:53 +00:00
|
|
|
}
|