geforkt von Mirrors/FastAsyncWorldEdit
Changed Location to use Extents rather than worlds and overhauled the new Entity code a bit.
Dieser Commit ist enthalten in:
Ursprung
c9612c05a7
Commit
eee2c5d9f4
@ -96,7 +96,7 @@ final class BukkitAdapter {
|
||||
final double length = Math.sqrt(eyeX * eyeX + eyeZ * eyeZ);
|
||||
final float pitch = (float) Math.toDegrees(Math.atan2(-direction.getY(), length));
|
||||
return new org.bukkit.Location(
|
||||
adapt(location.getWorld()),
|
||||
adapt((World) location.getExtent()),
|
||||
position.getX(), position.getY(), position.getZ(),
|
||||
yaw, pitch);
|
||||
}
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.LocalWorld;
|
||||
import com.sk89q.worldedit.PlayerNeededException;
|
||||
import com.sk89q.worldedit.WorldEditPermissionException;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
|
@ -22,8 +22,8 @@ package com.sk89q.worldedit.bukkit;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.metadata.Tameable;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -63,7 +63,7 @@ class BukkitEntity implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
public Extent getExtent() {
|
||||
return BukkitAdapter.adapt(getEntity().getWorld());
|
||||
}
|
||||
|
||||
@ -74,7 +74,12 @@ class BukkitEntity implements Entity {
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
return new BukkitBaseEntity(getEntity().getType());
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -184,13 +184,7 @@ public class BukkitWorld extends LocalWorld {
|
||||
@Nullable
|
||||
@Override
|
||||
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
||||
if (entity instanceof BukkitBaseEntity) {
|
||||
BukkitBaseEntity bukkitBaseEntity = (BukkitBaseEntity) entity;
|
||||
Entity nativeEntity = getWorld().spawnEntity(BukkitAdapter.adapt(location), bukkitBaseEntity.getBukkitType());
|
||||
return BukkitAdapter.adapt(nativeEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
private class NmsBlockClassLoader extends ClassLoader {
|
||||
|
@ -17,28 +17,23 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
package com.sk89q.worldedit.forge;
|
||||
|
||||
import com.sk89q.worldedit.entity.AbstractBaseEntity;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import net.minecraft.util.Vec3;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
final class ForgeAdapter {
|
||||
|
||||
/**
|
||||
* An implementation of a {@link BaseEntity} for Bukkit.
|
||||
*/
|
||||
public class BukkitBaseEntity extends AbstractBaseEntity {
|
||||
|
||||
private final EntityType type;
|
||||
|
||||
public BukkitBaseEntity(EntityType type) {
|
||||
checkNotNull(type);
|
||||
this.type = type;
|
||||
private ForgeAdapter() {
|
||||
}
|
||||
|
||||
public EntityType getBukkitType() {
|
||||
return type;
|
||||
public static World adapt(net.minecraft.world.World world) {
|
||||
return new ForgeWorld(world);
|
||||
}
|
||||
|
||||
public static Vector adapt(Vec3 vector) {
|
||||
return new Vector(vector.xCoord, vector.yCoord, vector.zCoord);
|
||||
}
|
||||
|
||||
}
|
67
src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
Normale Datei
67
src/forge/java/com/sk89q/worldedit/forge/ForgeEntity.java
Normale Datei
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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.forge;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
class ForgeEntity implements Entity {
|
||||
|
||||
private final net.minecraft.entity.Entity entity;
|
||||
|
||||
ForgeEntity(net.minecraft.entity.Entity entity) {
|
||||
checkNotNull(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseEntity getState() {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
entity.writeToNBT(tag);
|
||||
return new BaseEntity(EntityList.getEntityString(entity), NBTConverter.fromNative(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return new Location(
|
||||
ForgeAdapter.adapt(entity.worldObj),
|
||||
new Vector(entity.posX, entity.posY, entity.posZ),
|
||||
ForgeAdapter.adapt(entity.getLookVec()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Extent getExtent() {
|
||||
return ForgeAdapter.adapt(entity.worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
entity.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.LazyBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
@ -32,8 +33,8 @@ import com.sk89q.worldedit.world.AbstractWorld;
|
||||
import com.sk89q.worldedit.world.mapping.NullResolver;
|
||||
import com.sk89q.worldedit.world.mapping.Resolver;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.item.*;
|
||||
@ -55,7 +56,7 @@ import net.minecraft.world.gen.ChunkProviderServer;
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
@ -227,7 +228,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
int num = 0;
|
||||
double radiusSq = radius * radius;
|
||||
|
||||
for (Entity obj : (Iterable<Entity>) getWorld().loadedEntityList) {
|
||||
for (net.minecraft.entity.Entity obj : (Iterable<net.minecraft.entity.Entity>) getWorld().loadedEntityList) {
|
||||
if ((obj instanceof EntityLiving)) {
|
||||
EntityLiving ent = (EntityLiving) obj;
|
||||
|
||||
@ -270,7 +271,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
int num = 0;
|
||||
double radiusSq = Math.pow(radius, 2.0D);
|
||||
|
||||
for (Entity ent : (Iterable<Entity>) getWorld().loadedEntityList) {
|
||||
for (net.minecraft.entity.Entity ent : (Iterable<net.minecraft.entity.Entity>) getWorld().loadedEntityList) {
|
||||
if ((radius != -1) && (origin.distanceSq(new Vector(ent.posX, ent.posY, ent.posZ)) > radiusSq)) {
|
||||
continue;
|
||||
}
|
||||
@ -497,7 +498,7 @@ public class ForgeWorld extends AbstractWorld {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getMetaData(com.sk89q.worldedit.entity.Entity entity, Class<T> metaDataClass) {
|
||||
public <T> T getMetaData(Entity entity, Class<T> metaDataClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -508,14 +509,29 @@ public class ForgeWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<com.sk89q.worldedit.entity.Entity> getEntities() {
|
||||
return Collections.emptyList();
|
||||
public List<Entity> getEntities() {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (Object entity : getWorld().getLoadedEntityList()) {
|
||||
entities.add(new ForgeEntity((net.minecraft.entity.Entity) entity));
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public com.sk89q.worldedit.entity.Entity createEntity(Location location, BaseEntity entity) {
|
||||
return null;
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
World world = getWorld();
|
||||
net.minecraft.entity.Entity createdEntity = EntityList.createEntityByName(entity.getTypeId(), world);
|
||||
if (createdEntity != null) {
|
||||
CompoundTag tag = entity.getNbtData();
|
||||
if (tag != null) {
|
||||
createdEntity.readFromNBT(NBTConverter.toNative(entity.getNbtData()));
|
||||
}
|
||||
world.spawnEntityInWorld(createdEntity);
|
||||
return new ForgeEntity(createdEntity);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
import com.sk89q.worldedit.internal.LocalWorldAdapter;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
|
||||
@ -97,7 +98,7 @@ public class WorldVector extends Vector {
|
||||
* @param location the location
|
||||
*/
|
||||
public WorldVector(com.sk89q.worldedit.util.Location location) {
|
||||
this(LocalWorldAdapter.adapt(location.getWorld()), location.getX(), location.getY(), location.getZ());
|
||||
this(LocalWorldAdapter.adapt((World) location.getExtent()), location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
* A super pickaxe mode that will remove blocks in an area.
|
||||
@ -48,7 +49,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
int ox = clicked.getBlockX();
|
||||
int oy = clicked.getBlockY();
|
||||
int oz = clicked.getBlockZ();
|
||||
int initialType = clicked.getWorld().getBlockType(clicked.toVector());
|
||||
int initialType = ((World) clicked.getExtent()).getBlockType(clicked.toVector());
|
||||
|
||||
if (initialType == 0) {
|
||||
return true;
|
||||
@ -70,7 +71,7 @@ public class AreaPickaxe implements BlockTool {
|
||||
continue;
|
||||
}
|
||||
|
||||
clicked.getWorld().queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
|
||||
((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos));
|
||||
|
||||
editSession.setBlock(pos, air);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class BlockDataCyler implements DoubleActionBlockTool {
|
||||
private boolean handleCycle(Platform server, LocalConfiguration config,
|
||||
Player player, LocalSession session, Location clicked, boolean forward) {
|
||||
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
int type = world.getBlockType(clicked.toVector());
|
||||
int data = world.getBlockData(clicked.toVector());
|
||||
|
@ -48,7 +48,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
BlockBag bag = session.getBlockBag(player);
|
||||
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, bag, player);
|
||||
|
||||
try {
|
||||
@ -67,7 +67,7 @@ BlockBag bag = session.getBlockBag(player);
|
||||
|
||||
@Override
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player);
|
||||
targetBlock = (editSession).getBlock(clicked.toVector());
|
||||
BlockType type = BlockType.fromID(targetBlock.getType());
|
||||
|
@ -53,7 +53,7 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config,
|
||||
Player player, LocalSession session, Location clicked) {
|
||||
|
||||
final World world = clicked.getWorld();
|
||||
final World world = (World) clicked.getExtent();
|
||||
|
||||
switch (world.getBlockType(clicked.toVector())) {
|
||||
case BlockID.LOG:
|
||||
|
@ -51,7 +51,7 @@ public class FloodFillTool implements BlockTool {
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
int initialType = world.getBlockType(clicked.toVector());
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class QueryTool implements BlockTool {
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 0, player);
|
||||
BaseBlock block = (editSession).rawGetBlock(clicked.toVector());
|
||||
BlockType type = BlockType.fromID(block.getType());
|
||||
|
@ -50,7 +50,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
int initialType = world.getBlockType(clicked.toVector());
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class SinglePickaxe implements BlockTool {
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
World world = clicked.getWorld();
|
||||
World world = (World) clicked.getExtent();
|
||||
final int blockType = world.getBlockType(clicked.toVector());
|
||||
if (blockType == BlockID.BEDROCK
|
||||
&& !player.canDestroyBedrock()) {
|
||||
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* An abstract implementation of {@link BaseEntity} that implementations can
|
||||
* subclass to simplify implementation.
|
||||
*/
|
||||
public abstract class AbstractBaseEntity implements BaseEntity {
|
||||
|
||||
private CompoundTag nbtData;
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return getNbtData() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return nbtData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag nbtData) throws DataException {
|
||||
checkNotNull(nbtData);
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
}
|
@ -19,11 +19,74 @@
|
||||
|
||||
package com.sk89q.worldedit.entity;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.world.NbtValued;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A snapshot of an entity that can be reused and passed around.
|
||||
*/
|
||||
public interface BaseEntity extends NbtValued {
|
||||
public class BaseEntity implements NbtValued {
|
||||
|
||||
private String id;
|
||||
private CompoundTag nbtData;
|
||||
|
||||
/**
|
||||
* Create a new base entity.
|
||||
*
|
||||
* @param id the entity type ID
|
||||
* @param nbtData NBT data
|
||||
*/
|
||||
public BaseEntity(String id, CompoundTag nbtData) {
|
||||
setTypeId(id);
|
||||
setNbtData(nbtData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a clone of a {@link BaseEntity}.
|
||||
*
|
||||
* @param other the object to clone
|
||||
*/
|
||||
public BaseEntity(BaseEntity other) {
|
||||
checkNotNull(other);
|
||||
setTypeId(other.getTypeId());
|
||||
setNbtData(other.getNbtData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbtData() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getNbtData() {
|
||||
return nbtData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNbtData(CompoundTag nbtData) {
|
||||
checkNotNull(nbtData);
|
||||
this.nbtData = nbtData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity that determines the type of entity.
|
||||
*
|
||||
* @return the entity ID
|
||||
*/
|
||||
public String getTypeId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the entity ID that determines the type of entity.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void setTypeId(String id) {
|
||||
checkNotNull(id);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.worldedit.entity;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
* A reference to an instance of an entity that exists in an {@link Extent}
|
||||
@ -50,10 +49,17 @@ public interface Entity {
|
||||
Location getLocation();
|
||||
|
||||
/**
|
||||
* Get the world that this entity is on.
|
||||
* Get the extent that this entity is on.
|
||||
*
|
||||
* @return the world
|
||||
* @return the extent
|
||||
*/
|
||||
World getWorld();
|
||||
Extent getExtent();
|
||||
|
||||
/**
|
||||
* Remove this entity from it container.
|
||||
*
|
||||
* @return true if removal was successful
|
||||
*/
|
||||
boolean remove();
|
||||
|
||||
}
|
||||
|
@ -19,16 +19,28 @@
|
||||
|
||||
package com.sk89q.worldedit.entity;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.PlayerDirection;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.WorldVectorFace;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
/**
|
||||
* A player.
|
||||
*/
|
||||
public interface Player extends Entity, Actor {
|
||||
|
||||
/**
|
||||
* Return the world that the player is on.
|
||||
*
|
||||
* @return the world
|
||||
*/
|
||||
World getWorld();
|
||||
|
||||
/**
|
||||
* Returns true if the entity is holding a pick axe.
|
||||
*
|
||||
|
@ -19,12 +19,21 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.BlockWorldVector;
|
||||
import com.sk89q.worldedit.LocalPlayer;
|
||||
import com.sk89q.worldedit.NotABlockException;
|
||||
import com.sk89q.worldedit.PlayerDirection;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.WorldEditPermissionException;
|
||||
import com.sk89q.worldedit.WorldVector;
|
||||
import com.sk89q.worldedit.WorldVectorFace;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||
import com.sk89q.worldedit.util.TargetBlock;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -36,7 +45,12 @@ import java.io.File;
|
||||
* that is intended for implementations of WorldEdit to use to wrap
|
||||
* players that make use of WorldEdit.
|
||||
*/
|
||||
public abstract class AbstractPlayerActor implements Actor, Player {
|
||||
public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
|
||||
@Override
|
||||
public final Extent getExtent() {
|
||||
return getWorld();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns direction according to rotation. May return null.
|
||||
@ -466,4 +480,15 @@ public abstract class AbstractPlayerActor implements Actor, Player {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("CloneDoesntCallSuperClone")
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
throw new CloneNotSupportedException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,21 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.BiomeType;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.UnknownDirectionException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
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.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
@ -33,7 +41,12 @@ import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.parametric.*;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -158,7 +171,10 @@ public class WorldEditBinding extends BindingHelper {
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
@ -184,7 +200,10 @@ public class WorldEditBinding extends BindingHelper {
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
@ -210,7 +229,10 @@ public class WorldEditBinding extends BindingHelper {
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
|
@ -20,7 +20,7 @@
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -36,92 +36,92 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class Location {
|
||||
|
||||
private final World world;
|
||||
private final Extent extent;
|
||||
private final Vector position;
|
||||
private final Vector direction;
|
||||
|
||||
/**
|
||||
* Create a new instance in the given world at 0, 0, 0 with a
|
||||
* Create a new instance in the given extent at 0, 0, 0 with a
|
||||
* direction vector of 0, 0, 0.
|
||||
*
|
||||
* @param world the world
|
||||
* @param extent the extent
|
||||
*/
|
||||
public Location(World world) {
|
||||
this(world, new Vector(), new Vector());
|
||||
public Location(Extent extent) {
|
||||
this(extent, new Vector(), new Vector());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in the given world with the given coordinates
|
||||
* Create a new instance in the given extent with the given coordinates
|
||||
* with a direction vector of 0, 0, 0.
|
||||
*
|
||||
* @param world the world
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
*/
|
||||
public Location(World world, double x, double y, double z) {
|
||||
this(world, new Vector(x, y, z), new Vector());
|
||||
public Location(Extent extent, double x, double y, double z) {
|
||||
this(extent, new Vector(x, y, z), new Vector());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in the given world with the given position
|
||||
* Create a new instance in the given extent with the given position
|
||||
* vector and a direction vector of 0, 0, 0.
|
||||
*
|
||||
* @param world the world
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
*/
|
||||
public Location(World world, Vector position) {
|
||||
this(world, position, new Vector());
|
||||
public Location(Extent extent, Vector position) {
|
||||
this(extent, position, new Vector());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in the given world with the given coordinates
|
||||
* Create a new instance in the given extent with the given coordinates
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param world the world
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(World world, double x, double y, double z, Vector direction) {
|
||||
this(world, new Vector(x, y, z), direction);
|
||||
public Location(Extent extent, double x, double y, double z, Vector direction) {
|
||||
this(extent, new Vector(x, y, z), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in the given world with the given position vector
|
||||
* Create a new instance in the given extent with the given position vector
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param world the world
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(World world, Vector position, Vector direction) {
|
||||
checkNotNull(world);
|
||||
public Location(Extent extent, Vector position, Vector direction) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(position);
|
||||
checkNotNull(direction);
|
||||
this.world = world;
|
||||
this.extent = extent;
|
||||
this.position = position;
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world.
|
||||
* Get the extent.
|
||||
*
|
||||
* @return the world
|
||||
* @return the extent
|
||||
*/
|
||||
public World getWorld() {
|
||||
return world;
|
||||
public Extent getExtent() {
|
||||
return extent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a clone of this object with the given world.
|
||||
* Create a clone of this object with the given extent.
|
||||
*
|
||||
* @param world the new world
|
||||
* @param extent the new extent
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setWorld(World world) {
|
||||
return new Location(world, position, getDirection());
|
||||
public Location setExtent(Extent extent) {
|
||||
return new Location(extent, position, getDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,7 +143,7 @@ public class Location {
|
||||
* @return the new instance
|
||||
*/
|
||||
public Location setDirection(Vector direction) {
|
||||
return new Location(world, position, direction);
|
||||
return new Location(extent, position, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +181,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setX(double x) {
|
||||
return new Location(world, position.setX(x), direction);
|
||||
return new Location(extent, position.setX(x), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setX(int x) {
|
||||
return new Location(world, position.setX(x), direction);
|
||||
return new Location(extent, position.setX(x), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +221,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setY(double y) {
|
||||
return new Location(world, position.setY(y), direction);
|
||||
return new Location(extent, position.setY(y), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +232,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setY(int y) {
|
||||
return new Location(world, position.setY(y), direction);
|
||||
return new Location(extent, position.setY(y), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,7 +261,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setZ(double z) {
|
||||
return new Location(world, position.setZ(z), direction);
|
||||
return new Location(extent, position.setZ(z), direction);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,7 +272,7 @@ public class Location {
|
||||
* @return a new immutable instance
|
||||
*/
|
||||
public Location setZ(int z) {
|
||||
return new Location(world, position.setZ(z), direction);
|
||||
return new Location(extent, position.setZ(z), direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -284,14 +284,14 @@ public class Location {
|
||||
|
||||
if (!direction.equals(location.direction)) return false;
|
||||
if (!position.equals(location.position)) return false;
|
||||
if (!world.equals(location.world)) return false;
|
||||
if (!extent.equals(location.extent)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = world.hashCode();
|
||||
int result = extent.hashCode();
|
||||
result = 31 * result + position.hashCode();
|
||||
result = 31 * result + direction.hashCode();
|
||||
return result;
|
||||
|
@ -38,7 +38,7 @@ public class LocationTest {
|
||||
public void testGetWorld() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world);
|
||||
assertEquals(world, location.getWorld());
|
||||
assertEquals(world, location.getExtent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -46,9 +46,9 @@ public class LocationTest {
|
||||
World world1 = mock(World.class);
|
||||
World world2 = mock(World.class);
|
||||
Location location1 = new Location(world1);
|
||||
Location location2 = location1.setWorld(world2);
|
||||
assertEquals(world1, location1.getWorld());
|
||||
assertEquals(world2, location2.getWorld());
|
||||
Location location2 = location1.setExtent(world2);
|
||||
assertEquals(world1, location1.getExtent());
|
||||
assertEquals(world2, location2.getExtent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren