Search in sources :

Example 61 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftEventFactory method callPlayerInteractEvent.

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;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 62 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftEventFactory method callBlockMultiPlaceEvent.

/**
 * Block place methods
 */
public static BlockMultiPlaceEvent callBlockMultiPlaceEvent(World world, EntityPlayer who, EnumHand hand, List<BlockState> blockStates, 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);
    boolean canBuild = true;
    for (BlockState blockState : blockStates) {
        if (!canBuild(craftWorld, player, blockState.getX(), blockState.getZ())) {
            canBuild = false;
            break;
        }
    }
    org.bukkit.inventory.ItemStack item;
    if (hand == EnumHand.MAIN_HAND) {
        item = player.getInventory().getItemInMainHand();
    } else {
        item = player.getInventory().getItemInOffHand();
    }
    BlockMultiPlaceEvent event = new BlockMultiPlaceEvent(blockStates, blockClicked, item, player, canBuild);
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) CraftBlockState(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlockState) BlockState(org.bukkit.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 63 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftEventFactory method getPlayerBucketEvent.

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 == null ? Items.AIR : 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;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) Material(org.bukkit.Material) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 64 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftEventFactory method callBlockPlaceEvent.

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;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_12_R1.block.CraftBlock) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 65 with CraftWorld

use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Magma by magmafoundation.

the class CraftRabbit method setRabbitType.

@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));
}
Also used : EntityRabbit(net.minecraft.entity.passive.EntityRabbit) EntityAITasks(net.minecraft.entity.ai.EntityAITasks) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld) World(net.minecraft.world.World) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)147 Location (org.bukkit.Location)131 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)111 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)103 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)95 BlockPos (net.minecraft.core.BlockPos)83 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)74 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)66 ItemStack (org.bukkit.inventory.ItemStack)61 Block (org.bukkit.block.Block)57 LivingEntity (org.bukkit.entity.LivingEntity)54 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)53 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)47 ArrayList (java.util.ArrayList)43 World (org.bukkit.World)41 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)39 Entity (org.bukkit.entity.Entity)39 Level (net.minecraft.world.level.Level)38 List (java.util.List)34 GameProfile (com.mojang.authlib.GameProfile)32