Search in sources :

Example 21 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Mohist by MohistMC.

the class CraftEventFactory method getPlayerBucketEvent.

private static PlayerEvent getPlayerBucketEvent(boolean isFilling, ServerLevel world, net.minecraft.world.entity.player.Player who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, net.minecraft.world.item.Item item) {
    Player player = (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());
    CraftServer craftServer = (CraftServer) player.getServer();
    Block block = CraftBlock.at(world, changed);
    Block blockClicked = CraftBlock.at(world, clicked);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
    PlayerEvent event;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
    } else {
        event = new PlayerBucketEmptyEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
    }
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) BlockFace(org.bukkit.block.BlockFace) PlayerEvent(org.bukkit.event.player.PlayerEvent) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) Material(org.bukkit.Material) PlayerBucketEmptyEvent(org.bukkit.event.player.PlayerBucketEmptyEvent)

Example 22 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Mohist by MohistMC.

the class CraftEventFactory method callInventoryOpenEvent.

public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
    if (player.containerMenu != player.inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId));
    }
    CraftServer server = player.level.getCraftServer();
    CraftPlayer craftPlayer = player.getBukkitEntity();
    player.containerMenu.transferTo(container, craftPlayer);
    InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
    event.setCancelled(cancelled);
    server.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        container.transferTo(player.containerMenu, craftPlayer);
        return null;
    }
    return container;
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)

Example 23 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Magma by magmafoundation.

the class CraftEventFactory method canBuild.

// helper methods
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;
}
Also used : WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) CraftServer(org.bukkit.craftbukkit.v1_12_R1.CraftServer)

Example 24 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer 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 25 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer 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)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)49 CraftServer (org.bukkit.craftbukkit.v1_16_R3.CraftServer)38 Player (org.bukkit.entity.Player)33 CraftServer (org.bukkit.craftbukkit.v1_18_R2.CraftServer)23 ResourceLocation (net.minecraft.resources.ResourceLocation)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)21 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)21 ServerPlayer (net.minecraft.server.level.ServerPlayer)20 Block (org.bukkit.block.Block)19 NotNull (org.jetbrains.annotations.NotNull)18 OfflinePlayer (org.bukkit.OfflinePlayer)16 CraftServer (org.bukkit.craftbukkit.v1_12_R1.CraftServer)16 ServerLevel (net.minecraft.server.level.ServerLevel)14 Property (com.mojang.authlib.properties.Property)13 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)11 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)10 BlockFace (org.bukkit.block.BlockFace)8 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)8 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)7