Skip to content
Permalink
Browse files

Added a Locatable interface and use that for getting the location of …

…the player in commands.
  • Loading branch information...
me4502 committed Jul 23, 2019
1 parent 5b56661 commit 3212e969455927dadaa9b1b01d48eec9acc1b96e
@@ -34,6 +34,7 @@
import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.internal.cui.CUIEvent;
@@ -504,8 +505,8 @@ public boolean toggleSuperPickAxe() {
public BlockVector3 getPlacementPosition(Actor actor) throws IncompleteRegionException {
checkNotNull(actor);
if (!placeAtPos1) {
if (actor instanceof Player) {
return ((Player) actor).getBlockIn().toVector().toBlockPoint();
if (actor instanceof Locatable) {
return ((Locatable) actor).getBlockLocation().toVector().toBlockPoint();
} else {
throw new IncompleteRegionException();
}
@@ -80,7 +80,7 @@ public ChunkCommands(WorldEdit worldEdit) {
)
@CommandPermissions("worldedit.chunkinfo")
public void chunkInfo(Player player) {
Location pos = player.getBlockIn();
Location pos = player.getBlockLocation();
int chunkX = (int) Math.floor(pos.getBlockX() / 16.0);
int chunkZ = (int) Math.floor(pos.getBlockZ() / 16.0);

@@ -34,6 +34,7 @@
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.block.BlockDistributionCounter;
@@ -111,8 +112,8 @@ public void pos1(Actor actor, World world, LocalSession session,
Location pos;
if (coordinates != null) {
pos = new Location(world, coordinates.toVector3());
} else if (actor.isPlayer() && actor instanceof Player) {
pos = ((Player) actor).getBlockIn();
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation();
} else {
actor.printError("You must provide coordinates as console.");
return;
@@ -139,8 +140,8 @@ public void pos2(Actor actor, World world, LocalSession session,
Location pos;
if (coordinates != null) {
pos = new Location(world, coordinates.toVector3());
} else if (actor.isPlayer() && actor instanceof Player) {
pos = ((Player) actor).getBlockIn();
} else if (actor instanceof Locatable) {
pos = ((Locatable) actor).getBlockLocation();
} else {
actor.printError("You must provide coordinates as console.");
return;
@@ -236,7 +237,7 @@ public void chunk(Player player, LocalSession session,
: ChunkStore.toChunk(coordinates.toBlockVector3());
} else {
// use player loc
min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint());
min2D = ChunkStore.toChunk(player.getBlockLocation().toVector().toBlockPoint());
}

min = BlockVector3.at(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16);
@@ -19,9 +19,9 @@

package com.sk89q.worldedit.entity;

import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Faceted;
import com.sk89q.worldedit.util.Location;

import javax.annotation.Nullable;

@@ -33,7 +33,7 @@
* instance of an entity, but a {@link BaseEntity} can be created from
* this entity by calling {@link #getState()}.</p>
*/
public interface Entity extends Faceted {
public interface Entity extends Faceted, Locatable {

/**
* Get a copy of the entity's state.
@@ -47,28 +47,6 @@
@Nullable
BaseEntity getState();

/**
* Get the location of this entity.
*
* @return the location of the entity
*/
Location getLocation();

/**
* Sets the location of this entity.
*
* @param location the new location of the entity
* @return if the teleport worked
*/
boolean setLocation(Location location);

/**
* Get the extent that this entity is on.
*
* @return the extent
*/
Extent getExtent();

/**
* Remove this entity from it container.
*
@@ -191,8 +191,12 @@
* Get the point of the block that is being stood in.
*
* @return point
* @deprecated Use Locatable#getBlockLocation
*/
Location getBlockIn();
@Deprecated
default Location getBlockIn() {
return getBlockLocation();
}

/**
* Get the point of the block that is being stood upon.
@@ -281,13 +285,6 @@
*/
void setPosition(Vector3 pos, float pitch, float yaw);

/**
* Move the player.
*
* @param pos where to move them
*/
void setPosition(Vector3 pos);

/**
* Sends a fake block to the client.
*
@@ -151,12 +151,12 @@ public void setOnGround(Location searchPos) {

@Override
public void findFreePosition() {
findFreePosition(getBlockIn());
findFreePosition(getBlockLocation());
}

@Override
public boolean ascendLevel() {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY());
final int z = pos.getBlockZ();
@@ -197,7 +197,7 @@ public boolean ascendLevel() {

@Override
public boolean descendLevel() {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
int y = Math.max(0, pos.getBlockY() - 1);
final int z = pos.getBlockZ();
@@ -247,7 +247,7 @@ public boolean ascendToCeiling(int clearance) {

@Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
Location pos = getBlockIn();
Location pos = getBlockLocation();
int x = pos.getBlockX();
int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 2);
@@ -287,7 +287,7 @@ public boolean ascendUpwards(int distance) {

@Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) {
final Location pos = getBlockIn();
final Location pos = getBlockLocation();
final int x = pos.getBlockX();
final int initialY = Math.max(0, pos.getBlockY());
int y = Math.max(0, pos.getBlockY() + 1);
@@ -345,13 +345,6 @@ protected boolean isAllowedToFly() {
protected void setFlying(boolean flying) {
}


@Override
public Location getBlockIn() {
final Location location = getLocation();
return location.setPosition(location.toVector().floor());
}

@Override
public Location getBlockOn() {
final Location location = getLocation();
@@ -0,0 +1,69 @@
/*
* 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.extent.Extent;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;

public interface Locatable {

/**
* Get the location of this actor.
*
* @return the location of the actor
*/
Location getLocation();

/**
* Get the location of this actor in block coordinates.
*
* @return the block location of the actor
*/
default Location getBlockLocation() {
Location location = getLocation();
return location.setPosition(location.toVector().floor());
}

/**
* Sets the location of this actor.
*
* @param location the new location of the actor
* @return if the teleport succeeded
*/
boolean setLocation(Location location);

/**
* Sets the position of this actor.
*
* @param pos where to move them
*/
default void setPosition(Vector3 pos) {
setLocation(new Location(getExtent(), pos));
}

/**
* Get the extent that this actor is in.
*
* @return the extent
*/
Extent getExtent();

}

0 comments on commit 3212e96

Please sign in to comment.
You can’t perform that action at this time.