Search in sources :

Example 1 with BlockPosition

use of com.comphenix.protocol.wrappers.BlockPosition in project BetterRTP by SuperRonanCraft.

the class PortalsCache method cachePortal.

public void cachePortal(Player p, Location loc, boolean loc2) {
    PortalsRegionInfo portal;
    if (portalsBeingCreated.containsKey(p)) {
        portal = portalsBeingCreated.get(p);
    } else {
        portal = new PortalsRegionInfo();
        portalsBeingCreated.put(p, portal);
    }
    Location old_loc1 = portal.loc_1;
    Location old_loc2 = portal.loc_2;
    if (loc2)
        portal.loc_2 = loc;
    else
        portal.loc_1 = loc;
    if (portal.loc_1 != null && portal.loc_2 != null)
        if (old_loc1 == null || old_loc2 == null)
            addonPortals.msgs.getLocation_Ready(p);
    if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
        ProtocolManager pm = ProtocolLibrary.getProtocolManager();
        // if (portal.loc_1 != null && portal.loc_2 != null) {
        // if (Math.abs(portal.loc_1.getBlockX() - portal.loc_2.getBlockX()) <= 10)
        // if (Math.abs(portal.loc_1.getBlockZ() - portal.loc_2.getBlockZ()) <= 10)
        // if (Math.abs(portal.loc_1.getBlockY() - portal.loc_2.getBlockY()) <= 10) {
        // preview(portal.loc_1, portal.loc_2);
        // }
        /*Location max = portal.loc_1;
                Location min = portal.loc_2;
                for (int x = Math.max(max.getBlockX(), min.getBlockX()); x >= Math.min(min.getBlockX(), max.getBlockX()); x--) {
                    for (int y = Math.max(max.getBlockY(), min.getBlockY()); y >= Math.min(min.getBlockY(), max.getBlockY()); y--) {
                        for (int z = Math.max(max.getBlockZ(), min.getBlockZ()); z >= Math.min(min.getBlockZ(), max.getBlockZ()); z--) {
                            WrapperPlayServerBlockChange packet = new WrapperPlayServerBlockChange(pm.createPacket(PacketType.Play.Server.BLOCK_CHANGE));
                            packet.setBlockData(WrappedBlockData.createData(Material.REDSTONE_BLOCK));
                            packet.setLocation(new BlockPosition(new Location(max.getWorld(), x, y, z).toVector()));
                            packet.sendPacket(p);
                            //Block block = max.getWorld().getBlockAt(x, y, z);
                            //block.setType(Material.GLOWSTONE);
                        }
                    }
                }*/
        // } else {
        WrapperPlayServerBlockChange packet = new WrapperPlayServerBlockChange(pm.createPacket(PacketType.Play.Server.BLOCK_CHANGE));
        packet.setBlockData(WrappedBlockData.createData(Material.GLOWSTONE));
        packet.setLocation(new BlockPosition(loc.toVector()));
        packet.sendPacket(p);
    // }
    } else {
        try {
            if (loc2)
                p.sendBlockChange(portal.loc_2, Material.GLOWSTONE.createBlockData());
            else
                p.sendBlockChange(portal.loc_1, Material.GLOWSTONE.createBlockData());
        } catch (Exception e) {
        // Not 1.13+ (dont show block changes)
        }
    }
}
Also used : ProtocolManager(com.comphenix.protocol.ProtocolManager) WrapperPlayServerBlockChange(me.SuperRonanCraft.BetterRTPAddons.packets.WrapperPlayServerBlockChange) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) InvocationTargetException(java.lang.reflect.InvocationTargetException) Location(org.bukkit.Location)

Example 2 with BlockPosition

use of com.comphenix.protocol.wrappers.BlockPosition in project CriticalMiningTech by CriticalGameEror.

the class BlockDamage method configureBreakingPacket.

protected void configureBreakingPacket(double hardness, Player player, Block block) {
    PacketContainer breakingAnimation = manager.createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
    // this enusres that the player wont conflict with another player's breaking animation
    int entityId = player.getEntityId() + 1;
    entityId = entityId * 1000;
    breakingAnimation.getIntegers().write(0, entityId);
    breakingAnimation.getBlockPositionModifier().write(0, new BlockPosition(block.getX(), block.getY(), block.getZ()));
    breakingTimeCheck(hardness, player, block, breakingAnimation);
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition)

Example 3 with BlockPosition

use of com.comphenix.protocol.wrappers.BlockPosition in project WheelCore by Plugindustry.

the class PlayerUtil method sendBlockCrack.

public static void sendBlockCrack(@Nonnull Player player, @Nonnull Location location, int level) {
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
    packet.getIntegers().write(0, 0);
    packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector()));
    packet.getIntegers().write(1, level);
    try {
        WheelCore.protocolManager.sendServerPacket(player, packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with BlockPosition

use of com.comphenix.protocol.wrappers.BlockPosition in project WheelCore by Plugindustry.

the class TextureManager method generatePacket.

private static PacketContainer generatePacket(Location loc, ItemStack item) {
    PacketContainer packet = templatePacket.shallowClone();
    packet.getBlockPositionModifier().write(0, new BlockPosition(loc.toVector()));
    NbtCompound compound = NbtFactory.ofCompound(null);
    compound.put("Delay", (short) 160);
    compound.put("MaxNearbyEntities", (short) 0);
    compound.put("MaxSpawnDelay", (short) 800);
    compound.put("MinSpawnDelay", (short) 200);
    compound.put("RequiredPlayerRange", (short) 0);
    compound.put("SpawnCount", (short) 0);
    compound.put("SpawnRange", (short) 0);
    NbtCompound spawnDataCompound = NbtFactory.ofCompound(null);
    NbtCompound entityCompound = NbtFactory.ofCompound(null);
    entityCompound.put("id", "minecraft:item");
    entityCompound.put("Item", NbtFactory.fromNMS(ShadowManager.shadowUnpack(CraftItemStack.asNMSCopy(item).save(new NBTTagCompound())), null));
    spawnDataCompound.put("entity", entityCompound);
    compound.put("SpawnData", spawnDataCompound);
    packet.getNbtModifier().write(0, compound);
    return packet;
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) NbtCompound(com.comphenix.protocol.wrappers.nbt.NbtCompound) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) NBTTagCompound(io.github.plugindustry.wheelcore.internal.shadow.NBTTagCompound)

Example 5 with BlockPosition

use of com.comphenix.protocol.wrappers.BlockPosition in project WheelCore by Plugindustry.

the class PlayerUtil method broadcastBlockCrack.

public static void broadcastBlockCrack(@Nonnull Location location, int level) {
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.BLOCK_BREAK_ANIMATION);
    packet.getIntegers().write(0, 0);
    packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector()));
    packet.getIntegers().write(1, level);
    WheelCore.protocolManager.broadcastServerPacket(packet);
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition)

Aggregations

BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)20 PacketContainer (com.comphenix.protocol.events.PacketContainer)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Location (org.bukkit.Location)5 Player (org.bukkit.entity.Player)5 PacketAdapter (com.comphenix.protocol.events.PacketAdapter)3 PacketEvent (com.comphenix.protocol.events.PacketEvent)3 FieldAccessException (com.comphenix.protocol.reflect.FieldAccessException)3 WrapperPlayServerBed (com.comphenix.packetwrapper.WrapperPlayServerBed)2 ProtocolManager (com.comphenix.protocol.ProtocolManager)2 NbtCompound (com.comphenix.protocol.wrappers.nbt.NbtCompound)2 ItemStack (org.bukkit.inventory.ItemStack)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 Nullable (org.jetbrains.annotations.Nullable)2 Direction (com.comphenix.protocol.wrappers.EnumWrappers.Direction)1 MovingObjectPositionBlock (com.comphenix.protocol.wrappers.MovingObjectPositionBlock)1 Vector3F (com.comphenix.protocol.wrappers.Vector3F)1 WrappedBlockData (com.comphenix.protocol.wrappers.WrappedBlockData)1 WrappedChatComponent (com.comphenix.protocol.wrappers.WrappedChatComponent)1 WrappedDataWatcherObject (com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject)1