Added Actor, Player, Entity, BaseEntity.

Dieser Commit ist enthalten in:
sk89q 2014-04-04 17:54:14 -07:00
Ursprung db48f64585
Commit bed5fa8fdc
10 geänderte Dateien mit 587 neuen und 348 gelöschten Zeilen

Datei anzeigen

@ -19,24 +19,23 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import java.io.File;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID; import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.TargetBlock; import com.sk89q.worldedit.util.TargetBlock;
import java.io.File;
/** /**
* * Represents a player that uses WorldEdit. In the future, this type
* @author sk89q * will be completely replaced by {@link Actor}.
*/
public abstract class LocalPlayer {
/**
* Server.
*/ */
public abstract class LocalPlayer implements Actor, Entity {
protected ServerInterface server; protected ServerInterface server;
/** /**
@ -48,11 +47,7 @@ public abstract class LocalPlayer {
this.server = server; this.server = server;
} }
/** @Override
* Returns true if the player is holding a pick axe.
*
* @return whether a pick axe is held
*/
public boolean isHoldingPickAxe() { public boolean isHoldingPickAxe() {
int item = getItemInHand(); int item = getItemInHand();
return item == ItemID.IRON_PICK return item == ItemID.IRON_PICK
@ -62,14 +57,7 @@ public abstract class LocalPlayer {
|| item == ItemID.GOLD_PICKAXE; || item == ItemID.GOLD_PICKAXE;
} }
/** @Override
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*
* @param searchPos search position
*/
public void findFreePosition(WorldVector searchPos) { public void findFreePosition(WorldVector searchPos) {
LocalWorld world = searchPos.getWorld(); LocalWorld world = searchPos.getWorld();
int x = searchPos.getBlockX(); int x = searchPos.getBlockX();
@ -101,11 +89,7 @@ public abstract class LocalPlayer {
} }
} }
/** @Override
* Set the player on the ground.
*
* @param searchPos The location to start searching from
*/
public void setOnGround(WorldVector searchPos) { public void setOnGround(WorldVector searchPos) {
LocalWorld world = searchPos.getWorld(); LocalWorld world = searchPos.getWorld();
int x = searchPos.getBlockX(); int x = searchPos.getBlockX();
@ -125,21 +109,12 @@ public abstract class LocalPlayer {
} }
} }
/** @Override
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*/
public void findFreePosition() { public void findFreePosition() {
findFreePosition(getBlockIn()); findFreePosition(getBlockIn());
} }
/** @Override
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
public boolean ascendLevel() { public boolean ascendLevel() {
final WorldVector pos = getBlockIn(); final WorldVector pos = getBlockIn();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
@ -180,11 +155,7 @@ public abstract class LocalPlayer {
return false; return false;
} }
/** @Override
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
public boolean descendLevel() { public boolean descendLevel() {
final WorldVector pos = getBlockIn(); final WorldVector pos = getBlockIn();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
@ -229,23 +200,12 @@ public abstract class LocalPlayer {
return false; return false;
} }
/** @Override
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @return whether the player was moved
*/
public boolean ascendToCeiling(int clearance) { public boolean ascendToCeiling(int clearance) {
return ascendToCeiling(clearance, true); return ascendToCeiling(clearance, true);
} }
/** @Override
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) { public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
Vector pos = getBlockIn(); Vector pos = getBlockIn();
int x = pos.getBlockX(); int x = pos.getBlockX();
@ -273,23 +233,12 @@ public abstract class LocalPlayer {
return false; return false;
} }
/** @Override
* Just go up.
*
* @param distance How far up to teleport
* @return whether the player was moved
*/
public boolean ascendUpwards(int distance) { public boolean ascendUpwards(int distance) {
return ascendUpwards(distance, true); return ascendUpwards(distance, true);
} }
/** @Override
* Just go up.
*
* @param distance How far up to teleport
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
public boolean ascendUpwards(int distance, boolean alwaysGlass) { public boolean ascendUpwards(int distance, boolean alwaysGlass) {
final Vector pos = getBlockIn(); final Vector pos = getBlockIn();
final int x = pos.getBlockX(); final int x = pos.getBlockX();
@ -315,94 +264,55 @@ public abstract class LocalPlayer {
return false; return false;
} }
/** @Override
* Make the player float in the given blocks.
*
* @param x The X coordinate of the block to float in
* @param y The Y coordinate of the block to float in
* @param z The Z coordinate of the block to float in
*/
public void floatAt(int x, int y, int z, boolean alwaysGlass) { public void floatAt(int x, int y, int z, boolean alwaysGlass) {
getPosition().getWorld().setBlockType(new Vector(x, y - 1, z), BlockID.GLASS); getPosition().getWorld().setBlockType(new Vector(x, y - 1, z), BlockID.GLASS);
setPosition(new Vector(x + 0.5, y, z + 0.5)); setPosition(new Vector(x + 0.5, y, z + 0.5));
} }
/** @Override
* Get the point of the block that is being stood in.
*
* @return point
*/
public WorldVector getBlockIn() { public WorldVector getBlockIn() {
WorldVector pos = getPosition(); WorldVector pos = getPosition();
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(), return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
pos.getY(), pos.getZ()); pos.getY(), pos.getZ());
} }
/** @Override
* Get the point of the block that is being stood upon.
*
* @return point
*/
public WorldVector getBlockOn() { public WorldVector getBlockOn() {
WorldVector pos = getPosition(); WorldVector pos = getPosition();
return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(), return WorldVector.toBlockPoint(pos.getWorld(), pos.getX(),
pos.getY() - 1, pos.getZ()); pos.getY() - 1, pos.getZ());
} }
/** @Override
* Get the point of the block being looked at. May return null.
* Will return the farthest away air block if useLastBlock is true and no other block is found.
*
* @param range How far to checks for blocks
* @param useLastBlock Try to return the last valid air block found.
* @return point
*/
public WorldVector getBlockTrace(int range, boolean useLastBlock) { public WorldVector getBlockTrace(int range, boolean useLastBlock) {
TargetBlock tb = new TargetBlock(this, range, 0.2); TargetBlock tb = new TargetBlock(this, range, 0.2);
return (useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock()); return (useLastBlock ? tb.getAnyTargetBlock() : tb.getTargetBlock());
} }
@Override
public WorldVectorFace getBlockTraceFace(int range, boolean useLastBlock) { public WorldVectorFace getBlockTraceFace(int range, boolean useLastBlock) {
TargetBlock tb = new TargetBlock(this, range, 0.2); TargetBlock tb = new TargetBlock(this, range, 0.2);
return (useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace()); return (useLastBlock ? tb.getAnyTargetBlockFace() : tb.getTargetBlockFace());
} }
/** @Override
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
public WorldVector getBlockTrace(int range) { public WorldVector getBlockTrace(int range) {
return getBlockTrace(range, false); return getBlockTrace(range, false);
} }
/** @Override
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
public WorldVector getSolidBlockTrace(int range) { public WorldVector getSolidBlockTrace(int range) {
TargetBlock tb = new TargetBlock(this, range, 0.2); TargetBlock tb = new TargetBlock(this, range, 0.2);
return tb.getSolidTargetBlock(); return tb.getSolidTargetBlock();
} }
/** @Override
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
*
* @return the direction
*/
public PlayerDirection getCardinalDirection() { public PlayerDirection getCardinalDirection() {
return getCardinalDirection(0); return getCardinalDirection(0);
} }
/** @Override
* Get the player's cardinal direction (N, W, NW, etc.) with an offset. May return null.
* @param yawOffset offset that is added to the player's yaw before determining the cardinal direction
*
* @return the direction
*/
public PlayerDirection getCardinalDirection(int yawOffset) { public PlayerDirection getCardinalDirection(int yawOffset) {
if (getPitch() > 67.5) { if (getPitch() > 67.5) {
return PlayerDirection.DOWN; return PlayerDirection.DOWN;
@ -449,18 +359,7 @@ public abstract class LocalPlayer {
} }
} }
/** @Override
* Get the ID of the item that the player is holding.
*
* @return the item id of the item the player is holding
*/
public abstract int getItemInHand();
/**
* Get the Block that the player is holding.
*
* @return the item id of the item the player is holding
*/
public BaseBlock getBlockInHand() throws WorldEditException { public BaseBlock getBlockInHand() throws WorldEditException {
final int typeId = getItemInHand(); final int typeId = getItemInHand();
if (!getWorld().isValidBlockType(typeId)) { if (!getWorld().isValidBlockType(typeId)) {
@ -469,65 +368,19 @@ public abstract class LocalPlayer {
return new BaseBlock(typeId); return new BaseBlock(typeId);
} }
/**
* Get the name of the player.
*
* @return String
*/
public abstract String getName();
/**
* Get the player's position.
*
* @return point
*/
public abstract WorldVector getPosition();
/**
* Get the player's world.
*
* @return point
*/
public abstract LocalWorld getWorld();
/** /**
* Get the player's view pitch. * Get the player's view pitch.
* *
* @return pitch * @return pitch
*/ */
/**
* Get the player's view pitch.
*
* @return pitch
*/
public abstract double getPitch();
/** /**
* Get the player's view yaw. * Get the player's view yaw.
* *
* @return yaw * @return yaw
*/ */
/**
* Get the player's view yaw.
*
* @return yaw
*/
public abstract double getYaw();
/** @Override
* Gives the player an item.
*
* @param type The item id of the item to be given to the player
* @param amount How many items in the stack
*/
public abstract void giveItem(int type, int amount);
/**
* Pass through the wall that you are looking at.
*
* @param range How far to checks for blocks
* @return whether the player was pass through
*/
public boolean passThroughForwardWall(int range) { public boolean passThroughForwardWall(int range) {
int searchDist = 0; int searchDist = 0;
TargetBlock hitBlox = new TargetBlock(this, range, 0.2); TargetBlock hitBlox = new TargetBlock(this, range, 0.2);
@ -571,121 +424,32 @@ public abstract class LocalPlayer {
return false; return false;
} }
/** @Override
* Print a message.
*
* @param msg The message text
*/
public abstract void printRaw(String msg);
/**
* Print a WorldEdit message.
*
* @param msg The message text
*/
public abstract void printDebug(String msg);
/**
* Print a WorldEdit message.
*
* @param msg The message text
*/
public abstract void print(String msg);
/**
* Print a WorldEdit error.
*
* @param msg The error message text
*/
public abstract void printError(String msg);
/**
* Move the player.
*
* @param pos Where to move them
* @param pitch The pitch (up/down) of the player's view
* @param yaw The yaw (left/right) of the player's view
*/
public abstract void setPosition(Vector pos, float pitch, float yaw);
/**
* Move the player.
*
* @param pos Where to move them
*/
public void setPosition(Vector pos) { public void setPosition(Vector pos) {
setPosition(pos, (float) getPitch(), (float) getYaw()); setPosition(pos, (float) getPitch(), (float) getYaw());
} }
/** @Override
* Get a player's list of groups.
*
* @return an array containing a group name per entry
*/
public abstract String[] getGroups();
/**
* Get this player's block bag.
*
* @return the player's block bag
*/
public abstract BlockBag getInventoryBlockBag();
/**
* Checks if a player has permission.
*
* @param perm The permission to check
* @return true if the player has that permission
*/
public abstract boolean hasPermission(String perm);
/**
* Open a file open dialog.
*
* @param extensions null to allow all
* @return the selected file or null if something went wrong
*/
public File openFileOpenDialog(String[] extensions) { public File openFileOpenDialog(String[] extensions) {
printError("File dialogs are not supported in your environment."); printError("File dialogs are not supported in your environment.");
return null; return null;
} }
/** @Override
* Open a file save dialog.
*
* @param extensions null to allow all
* @return the selected file or null if something went wrong
*/
public File openFileSaveDialog(String[] extensions) { public File openFileSaveDialog(String[] extensions) {
printError("File dialogs are not supported in your environment."); printError("File dialogs are not supported in your environment.");
return null; return null;
} }
/** @Override
* Returns true if the player can destroy bedrock.
*
* @return
*/
public boolean canDestroyBedrock() { public boolean canDestroyBedrock() {
return hasPermission("worldedit.override.bedrock"); return hasPermission("worldedit.override.bedrock");
} }
/** @Override
* Send a CUI event.
*
* @param event
*/
public void dispatchCUIEvent(CUIEvent event) { public void dispatchCUIEvent(CUIEvent event) {
} }
/**
* Send the CUI handshake.
* @deprecated Not used anymore; The CUI begins the handshake
*/
@Deprecated
public void dispatchCUIHandshake() {
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (!(other instanceof LocalPlayer)) { if (!(other instanceof LocalPlayer)) {
@ -700,16 +464,19 @@ public abstract class LocalPlayer {
return getName().hashCode(); return getName().hashCode();
} }
@Override
public void checkPermission(String permission) throws WorldEditPermissionException { public void checkPermission(String permission) throws WorldEditPermissionException {
if (!hasPermission(permission)) { if (!hasPermission(permission)) {
throw new WorldEditPermissionException(); throw new WorldEditPermissionException();
} }
} }
@Override
public boolean isPlayer() { public boolean isPlayer() {
return true; return true;
} }
@Override
public boolean hasCreativeMode() { public boolean hasCreativeMode() {
return false; return false;
} }

Datei anzeigen

@ -314,7 +314,7 @@ public class WorldEdit {
@Deprecated @Deprecated
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException { public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setPlayer(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
context.setSession(getSession(player)); context.setSession(getSession(player));
context.setRestricted(!allAllowed); context.setRestricted(!allAllowed);
@ -383,7 +383,7 @@ public class WorldEdit {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Pattern getBlockPattern(LocalPlayer player, String input) throws WorldEditException { public Pattern getBlockPattern(LocalPlayer player, String input) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setPlayer(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
context.setSession(getSession(player)); context.setSession(getSession(player));
return Patterns.wrap(getPatternRegistry().parseFromInput(input, context)); return Patterns.wrap(getPatternRegistry().parseFromInput(input, context));
@ -396,7 +396,7 @@ public class WorldEdit {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Mask getBlockMask(LocalPlayer player, LocalSession session, String input) throws WorldEditException { public Mask getBlockMask(LocalPlayer player, LocalSession session, String input) throws WorldEditException {
ParserContext context = new ParserContext(); ParserContext context = new ParserContext();
context.setPlayer(player); context.setActor(player);
context.setWorld(player.getWorld()); context.setWorld(player.getWorld());
context.setSession(session); context.setSession(session);
return Masks.wrap(getMaskRegistry().parseFromInput(input, context)); return Masks.wrap(getMaskRegistry().parseFromInput(input, context));

Datei anzeigen

@ -0,0 +1,26 @@
/*
* 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.entity;
/**
* A snapshot of an entity that can be reused and passed around.
*/
public class BaseEntity {
}

Datei anzeigen

@ -0,0 +1,218 @@
/*
* 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.entity;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.WorldVectorFace;
import com.sk89q.worldedit.extent.Extent;
/**
* A reference to an instance of an entity that exists in an {@link Extent}
* and thus would have position and similar details.
* </p>
* This object cannot be directly cloned because it represents a particular
* instance of an entity, but a {@link BaseEntity} can be created from
* this entity (or at least, it will be possible in the future), which
* can then be used to spawn new instances of that particular entity
* description.
*/
public interface Entity extends Player {
/**
* Find a position for the actor to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The actor will be teleported to
* that free position.
*
* @param searchPos search position
*/
void findFreePosition(WorldVector searchPos);
/**
* Set the actor on the ground.
*
* @param searchPos The location to start searching from
*/
void setOnGround(WorldVector searchPos);
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*/
void findFreePosition();
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
boolean ascendLevel();
/**
* Go up one level to the next free space above.
*
* @return true if a spot was found
*/
boolean descendLevel();
/**
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @return whether the player was moved
*/
boolean ascendToCeiling(int clearance);
/**
* Ascend to the ceiling above.
*
* @param clearance How many blocks to leave above the player's head
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
boolean ascendToCeiling(int clearance, boolean alwaysGlass);
/**
* Just go up.
*
* @param distance How far up to teleport
* @return whether the player was moved
*/
boolean ascendUpwards(int distance);
/**
* Just go up.
*
* @param distance How far up to teleport
* @param alwaysGlass Always put glass under the player
* @return whether the player was moved
*/
boolean ascendUpwards(int distance, boolean alwaysGlass);
/**
* Make the player float in the given blocks.
*
* @param x The X coordinate of the block to float in
* @param y The Y coordinate of the block to float in
* @param z The Z coordinate of the block to float in
*/
void floatAt(int x, int y, int z, boolean alwaysGlass);
/**
* Get the point of the block that is being stood in.
*
* @return point
*/
WorldVector getBlockIn();
/**
* Get the point of the block that is being stood upon.
*
* @return point
*/
WorldVector getBlockOn();
/**
* Get the point of the block being looked at. May return null.
* Will return the farthest away air block if useLastBlock is true and no other block is found.
*
* @param range How far to checks for blocks
* @param useLastBlock Try to return the last valid air block found.
* @return point
*/
WorldVector getBlockTrace(int range, boolean useLastBlock);
WorldVectorFace getBlockTraceFace(int range, boolean useLastBlock);
/**
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
WorldVector getBlockTrace(int range);
/**
* Get the point of the block being looked at. May return null.
*
* @param range How far to checks for blocks
* @return point
*/
WorldVector getSolidBlockTrace(int range);
/**
* Get the player's cardinal direction (N, W, NW, etc.). May return null.
*
* @return the direction
*/
PlayerDirection getCardinalDirection();
/**
* Get the actor's position.
* </p>
* If the actor has no permission, then return a dummy location.
*
* @return the actor's position
*/
WorldVector getPosition();
/**
* Get the player's view pitch.
*
* @return pitch
*/
double getPitch();
/**
* Get the player's view yaw.
*
* @return yaw
*/
double getYaw();
/**
* Pass through the wall that you are looking at.
*
* @param range How far to checks for blocks
* @return whether the player was pass through
*/
boolean passThroughForwardWall(int range);
/**
* Move the player.
*
* @param pos Where to move them
* @param pitch The pitch (up/down) of the player's view
* @param yaw The yaw (left/right) of the player's view
*/
void setPosition(Vector pos, float pitch, float yaw);
/**
* Move the player.
*
* @param pos Where to move them
*/
void setPosition(Vector pos);
}

Datei anzeigen

@ -0,0 +1,83 @@
/*
* 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.entity;
import com.sk89q.worldedit.PlayerDirection;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.inventory.BlockBag;
/**
* A player.
*/
public interface Player {
/**
* Returns true if the entity is holding a pick axe.
*
* @return whether a pick axe is held
*/
boolean isHoldingPickAxe();
/**
* Get the player's cardinal direction (N, W, NW, etc.) with an offset. May return null.
* @param yawOffset offset that is added to the player's yaw before determining the cardinal direction
*
* @return the direction
*/
PlayerDirection getCardinalDirection(int yawOffset);
/**
* Get the ID of the item that the player is holding.
*
* @return the item id of the item the player is holding
*/
int getItemInHand();
/**
* Get the Block that the player is holding.
*
* @return the item id of the item the player is holding
*/
BaseBlock getBlockInHand() throws WorldEditException;
/**
* Gives the player an item.
*
* @param type The item id of the item to be given to the player
* @param amount How many items in the stack
*/
void giveItem(int type, int amount);
/**
* Get this actor's block bag.
*
* @return the actor's block bag
*/
BlockBag getInventoryBlockBag();
/**
* Return whether this actor has creative mode.
*
* @return true if creative mode is enabled
*/
boolean hasCreativeMode();
}

Datei anzeigen

@ -20,11 +20,11 @@
package com.sk89q.worldedit.event.extent; package com.sk89q.worldedit.event.extent;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.event.Event; import com.sk89q.worldedit.event.Event;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -60,7 +60,7 @@ import static com.sk89q.worldedit.EditSession.Stage;
public class EditSessionEvent extends Event { public class EditSessionEvent extends Event {
private final LocalWorld world; private final LocalWorld world;
private final LocalPlayer player; private final Actor actor;
private final int maxBlocks; private final int maxBlocks;
private final Stage stage; private final Stage stage;
private Extent extent; private Extent extent;
@ -69,25 +69,25 @@ public class EditSessionEvent extends Event {
* Create a new event. * Create a new event.
* *
* @param world the world * @param world the world
* @param player the player, or null if not available * @param actor the actor, or null if there is no actor specified
* @param maxBlocks the maximum number of block changes * @param maxBlocks the maximum number of block changes
* @param stage the stage * @param stage the stage
*/ */
public EditSessionEvent(LocalWorld world, LocalPlayer player, int maxBlocks, Stage stage) { public EditSessionEvent(LocalWorld world, Actor actor, int maxBlocks, Stage stage) {
checkNotNull(world); checkNotNull(world);
this.world = world; this.world = world;
this.player = player; this.actor = actor;
this.maxBlocks = maxBlocks; this.maxBlocks = maxBlocks;
this.stage = stage; this.stage = stage;
} }
/** /**
* Get the player for this event. * Get the actor for this event.
* *
* @return the player, which may be null if unavailable * @return the actor, which may be null if unavailable
*/ */
public @Nullable LocalPlayer getPlayer() { public @Nullable Actor getActor() {
return player; return actor;
} }
/** /**
@ -144,7 +144,7 @@ public class EditSessionEvent extends Event {
* @return a new event * @return a new event
*/ */
public EditSessionEvent clone(Stage stage) { public EditSessionEvent clone(Stage stage) {
return new EditSessionEvent(world, player, maxBlocks, stage); return new EditSessionEvent(world, actor, maxBlocks, stage);
} }
} }

Datei anzeigen

@ -22,6 +22,7 @@ package com.sk89q.worldedit.extension.input;
import com.sk89q.worldedit.LocalPlayer; import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.registry.MaskRegistry; import com.sk89q.worldedit.extension.registry.MaskRegistry;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -38,7 +39,7 @@ public class ParserContext {
private @Nullable Extent extent; private @Nullable Extent extent;
private @Nullable LocalSession session; private @Nullable LocalSession session;
private @Nullable LocalWorld world; private @Nullable LocalWorld world;
private @Nullable LocalPlayer player; private @Nullable Actor actor;
private boolean restricted = true; private boolean restricted = true;
private boolean preferringWildcard; 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() { public @Nullable Actor getActor() {
return player; 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) { public void setActor(@Nullable Actor actor) {
this.player = player; 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 * @throws InputParseException thrown if no {@link LocalPlayer} is set
*/ */
public LocalPlayer requirePlayer() throws InputParseException { public Actor requireActor() throws InputParseException {
LocalPlayer player = getPlayer(); Actor actor = getActor();
if (player == null) { if (actor == null) {
throw new InputParseException("No player is known"); throw new InputParseException("No actor is known");
} }
return player; return actor;
} }
/** /**

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -21,10 +21,12 @@ package com.sk89q.worldedit.extension.registry;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.*; import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.DisallowedUsageException; 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.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException; 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; import com.sk89q.worldedit.internal.registry.InputParser;
/** /**
@ -36,14 +38,18 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
super(worldEdit); super(worldEdit);
} }
private static BaseBlock getBlockInHand(LocalPlayer player) throws InputParseException { private static BaseBlock getBlockInHand(Actor actor) throws InputParseException {
if (actor instanceof Player) {
try { try {
return player.getBlockInHand(); return ((Player) actor).getBlockInHand();
} catch (NotABlockException e) { } catch (NotABlockException e) {
throw new InputParseException("You're not holding a block!"); throw new InputParseException("You're not holding a block!");
} catch (WorldEditException e) { } catch (WorldEditException e) {
throw new InputParseException("Unknown error occurred: " + e.getMessage(), e); throw new InputParseException("Unknown error occurred: " + e.getMessage(), e);
} }
} else {
throw new InputParseException("The user is not a player!");
}
} }
@Override @Override
@ -63,7 +69,7 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
if ("hand".equalsIgnoreCase(testID)) { if ("hand".equalsIgnoreCase(testID)) {
// Get the block type from the item in the user's hand. // 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) { if (blockInHand.getClass() != BaseBlock.class) {
return blockInHand; return blockInHand;
} }
@ -211,8 +217,8 @@ class DefaultBlockParser extends InputParser<BaseBlock> {
} }
// Check if the item is allowed // Check if the item is allowed
LocalPlayer player = context.requirePlayer(); Actor actor = context.requireActor();
if (context.isRestricted() && player != null && !player.hasPermission("worldedit.anyblock") if (context.isRestricted() && actor != null && !actor.hasPermission("worldedit.anyblock")
&& worldEdit.getConfiguration().disallowedBlocks.contains(blockId)) { && worldEdit.getConfiguration().disallowedBlocks.contains(blockId)) {
throw new DisallowedUsageException("You are not allowed to use '" + input + "'"); throw new DisallowedUsageException("You are not allowed to use '" + input + "'");
} }

Datei anzeigen

@ -20,6 +20,8 @@
package com.sk89q.worldedit.session; package com.sk89q.worldedit.session;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashMap; import java.util.HashMap;
@ -50,34 +52,34 @@ public class SessionManager {
} }
/** /**
* Get whether a session exists for the given player. * Get whether a session exists for the given actor.
* *
* @param player the player * @param actor the actor
* @return true if a session exists * @return true if a session exists
*/ */
public synchronized boolean contains(LocalPlayer player) { public synchronized boolean contains(Actor actor) {
checkNotNull(player); checkNotNull(actor);
return sessions.containsKey(getKey(player)); return sessions.containsKey(getKey(actor));
} }
/** /**
* Gets the session for a player and return it if it exists, otherwise * Gets the session for an actor and return it if it exists, otherwise
* return <code>null</code>. * return <code>null</code>.
* *
* @param player the player * @param actor the actor
* @return the session for the player, if it exists * @return the session for the actor, if it exists
*/ */
public synchronized @Nullable LocalSession find(LocalPlayer player) { public synchronized @Nullable LocalSession find(Actor actor) {
checkNotNull(player); checkNotNull(actor);
return sessions.get(getKey(player)); return sessions.get(getKey(actor));
} }
/** /**
* Gets the session for someone named by the given name and return it if * Gets the session for someone named by the given name and return it if
* it exists, otherwise return <code>null</code>. * it exists, otherwise return <code>null</code>.
* *
* @param name the player's name * @param name the actor's name
* @return the session for the player, if it exists * @return the session for the actor, if it exists
*/ */
public synchronized @Nullable LocalSession findByName(String name) { public synchronized @Nullable LocalSession findByName(String name) {
checkNotNull(name); checkNotNull(name);
@ -85,32 +87,32 @@ public class SessionManager {
} }
/** /**
* Get the session for a player and create one if one doesn't exist. * Get the session for an actor and create one if one doesn't exist.
* *
* @param player the player * @param actor the actor
* @return a session * @return a session
*/ */
public synchronized LocalSession get(LocalPlayer player) { public synchronized LocalSession get(Actor actor) {
checkNotNull(player); checkNotNull(actor);
LocalSession session; LocalSession session;
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
if (sessions.containsKey(player.getName())) { if (sessions.containsKey(actor.getName())) {
session = sessions.get(player.getName()); session = sessions.get(actor.getName());
} else { } else {
session = new LocalSession(config); session = new LocalSession(config);
session.setBlockChangeLimit(config.defaultChangeLimit); session.setBlockChangeLimit(config.defaultChangeLimit);
// Remember the session // Remember the session
sessions.put(player.getName(), session); sessions.put(actor.getName(), session);
} }
// Set the limit on the number of blocks that an operation can // Set the limit on the number of blocks that an operation can
// change at once, or don't if the player has an override or there // change at once, or don't if the actor has an override or there
// is no limit. There is also a default limit // is no limit. There is also a default limit
int currentChangeLimit = session.getBlockChangeLimit(); int currentChangeLimit = session.getBlockChangeLimit();
if (!player.hasPermission("worldedit.limit.unrestricted") if (!actor.hasPermission("worldedit.limit.unrestricted")
&& config.maxChangeLimit > -1) { && config.maxChangeLimit > -1) {
// If the default limit is infinite but there is a maximum // If the default limit is infinite but there is a maximum
@ -128,47 +130,47 @@ public class SessionManager {
} }
} }
// Have the session use inventory if it's enabled and the player // Have the session use inventory if it's enabled and the actor
// doesn't have an override // doesn't have an override
session.setUseInventory(config.useInventory session.setUseInventory(config.useInventory
&& !(config.useInventoryOverride && !(config.useInventoryOverride
&& (player.hasPermission("worldedit.inventory.unrestricted") && (actor.hasPermission("worldedit.inventory.unrestricted")
|| (config.useInventoryCreativeOverride && player.hasCreativeMode())))); || (config.useInventoryCreativeOverride && (!(actor instanceof Player) || ((Player) actor).hasCreativeMode())))));
return session; return session;
} }
/** /**
* Get the key to use in the map for a player. * Get the key to use in the map for an actor.
* *
* @param player the player * @param actor the actor
* @return the key object * @return the key object
*/ */
protected String getKey(LocalPlayer player) { protected String getKey(Actor actor) {
return player.getName(); return actor.getName();
} }
/** /**
* Mark for expiration. * Mark for expiration.
* *
* @param player the player * @param actor the actor
*/ */
public synchronized void markforExpiration(LocalPlayer player) { public synchronized void markforExpiration(Actor actor) {
checkNotNull(player); checkNotNull(actor);
LocalSession session = find(player); LocalSession session = find(actor);
if (session != null) { if (session != null) {
session.update(); session.update();
} }
} }
/** /**
* Remove the session for the given player if one exists. * Remove the session for the given actor if one exists.
* *
* @param player the player * @param actor the actor
*/ */
public synchronized void remove(LocalPlayer player) { public synchronized void remove(Actor actor) {
checkNotNull(player); checkNotNull(actor);
sessions.remove(player.getName()); sessions.remove(actor.getName());
} }
/** /**