Search in sources :

Example 31 with CraftServer

use of org.bukkit.craftbukkit.v1_16_R1.CraftServer in project LoliServer by Loli-Server.

the class CraftEventFactory method callEntityTameEvent.

/**
 * EntityTameEvent
 */
public static EntityTameEvent callEntityTameEvent(MobEntity entity, PlayerEntity tamer) {
    org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
    org.bukkit.entity.AnimalTamer bukkitTamer = (tamer != null ? tamer.getBukkitEntity() : null);
    CraftServer craftServer = (CraftServer) bukkitEntity.getServer();
    entity.persistenceRequired = true;
    EntityTameEvent event = new EntityTameEvent((org.bukkit.entity.LivingEntity) bukkitEntity, bukkitTamer);
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) org.bukkit.event.entity(org.bukkit.event.entity) org.bukkit.entity(org.bukkit.entity)

Example 32 with CraftServer

use of org.bukkit.craftbukkit.v1_16_R1.CraftServer in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callInventoryOpenEvent.

public static Container callInventoryOpenEvent(ServerPlayerEntity player, Container container, boolean cancelled) {
    if (player.containerMenu != player.inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        player.connection.handleContainerClose(new CCloseWindowPacket(player.containerMenu.containerId));
    }
    CraftServer server = player.level.getServerCB();
    CraftPlayer craftPlayer = player.getBukkitEntity();
    try {
        player.containerMenu.transferTo(container, craftPlayer);
    } catch (AbstractMethodError e) {
    // Magma - modded
    }
    InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
    event.setCancelled(cancelled);
    if (container.getBukkitView() != null) {
        server.getPluginManager().callEvent(event);
    }
    if (event.isCancelled()) {
        container.transferTo(player.containerMenu, craftPlayer);
        if (!cancelled) {
            // fire INVENTORY_CLOSE if one already open
            player.containerMenu = container;
            player.closeContainer();
            player.containerMenu = player.inventoryMenu;
        }
        return null;
    }
    return container;
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer)

Example 33 with CraftServer

use of org.bukkit.craftbukkit.v1_16_R1.CraftServer in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callBlockPlaceEvent.

public static BlockPlaceEvent callBlockPlaceEvent(ServerWorld world, PlayerEntity who, Hand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
    CraftWorld craftWorld = world.getWorldCB();
    CraftServer craftServer = world.getServerCB();
    Player player = (Player) who.getBukkitEntity();
    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    Block placedBlock = replacedBlockState.getBlock();
    boolean canBuild = canBuild(world, player, placedBlock.getX(), placedBlock.getZ());
    org.bukkit.inventory.ItemStack item;
    EquipmentSlot equipmentSlot;
    if (hand == Hand.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 : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 34 with CraftServer

use of org.bukkit.craftbukkit.v1_16_R1.CraftServer in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method canBuild.

// helper methods
private static boolean canBuild(World world, Player player, int x, int z) {
    int spawnSize = Bukkit.getServer().getSpawnRadius();
    if (world.dimension() != World.OVERWORLD)
        return true;
    if (spawnSize <= 0)
        return true;
    if (((CraftServer) Bukkit.getServer()).getHandle().getOps().isEmpty())
        return true;
    if (player.isOp())
        return true;
    BlockPos chunkcoordinates = getSharedSpawnPos(world);
    int distanceFromSpawn = Math.max(Math.abs(x - chunkcoordinates.getX()), Math.abs(z - chunkcoordinates.getZ()));
    return distanceFromSpawn > spawnSize;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer)

Example 35 with CraftServer

use of org.bukkit.craftbukkit.v1_16_R1.CraftServer in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callBlockDamageEvent.

/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(PlayerEntity 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;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) BlockDamageEvent(org.bukkit.event.block.BlockDamageEvent) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)49 CraftServer (org.bukkit.craftbukkit.v1_16_R3.CraftServer)38 Player (org.bukkit.entity.Player)29 CraftServer (org.bukkit.craftbukkit.v1_18_R2.CraftServer)23 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 ResourceLocation (net.minecraft.resources.ResourceLocation)20 NotNull (org.jetbrains.annotations.NotNull)18 ServerPlayer (net.minecraft.server.level.ServerPlayer)16 OfflinePlayer (org.bukkit.OfflinePlayer)16 CraftServer (org.bukkit.craftbukkit.v1_12_R1.CraftServer)16 Block (org.bukkit.block.Block)15 ServerLevel (net.minecraft.server.level.ServerLevel)14 Property (com.mojang.authlib.properties.Property)13 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)11 CraftBlock (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock)10 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)8 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)7 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)7