com.sk89q.worldedit.util.Location Java Examples

The following examples show how to use com.sk89q.worldedit.util.Location. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldEditUtils.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
public static org.bukkit.Location toLocation(Object location)
{
	if (WorldEditUtils.legacyToLocationMethod != null)
	{
		try
		{
			return (org.bukkit.Location)WorldEditUtils.legacyToLocationMethod.invoke(null, location);
		}
		catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e)
		{
			throw new RuntimeException("Unsupported WorldEdit version");
		}
	}
	else
	{
		return BukkitAdapter.adapt((Location)location);
	}
}
 
Example #2
Source File: FastWorldEditExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Entity createEntity(final Location loc, final BaseEntity entity) {
    if (entity != null) {
        CompoundTag tag = entity.getNbtData();
        Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
        map.put("Id", new StringTag(entity.getTypeId()));
        ListTag pos = (ListTag) map.get("Pos");
        if (pos != null) {
            List<Tag> posList = ReflectionUtils.getList(pos.getValue());
            posList.set(0, new DoubleTag(loc.getX()));
            posList.set(1, new DoubleTag(loc.getY()));
            posList.set(2, new DoubleTag(loc.getZ()));
        }
        queue.setEntity(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), tag);
    }
    return null;
}
 
Example #3
Source File: CommandBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException {
    int radius = (int) size;
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    WorldVectorFace face = player.getBlockTraceFace(256, true);
    if (face == null) {
        position = position.add(0, 1, 1);
    } else {
        position = face.getFaceVector();
    }
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example #4
Source File: ScatterCommand.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector position, Pattern p, double size) throws MaxChangedBlocksException {
    int radius = getDistance();
    CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius));
    String replaced = command.replace("{x}", position.getBlockX() + "")
            .replace("{y}", Integer.toString(position.getBlockY()))
            .replace("{z}", Integer.toString(position.getBlockZ()))
            .replace("{world}", editSession.getQueue().getWorldName())
            .replace("{size}", Integer.toString(radius));

    FawePlayer fp = editSession.getPlayer();
    Player player = fp.getPlayer();
    fp.setSelection(selector);
    PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position)));
    List<String> cmds = StringMan.split(replaced, ';');
    for (String cmd : cmds) {
        CommandEvent event = new CommandEvent(wePlayer, cmd);
        CommandManager.getInstance().handleCommandOnCurrentThread(event);
    }
}
 
Example #5
Source File: FloodFillTool.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
    World world = (World) clicked.getExtent();

    int initialType = world.getBlockType(clicked.toVector());

    if (initialType == BlockID.AIR) {
        return true;
    }

    if (initialType == BlockID.BEDROCK && !player.canDestroyBedrock()) {
        return true;
    }

    EditSession editSession = session.createEditSession(player);

    try {
        recurse(server, editSession, world, clicked.toVector().toBlockVector(),
                clicked.toVector(), range, initialType, new HashSet<BlockVector>());
    } catch (WorldEditException e) {
        throw new RuntimeException(e);
    }
    editSession.flushQueue();
    session.remember(editSession);
    return true;
}
 
Example #6
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    org.spongepowered.api.world.Location<World> entityLoc = this.player.getLocation();
    Vector3d entityRot = this.player.getRotation();

    return SpongeWorldEdit.inst().getAdapter().adapt(entityLoc, entityRot);
}
 
Example #7
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
    org.spongepowered.api.world.Location<World> loc = new org.spongepowered.api.world.Location<>(
            this.player.getWorld(), pos.getX(), pos.getY(), pos.getZ()
    );

    this.player.setLocationAndRotation(loc, new Vector3d(pitch, yaw, 0));
}
 
Example #8
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.world),
            position,
            this.player.rotationYaw,
            this.player.rotationPitch);
}
 
Example #9
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.worldObj),
            position,
            this.player.cameraYaw,
            this.player.cameraPitch);
}
 
Example #10
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static cn.nukkit.level.Location center(cn.nukkit.level.Location loc) {
    return new cn.nukkit.level.Location(
            loc.getFloorX() + 0.5,
            loc.getFloorY() + 0.5,
            loc.getFloorZ() + 0.5,
            loc.getPitch(),
            loc.getYaw(),
            loc.getLevel()
    );
}
 
Example #11
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.worldObj),
            position,
            this.player.rotationYaw,
            this.player.rotationPitch);
}
 
Example #12
Source File: NukkitEntity.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Entity entity = entityRef.get();
    if (entity != null) {
        return NukkitUtil.toLocation(entity.getLocation());
    } else {
        return new Location(NullWorld.getInstance());
    }
}
 
Example #13
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(final Location location, final BaseEntity state) {
    final Entity entity = super.createEntity(location, state);
    if ((state != null)) {
        this.changeSet.addEntityCreate(state.getNbtData());
    }
    return entity;
}
 
Example #14
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.worldObj),
            position,
            this.player.rotationYaw,
            this.player.rotationPitch);
}
 
Example #15
Source File: NukkitUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Nukkit's Location class has serious problems with floating point
 * precision.
 */
@SuppressWarnings("RedundantIfStatement")
public static boolean equals(cn.nukkit.level.Location a, cn.nukkit.level.Location b) {
    if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
    if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
    if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
    return true;
}
 
Example #16
Source File: ForgePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Location getLocation() {
    Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ);
    return new Location(
            ForgeWorldEdit.inst.getWorld(this.player.world),
            position,
            this.player.rotationYaw,
            this.player.rotationPitch);
}
 
Example #17
Source File: MultiTransform.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    Entity created = null;
    for (AbstractDelegateExtent extent : extents) created = extent.createEntity(location, entity);
    return created;
}
 
Example #18
Source File: BukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private static org.bukkit.Location adapt(org.bukkit.World world, Location location) {
    checkNotNull(world);
    checkNotNull(location);
    return new org.bukkit.Location(
            world,
            location.getX(), location.getY(), location.getZ(),
            location.getYaw(),
            location.getPitch());
}
 
Example #19
Source File: FaweRegionExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Entity createEntity(Location location, BaseEntity entity) {
    if (!contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
        if (!limit.MAX_FAILS()) {
            WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION);
        }
        return null;
    }
    return super.createEntity(location, entity);
}
 
Example #20
Source File: ProcessedWEExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Entity createEntity(final Location location, final BaseEntity entity) {
    if (entity == null) {
        return null;
    }
    if (!limit.MAX_ENTITIES()) {
        WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_ENTITIES);
        return null;
    }
    return super.createEntity(location, entity);
}
 
Example #21
Source File: Radiation.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@Override
public boolean test(Player player, RegionContainer regionContainer) {
    Location location = BukkitAdapter.adapt(player.getLocation());
    location = location.setY(Math.max(0, Math.min(255, location.getY())));
    ApplicableRegionSet regions = regionContainer.createQuery().getApplicableRegions(location);

    Boolean value = regions.queryValue(WorldGuardPlugin.inst().wrapPlayer(player), this.flag);
    return value != null && value;
}
 
Example #22
Source File: HistoryExtent.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean remove() {
    final Location location = this.entity.getLocation();
    final BaseEntity state = this.entity.getState();
    final boolean success = this.entity.remove();
    if ((state != null) && success) {
        HistoryExtent.this.changeSet.addEntityRemove(state.getNbtData());
    }
    return success;
}
 
Example #23
Source File: CatenaryBrush.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void build(EditSession editSession, Vector pos2, final Pattern pattern, double size) throws MaxChangedBlocksException {
    boolean visual = (editSession.getExtent() instanceof VisualExtent);
    if (pos1 == null || pos2.equals(pos1)) {
        if (!visual) {
            pos1 = pos2;
            BBC.BRUSH_LINE_PRIMARY.send(editSession.getPlayer(), pos2);
        }
        return;
    }
    if (this.vertex == null) {
        vertex = getVertex(pos1, pos2, slack);
        if (this.direction) {
            BBC.BRUSH_CATENARY_DIRECTION.send(editSession.getPlayer(), 2);
            return;
        }
    } else if (this.direction) {
        Location loc = editSession.getPlayer().getPlayer().getLocation();
        Vector facing = loc.getDirection().normalize();
        Vector midpoint = pos1.add(pos2).divide(2);
        Vector offset = midpoint.subtract(vertex);
        vertex = midpoint.add(facing.multiply(offset.length()));
    }
    List<Vector> nodes = Arrays.asList(pos1, vertex, pos2);
    vertex = null;
    editSession.drawSpline(pattern, nodes, 0, 0, 0, 10, size, !shell);
    if (!visual) {
        BBC.BRUSH_LINE_SECONDARY.send(editSession.getPlayer());
        if (!select) {
            pos1 = null;
            return;
        } else {
            pos1 = pos2;
        }
    }
}
 
Example #24
Source File: MainUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public static void setEntityInfo(CompoundTag tag, Entity entity) {
    Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
    map.put("Id", new StringTag(entity.getState().getTypeId()));
    ListTag pos = (ListTag) map.get("Pos");
    if (pos != null) {
        Location loc = entity.getLocation();
        List<Tag> posList = ReflectionUtils.getList(pos.getValue());
        posList.set(0, new DoubleTag(loc.getX()));
        posList.set(1, new DoubleTag(loc.getY()));
        posList.set(2, new DoubleTag(loc.getZ()));
    }
}
 
Example #25
Source File: LocationMaskedPlayerWrapper.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
    this.position = new Location(position.getExtent(), pos, pitch, yaw);
    if (allowTeleport) {
        super.setPosition(pos, pitch, yaw);
    }
}
 
Example #26
Source File: FakePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public FakePlayer(String name, UUID uuid, Actor parent) {
    this.name = name;
    this.uuid = uuid == null ? UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)) : uuid;
    try {
        this.world = WorldEdit.getInstance().getServer().getWorlds().get(0);
    } catch (NoCapablePlatformException e) {
        this.world = NullWorld.getInstance();
    }
    this.pos = new Location(world, 0, 0, 0);
    this.parent = parent;
}
 
Example #27
Source File: FakePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
    if (pos instanceof WorldVector) {
        this.world = ((WorldVector) pos).getWorld();
    }
    this.pos = new Location(world, pos, yaw, pitch);
}
 
Example #28
Source File: BrushTool.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public Vector getPosition(EditSession editSession, Player player) {
    Location loc = player.getLocation();
    switch (targetMode) {
        case TARGET_BLOCK_RANGE:
            return offset(new MutableBlockVector(trace(editSession, player, getRange(), true)), loc.toVector());
        case FOWARD_POINT_PITCH: {
            int d = 0;
            float pitch = loc.getPitch();
            pitch = 23 - (pitch / 4);
            d += (int) (Math.sin(Math.toRadians(pitch)) * 50);
            final Vector vector = loc.getDirection().setY(0).normalize().multiply(d);
            vector.add(loc.getX(), loc.getY(), loc.getZ()).toBlockVector();
            return offset(new MutableBlockVector(vector), loc.toVector());
        }
        case TARGET_POINT_HEIGHT: {
            final int height = loc.getBlockY();
            final int x = loc.getBlockX();
            final int z = loc.getBlockZ();
            int y;
            for (y = height; y > 0; y--) {
                BaseBlock block = editSession.getBlock(x, y, z);
                if (!FaweCache.isLiquidOrGas(block.getId())) {
                    break;
                }
            }
            final int distance = (height - y) + 8;
            return offset(new MutableBlockVector(trace(editSession, player, distance, true)), loc.toVector());
        }
        case TARGET_FACE_RANGE:
            return offset(new MutableBlockVector(trace(editSession, player, getRange(), true)), loc.toVector());
        default:
            return null;
    }
}
 
Example #29
Source File: EntityCreate.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param location the location
 * @param state    the state of the created entity
 * @param entity   the entity that was created
 */
public EntityCreate(Location location, BaseEntity state, Entity entity) {
    checkNotNull(location);
    checkNotNull(state);
    checkNotNull(entity);
    this.location = location;
    this.state = state;
    this.entity = entity;
}
 
Example #30
Source File: EntityRemove.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new instance.
 *
 * @param location the location
 * @param state    the state of the created entity
 */
public EntityRemove(Location location, BaseEntity state) {
    checkNotNull(location);
    checkNotNull(state);
    this.location = location;
    this.state = state;
}