Search in sources :

Example 36 with CraftServer

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

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

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

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

Example 40 with CraftServer

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

the class CommandDispatcherHook method onRegisterPost.

public static <S> void onRegisterPost(RootCommandNode<S> root, CommandNode<S> child) {
    if (Bukkit.getServer() instanceof CraftServer) {
        CraftServer craftServer = (CraftServer) Bukkit.getServer();
        if (craftServer.isVanillaCommandRegistered && !craftServer.isSyncingCommand && !(child.getCommand() instanceof BukkitCommandWrapper)) {
            Commands dispatcher = craftServer.getServer().getCommands();
            RootCommandNode<CommandSource> vanillaRoot = dispatcher.getDispatcher().getRoot();
            if (root == vanillaRoot) {
                craftServer.getCommandMap().register("minecraft", new VanillaCommandWrapper(dispatcher, (CommandNode<CommandSource>) child));
            }
        }
    }
}
Also used : CommandNode(com.mojang.brigadier.tree.CommandNode) RootCommandNode(com.mojang.brigadier.tree.RootCommandNode) BukkitCommandWrapper(org.bukkit.craftbukkit.v1_16_R3.command.BukkitCommandWrapper) Commands(net.minecraft.command.Commands) VanillaCommandWrapper(org.bukkit.craftbukkit.v1_16_R3.command.VanillaCommandWrapper) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) CommandSource(net.minecraft.command.CommandSource)

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