Search in sources :

Example 16 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Nokaut by smaks6.

the class CreateNPC method spawnNPC.

private EntityPlayer spawnNPC() {
    Location location = znokautowany.getLocation();
    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
    WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
    gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
    EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
    npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    npc.setPose(EntityPose.SWIMMING);
    PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
    npc.setPose(EntityPose.SWIMMING);
    DataWatcher watcher = npc.getDataWatcher();
    connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
    connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
    CraftPlayer craftPlayer = npc.getBukkitEntity();
    craftPlayer.setCollidable(false);
    return npc;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_16_R2.CraftServer) GameProfile(com.mojang.authlib.GameProfile) CraftWorld(org.bukkit.craftbukkit.v1_16_R2.CraftWorld) Location(org.bukkit.Location)

Example 17 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Nokaut by smaks6.

the class CreateNPC method spawnNPC.

private EntityPlayer spawnNPC() {
    Location location = znokautowany.getLocation();
    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
    WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
    gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
    EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
    npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    npc.setPose(EntityPose.SWIMMING);
    PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
    npc.setPose(EntityPose.SWIMMING);
    DataWatcher watcher = npc.getDataWatcher();
    connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
    connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
    CraftPlayer craftPlayer = npc.getBukkitEntity();
    craftPlayer.setCollidable(false);
    return npc;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) GameProfile(com.mojang.authlib.GameProfile) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Location(org.bukkit.Location)

Example 18 with CraftServer

use of org.bukkit.craftbukkit.v1_18_R2.CraftServer in project Nokaut by smaks6.

the class CreateNPC method spawnNPC.

private EntityPlayer spawnNPC() {
    Location location = znokautowany.getLocation();
    MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
    WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorld(znokautowany.getWorld().getName())).getHandle();
    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), ChatColor.RED + "*Nokaut*");
    gameProfile.getProperties().putAll(((CraftPlayer) znokautowany).getHandle().getProfile().getProperties());
    EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
    npc.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    // npc.setPose(EntityPose.SWIMMING);
    PlayerConnection connection = ((CraftPlayer) see).getHandle().playerConnection;
    // npc.setPose(EntityPose.SWIMMING);
    DataWatcher watcher = npc.getDataWatcher();
    connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
    connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), watcher, false));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.yaw * 256 / 360)));
    CraftPlayer craftPlayer = npc.getBukkitEntity();
    craftPlayer.setCollidable(false);
    return npc;
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_15_R1.CraftServer) GameProfile(com.mojang.authlib.GameProfile) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld) Location(org.bukkit.Location)

Example 19 with CraftServer

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

the class CraftEventFactory method callPlayerInteractEvent.

public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand 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 == InteractionHand.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_18_R2.inventory.CraftItemStack) 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) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)

Example 20 with CraftServer

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

the class CraftEventFactory method callBlockPlaceEvent.

public static BlockPlaceEvent callBlockPlaceEvent(ServerLevel world, net.minecraft.world.entity.player.Player who, InteractionHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
    CraftWorld craftWorld = world.getWorld();
    CraftServer craftServer = world.getCraftServer();
    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 == InteractionHand.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 : ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)

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