Added Actor, Player, Entity, BaseEntity.
This commit is contained in:
@@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.input;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.registry.MaskRegistry;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class ParserContext {
|
||||
private @Nullable Extent extent;
|
||||
private @Nullable LocalSession session;
|
||||
private @Nullable LocalWorld world;
|
||||
private @Nullable LocalPlayer player;
|
||||
private @Nullable Actor actor;
|
||||
private boolean restricted = true;
|
||||
private boolean preferringWildcard;
|
||||
|
||||
@@ -97,21 +98,21 @@ public class ParserContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link LocalPlayer} set on this context.
|
||||
* Get the {@link Actor} set on this context.
|
||||
*
|
||||
* @return a player
|
||||
* @return an actor, or null
|
||||
*/
|
||||
public @Nullable LocalPlayer getPlayer() {
|
||||
return player;
|
||||
public @Nullable Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the player.
|
||||
* Set the actor.
|
||||
*
|
||||
* @param player a player, or null if none is available
|
||||
* @param actor an actor, or null if none is available
|
||||
*/
|
||||
public void setPlayer(@Nullable LocalPlayer player) {
|
||||
this.player = player;
|
||||
public void setActor(@Nullable Actor actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,17 +158,17 @@ public class ParserContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link LocalPlayer} set on this context.
|
||||
* Get the {@link Actor} set on this context.
|
||||
*
|
||||
* @return a player
|
||||
* @return an actor
|
||||
* @throws InputParseException thrown if no {@link LocalPlayer} is set
|
||||
*/
|
||||
public LocalPlayer requirePlayer() throws InputParseException {
|
||||
LocalPlayer player = getPlayer();
|
||||
if (player == null) {
|
||||
throw new InputParseException("No player is known");
|
||||
public Actor requireActor() throws InputParseException {
|
||||
Actor actor = getActor();
|
||||
if (actor == null) {
|
||||
throw new InputParseException("No actor is known");
|
||||
}
|
||||
return player;
|
||||
return actor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
136
src/main/java/com/sk89q/worldedit/extension/platform/Actor.java
Normal file
136
src/main/java/com/sk89q/worldedit/extension/platform/Actor.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.WorldEditPermissionException;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* An object that can perform actions in WorldEdit.
|
||||
*/
|
||||
public interface Actor {
|
||||
|
||||
/**
|
||||
* Get the name of the actor.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the actor's world.
|
||||
*
|
||||
* @return the world
|
||||
*/
|
||||
LocalWorld getWorld();
|
||||
|
||||
/**
|
||||
* Print a message.
|
||||
*
|
||||
* @param msg The message text
|
||||
*/
|
||||
void printRaw(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEdit message.
|
||||
*
|
||||
* @param msg The message text
|
||||
*/
|
||||
void printDebug(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEdit message.
|
||||
*
|
||||
* @param msg The message text
|
||||
*/
|
||||
void print(String msg);
|
||||
|
||||
/**
|
||||
* Print a WorldEdit error.
|
||||
*
|
||||
* @param msg The error message text
|
||||
*/
|
||||
void printError(String msg);
|
||||
|
||||
/**
|
||||
* Returns true if the actor can destroy bedrock.
|
||||
*
|
||||
* @return true if bedrock can be broken by the actor
|
||||
*/
|
||||
boolean canDestroyBedrock();
|
||||
|
||||
/**
|
||||
* Get a actor's list of groups.
|
||||
*
|
||||
* @return an array containing a group name per entry
|
||||
*/
|
||||
String[] getGroups();
|
||||
|
||||
/**
|
||||
* Checks if a player has permission.
|
||||
*
|
||||
* @param perm The permission to check
|
||||
* @return true if the player has that permission
|
||||
*/
|
||||
boolean hasPermission(String perm);
|
||||
|
||||
/**
|
||||
* Check whether this actor has the given permission, and throw an
|
||||
* exception if not.
|
||||
*
|
||||
* @param permission the permission
|
||||
* @throws WorldEditPermissionException thrown if permission is not availabe
|
||||
*/
|
||||
void checkPermission(String permission) throws WorldEditPermissionException;
|
||||
|
||||
/**
|
||||
* Return whether this actor is a player.
|
||||
*
|
||||
* @return true if a player
|
||||
*/
|
||||
boolean isPlayer();
|
||||
|
||||
/**
|
||||
* Open a file open dialog.
|
||||
*
|
||||
* @param extensions null to allow all
|
||||
* @return the selected file or null if something went wrong
|
||||
*/
|
||||
File openFileOpenDialog(String[] extensions);
|
||||
|
||||
/**
|
||||
* Open a file save dialog.
|
||||
*
|
||||
* @param extensions null to allow all
|
||||
* @return the selected file or null if something went wrong
|
||||
*/
|
||||
File openFileSaveDialog(String[] extensions);
|
||||
|
||||
/**
|
||||
* Send a CUI event.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
void dispatchCUIEvent(CUIEvent event);
|
||||
|
||||
}
|
||||
@@ -21,10 +21,12 @@ package com.sk89q.worldedit.extension.registry;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.registry.InputParser;
|
||||
|
||||
/**
|
||||
@@ -36,13 +38,17 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
private static BaseBlock getBlockInHand(LocalPlayer player) throws InputParseException {
|
||||
try {
|
||||
return player.getBlockInHand();
|
||||
} catch (NotABlockException e) {
|
||||
throw new InputParseException("You're not holding a block!");
|
||||
} catch (WorldEditException e) {
|
||||
throw new InputParseException("Unknown error occurred: " + e.getMessage(), e);
|
||||
private static BaseBlock getBlockInHand(Actor actor) throws InputParseException {
|
||||
if (actor instanceof Player) {
|
||||
try {
|
||||
return ((Player) actor).getBlockInHand();
|
||||
} catch (NotABlockException e) {
|
||||
throw new InputParseException("You're not holding a block!");
|
||||
} catch (WorldEditException e) {
|
||||
throw new InputParseException("Unknown error occurred: " + e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
throw new InputParseException("The user is not a player!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +69,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
|
||||
if ("hand".equalsIgnoreCase(testID)) {
|
||||
// Get the block type from the item in the user's hand.
|
||||
final BaseBlock blockInHand = getBlockInHand(context.requirePlayer());
|
||||
final BaseBlock blockInHand = getBlockInHand(context.requireActor());
|
||||
if (blockInHand.getClass() != BaseBlock.class) {
|
||||
return blockInHand;
|
||||
}
|
||||
@@ -211,8 +217,8 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
}
|
||||
|
||||
// Check if the item is allowed
|
||||
LocalPlayer player = context.requirePlayer();
|
||||
if (context.isRestricted() && player != null && !player.hasPermission("worldedit.anyblock")
|
||||
Actor actor = context.requireActor();
|
||||
if (context.isRestricted() && actor != null && !actor.hasPermission("worldedit.anyblock")
|
||||
&& worldEdit.getConfiguration().disallowedBlocks.contains(blockId)) {
|
||||
throw new DisallowedUsageException("You are not allowed to use '" + input + "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user