org.bukkit.craftbukkit.CraftWorld Java Examples

The following examples show how to use org.bukkit.craftbukkit.CraftWorld. 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: CraftEntity.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public boolean teleport(Location location, TeleportCause cause) {
    Preconditions.checkArgument(location != null, "location");
    location.checkFinite();

    if (entity.isBeingRidden() || entity.isDead) {
        return false;
    }

    // If this entity is riding another entity, we must dismount before teleporting.
    entity.dismountRidingEntity();

    entity.world = ((CraftWorld) location.getWorld()).getHandle();
    // entity.setLocation() throws no event, and so cannot be cancelled
    entity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    // SPIGOT-619: Force sync head rotation also
    entity.setRotationYawHead(location.getYaw());

    return true;
}
 
Example #2
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityPlayer who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
    CraftWorld craftWorld = world.getWorld();
    CraftServer craftServer = world.getServer();

    Player player = (Player) who.getBukkitEntity();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    Block placedBlock = replacedBlockState.getBlock();

    boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());

    org.bukkit.inventory.ItemStack item;
    EquipmentSlot equipmentSlot;
    if (hand == EnumHand.MAIN_HAND) {
        item = player.getInventory().getItemInMainHand();
        equipmentSlot = EquipmentSlot.HAND;
    } else {
        item = player.getInventory().getItemInOffHand();
        equipmentSlot = EquipmentSlot.OFF_HAND;
    }

    BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #3
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityPlayer who, int clickedX, int clickedY, int clickedZ, EnumFacing clickedFace, ItemStack itemstack, net.minecraft.item.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #4
Source File: CraftBlockState.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;

    createData(block.getData());
    TileEntity te = world.getHandle().getTileEntity(new BlockPos(this.x, this.y, this.z));
    if (te != null) {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    } else nbt = null;
}
 
Example #5
Source File: CraftJukebox.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);

    if (result && this.isPlaced() && this.getType() == Material.JUKEBOX) {
        CraftWorld world = (CraftWorld) this.getWorld();
        Material record = this.getPlaying();
        if (record == Material.AIR) {
            world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
                    Blocks.JUKEBOX.getDefaultState()
                            .withProperty(BlockJukebox.HAS_RECORD, false), 3);
        } else {
            world.getHandle().setBlockState(new BlockPos(this.getX(), this.getY(), this.getZ()),
                    Blocks.JUKEBOX.getDefaultState()
                            .withProperty(BlockJukebox.HAS_RECORD, true), 3);
        }
        world.playEffect(this.getLocation(), Effect.RECORD_PLAY, record.getId());
    }

    return result;
}
 
Example #6
Source File: VanillaCommandWrapper.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
private static net.minecraft.command.ICommandSender getListener(CommandSender sender)
{
    if ( sender instanceof CraftPlayer )
    {
        return new PlayerListener( ( (CraftPlayer) sender ).getHandle() );
    }
    if ( sender instanceof CraftBlockCommandSender )
    {
        CraftBlockCommandSender commandBlock = (CraftBlockCommandSender) sender;
        Block block = commandBlock.getBlock();
        return ( (net.minecraft.tileentity.TileEntityCommandBlock) ( (CraftWorld) block.getWorld() ).getTileEntityAt( block.getX(), block.getY(), block.getZ() ) ).func_145993_a();
    }
    if ( sender instanceof CraftMinecartCommand )
    {
        return ( (net.minecraft.entity.EntityMinecartCommandBlock) ( (CraftMinecartCommand) sender ).getHandle() ).func_145822_e();
    }
    return new ConsoleListener(sender); // Assume console/rcon
}
 
Example #7
Source File: CraftEntity.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public boolean teleport(Location location, TeleportCause cause) {
       if (entity.ridingEntity != null || entity.riddenByEntity != null || entity.isDead) {
           return false;
       }

       // Spigot start
       net.minecraft.world.WorldServer newWorld = ((CraftWorld) location.getWorld()).getHandle();
       if (newWorld != entity.worldObj) {
           entity.teleportTo(location, cause.isPortal());
           return true;
       }
       // Spigot end
       entity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
//entity.worldObj.entityJoinedWorld(entity, false); // PaperSpigot - Prevent Server from thinking a player teleporting within the world has joined the world
       // entity.setLocation() throws no event, and so cannot be cancelled
       return true;
   }
 
Example #8
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
Example #9
Source File: CraftPlayer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public Location getBedSpawnLocation() {
    World world = getServer().getWorld(getHandle().spawnWorld);
    net.minecraft.util.ChunkCoordinates bed = getHandle().getBedLocation();

    if (world != null && bed != null) {
        bed = net.minecraft.entity.player.EntityPlayer.verifyRespawnCoordinates(((CraftWorld) world).getHandle(), bed, getHandle().isSpawnForced());
        if (bed != null) {
            return new Location(world, bed.posX, bed.posY, bed.posZ);
        }
    }
    return null;
}
 
Example #10
Source File: CraftPainting.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    net.minecraft.world.WorldServer world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.item.EntityPainting painting = new net.minecraft.entity.item.EntityPainting(world);
    painting.field_146063_b = getHandle().field_146063_b;
    painting.field_146064_c = getHandle().field_146064_c;
    painting.field_146062_d = getHandle().field_146062_d;
    painting.art = getHandle().art;
    painting.setDirection(getHandle().hangingDirection);
    getHandle().setDead();
    getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important
    world.spawnEntityInWorld(painting);
    this.entity = painting;
}
 
Example #11
Source File: CraftPlayer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendBlockChange(Location loc, int material, byte data) {
    if (getHandle().playerNetServerHandler == null) return;

    S23PacketBlockChange packet = new S23PacketBlockChange(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), ((CraftWorld) loc.getWorld()).getHandle());

    packet.field_148883_d = CraftMagicNumbers.getBlock(material);
    packet.field_148884_e = data;
    getHandle().playerNetServerHandler.sendPacket(packet);
}
 
Example #12
Source File: CraftItemFrame.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean setFacingDirection(BlockFace face, boolean force) {
    if (!super.setFacingDirection(face, force)) {
        return false;
    }

    net.minecraft.world.WorldServer world = ((CraftWorld) this.getWorld()).getHandle();
    world.getEntityTracker().removeEntityFromAllTrackingPlayers(this.getHandle());
    world.getEntityTracker().addEntityToTracker(this.getHandle());
    return true;
}
 
Example #13
Source File: CraftCommandBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftCommandBlock(Block block) {
    super(block);

    CraftWorld world = (CraftWorld) block.getWorld();
    commandBlock = (TileEntityCommandBlock) world.getTileEntityAt(getX(), getY(), getZ());
    command = commandBlock.func_145993_a().field_145763_e;
    name = commandBlock.func_145993_a().getCommandSenderName();
}
 
Example #14
Source File: CraftSign.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftSign(final Block block) {
    super(block);

    CraftWorld world = (CraftWorld) block.getWorld();
    sign = (net.minecraft.tileentity.TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
    // Spigot start
    if (sign == null) {
        lines = new String[]{"", "", "", ""};
        return;
    }
    // Spigot end
    lines = new String[sign.signText.length];
    System.arraycopy(sign.signText, 0, lines, 0, lines.length);
}
 
Example #15
Source File: CraftSkull.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftSkull(final Block block) {
    super(block);

    CraftWorld world = (CraftWorld) block.getWorld();
    skull = (TileEntitySkull) world.getTileEntityAt(getX(), getY(), getZ());
    profile = skull.func_152108_a();
    skullType = getSkullType(skull.func_145904_a());
    rotation = (byte) skull.getRotation();
}
 
Example #16
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public FakeArmorStand(World world, @Nullable String name, boolean invisible, boolean marker, boolean small) {
    super(new EntityArmorStand(((CraftWorld) world).getHandle()));

    entity.setInvisible(invisible);
    entity.setMarker(marker);
    entity.setSmall(small);
    entity.setBasePlate(false);
    entity.setArms(false);

    if(name != null) {
        entity.setCustomName(name);
        entity.setCustomNameVisible(true);
    }
}
 
Example #17
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(EntityPlayer who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(x, y, z);

    BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #18
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static PlayerInteractEvent callPlayerInteractEvent(EntityPlayer who, Action action, BlockPos position, EnumFacing direction, ItemStack itemstack, boolean cancelledBlock, EnumHand hand) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = null;
    if (position != null) {
        blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
    } else {
        switch (action) {
            case LEFT_CLICK_BLOCK:
                action = Action.LEFT_CLICK_AIR;
                break;
            case RIGHT_CLICK_BLOCK:
                action = Action.RIGHT_CLICK_AIR;
                break;
        }
    }
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);

    if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
        itemInHand = null;
    }

    PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == EnumHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
    if (cancelledBlock) {
        event.setUseInteractedBlock(Event.Result.DENY);
    }
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example #19
Source File: CraftMapView.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public World getWorld() {
    int dimension = worldMap.dimension; // Cauldron - byte -> int for Forge
    for (World world : Bukkit.getServer().getWorlds()) {
        if (((CraftWorld) world).getHandle().provider.dimensionId == dimension) {
            return world;
        }
    }
    return null;
}
 
Example #20
Source File: CraftBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean isEmpty() {
    // Cauldron start - support custom air blocks (Railcraft player aura tracking block)
    //return getType() == Material.AIR;
    if (getType() == Material.AIR) return true;
    if (!(getWorld() instanceof CraftWorld)) return false;
    return ((CraftWorld) getWorld()).getHandle().isAirBlock(getX(), getY(), getZ());
    // Cauldron end
}
 
Example #21
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private static boolean canBuild(CraftWorld world, Player player, int x, int z) {
    WorldServer worldServer = world.getHandle();
    int spawnSize = Bukkit.getServer().getSpawnRadius();

    if (world.getHandle().dimension != 0) return true;
    if (spawnSize <= 0) return true;
    if (((CraftServer) Bukkit.getServer()).getHandle().getOppedPlayers().isEmpty()) return true;
    if (player.isOp()) return true;

    BlockPos chunkcoordinates = worldServer.getSpawnPoint();

    int distanceFromSpawn = Math.max(Math.abs(x - chunkcoordinates.getX()), Math.abs(z - chunkcoordinates.getZ()));
    return distanceFromSpawn > spawnSize;
}
 
Example #22
Source File: CraftPainting.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    WorldServer world = ((CraftWorld) getWorld()).getHandle();
    EntityPainting painting = new EntityPainting(world);
    painting.hangingPosition = getHandle().getHangingPosition();
    painting.art = getHandle().art;
    painting.updateFacingWithBoundingBox(getHandle().facingDirection);
    getHandle().setDead();
    getHandle().velocityChanged = true; // because this occurs when the painting is broken, so it might be important
    world.spawnEntity(painting);
    this.entity = painting;
}
 
Example #23
Source File: CraftItemFrame.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private void update() {
    EntityItemFrame old = this.getHandle();

    WorldServer world = ((CraftWorld) getWorld()).getHandle();
    BlockPos position = old.getPosition();
    EnumFacing direction = old.getHorizontalFacing();
    ItemStack item = old.getDisplayedItem() != null ? old.getDisplayedItem().copy() : null;

    old.setDead();

    EntityItemFrame frame = new EntityItemFrame(world, position, direction);
    frame.setDisplayedItem(item);
    world.spawnEntity(frame);
    this.entity = frame;
}
 
Example #24
Source File: CraftRabbit.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setRabbitType(Type type) {
    EntityRabbit entity = getHandle();
    if (getRabbitType() == Type.THE_KILLER_BUNNY) {
        // Reset goals and target finders.
        World world = ((CraftWorld) this.getWorld()).getHandle();
        entity.tasks = new EntityAITasks(world != null && world.profiler != null ? world.profiler : null);
        entity.targetTasks = new EntityAITasks(world != null && world.profiler != null ? world.profiler : null);
        entity.initializePathFinderGoals();
    }

    entity.setRabbitType(CraftMagicMapping.toMagic(type));
}
 
Example #25
Source File: CraftMapView.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public World getWorld() {
    int dimension = worldMap.dimension;
    for (World world : Bukkit.getServer().getWorlds()) {
        if (((CraftWorld) world).getHandle().dimension == dimension) {
            return world;
        }
    }
    return null;
}
 
Example #26
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
private static boolean canBuild(CraftWorld world, Player player, int x, int z) {
    net.minecraft.world.WorldServer worldServer = world.getHandle();
    int spawnSize = Bukkit.getServer().getSpawnRadius();

    if (world.getHandle().provider.dimensionId != 0) return true;
    if (spawnSize <= 0) return true;
    if (((CraftServer) Bukkit.getServer()).getHandle().func_152603_m().func_152690_d()) return true;
    if (player.isOp()) return true;

    net.minecraft.util.ChunkCoordinates chunkcoordinates = worldServer.getSpawnPoint();

    int distanceFromSpawn = Math.max(Math.abs(x - chunkcoordinates.posX), Math.abs(z - chunkcoordinates.posZ));
    return distanceFromSpawn > spawnSize;
}
 
Example #27
Source File: CraftJukebox.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean eject() {
    requirePlaced();
    TileEntity tileEntity = this.getTileEntityFromWorld();
    if (!(tileEntity instanceof TileEntityJukebox)) return false;

    TileEntityJukebox jukebox = (TileEntityJukebox) tileEntity;
    boolean result = !jukebox.getRecord().isEmpty();
    CraftWorld world = (CraftWorld) this.getWorld();
    ((BlockJukebox) Blocks.JUKEBOX).dropRecord(world.getHandle(), new BlockPos(getX(), getY(), getZ()), null);
    return result;
}
 
Example #28
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean play() {
    Block block = getBlock();

    if (block.getType() == Material.NOTE_BLOCK) {
        TileEntityNote note = (TileEntityNote) this.getTileEntityFromWorld();
        CraftWorld world = (CraftWorld) this.getWorld();
        note.triggerNote(world.getHandle(), new BlockPos(getX(), getY(), getZ()));
        return true;
    } else {
        return false;
    }
}
 
Example #29
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean play(byte instrument, byte note) {
    Block block = getBlock();

    if (block.getType() == Material.NOTE_BLOCK) {
        CraftWorld world = (CraftWorld) this.getWorld();
        world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument, note);
        return true;
    } else {
        return false;
    }
}
 
Example #30
Source File: CraftNoteBlock.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean play(Instrument instrument, Note note) {
    Block block = getBlock();

    if (block.getType() == Material.NOTE_BLOCK) {
        CraftWorld world = (CraftWorld) this.getWorld();
        world.getHandle().addBlockEvent(new BlockPos(getX(), getY(), getZ()), CraftMagicNumbers.getBlock(block), instrument.getType(), note.getId());
        return true;
    } else {
        return false;
    }
}