Java Code Examples for com.comphenix.protocol.ProtocolManager

The following examples show how to use com.comphenix.protocol.ProtocolManager. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void sendNbt(Vector pos, NbtCompound compound) {
    Player player = this.<Player>getPlayer().parent;
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();

    PacketContainer blockNbt = new PacketContainer(PacketType.Play.Server.TILE_ENTITY_DATA);
    blockNbt.getBlockPositionModifier().write(0, new BlockPosition(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()));
    blockNbt.getIntegers().write(0, 7);
    blockNbt.getNbtModifier().write(0, compound);


    try {
        manager.sendServerPacket(player, blockNbt);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source Project: FastLogin   Source File: ProtocolLibLoginSource.java    License: MIT License 6 votes vote down vote up
@Override
public void kick(String message) throws InvocationTargetException {
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

    PacketContainer kickPacket = new PacketContainer(DISCONNECT);
    kickPacket.getChatComponents().write(0, WrappedChatComponent.fromText(message));

    try {
        //send kick packet at login state
        //the normal event.getPlayer.kickPlayer(String) method does only work at play state
        protocolManager.sendServerPacket(player, kickPacket);
    } finally {
        //tell the server that we want to close the connection
        player.kickPlayer("Disconnect");
    }
}
 
Example 3
/**
 * Sends a blanked out packet to the given player in order to hide the inventory.
 *
 * @param player the player to send the blank inventory packet to
 */
public void sendBlankInventoryPacket(Player player) {
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
    PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
    inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
    int inventorySize = CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE + HOTBAR_SIZE;

    ItemStack[] blankInventory = new ItemStack[inventorySize];
    Arrays.fill(blankInventory, new ItemStack(Material.AIR));

    //old minecraft versions
    StructureModifier<ItemStack[]> itemArrayModifier = inventoryPacket.getItemArrayModifier();
    if (itemArrayModifier.size() > 0) {
        itemArrayModifier.write(0, blankInventory);
    } else {
        //minecraft versions above 1.11
        StructureModifier<List<ItemStack>> itemListModifier = inventoryPacket.getItemListModifier();
        itemListModifier.write(0, Arrays.asList(blankInventory));
    }

    try {
        protocolManager.sendServerPacket(player, inventoryPacket, false);
    } catch (InvocationTargetException invocationExc) {
        logger.logException("Error during sending blank inventory", invocationExc);
    }
}
 
Example 4
Source Project: CombatLogX   Source File: ForceField.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void unregisterProtocol() {
    PluginManager pluginManager = Bukkit.getPluginManager();
    if(!pluginManager.isPluginEnabled("ProtocolLib")) return;

    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    manager.removePacketListeners(this.plugin.getPlugin());
}
 
Example 5
Source Project: CombatLogX   Source File: AbstractPacket.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void sendPacket(Player player) {
    try {
        ProtocolManager manager = ProtocolLibrary.getProtocolManager();
        manager.sendServerPacket(player, getHandle());
    } catch(InvocationTargetException ex) {
        throw new RuntimeException("Cannot send packet", ex);
    }
}
 
Example 6
Source Project: CombatLogX   Source File: AbstractPacket.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void receivePacket(Player player) {
    try {
        ProtocolManager manager = ProtocolLibrary.getProtocolManager();
        manager.recieveClientPacket(player, getHandle());
    } catch(InvocationTargetException | IllegalAccessException ex) {
        throw new RuntimeException("Cannot receive packet", ex);
    }
}
 
Example 7
@Override
public void sendChunkUpdatePLIB(FaweChunk chunk, FawePlayer... players) {
    PlayerChunkMap playerManager = ((CraftWorld) getWorld()).getHandle().getPlayerChunkMap();
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    WirePacket packet = null;
    try {
        for (int i = 0; i < players.length; i++) {
            CraftPlayer bukkitPlayer = ((CraftPlayer) ((BukkitPlayer) players[i]).parent);
            EntityPlayer player = bukkitPlayer.getHandle();

            if (playerManager.a(player, chunk.getX(), chunk.getZ())) {
                if (packet == null) {
                    byte[] data;
                    byte[] buffer = new byte[8192];
                    if (chunk instanceof LazyFaweChunk) {
                        chunk = (FaweChunk) chunk.getChunk();
                    }
                    if (chunk instanceof MCAChunk) {
                        data = new MCAChunkPacket((MCAChunk) chunk, true, true, hasSky()).apply(buffer);
                    } else {
                        data = new FaweChunkPacket(chunk, true, true, hasSky()).apply(buffer);
                    }
                    packet = new WirePacket(PacketType.Play.Server.MAP_CHUNK, data);
                }
                manager.sendWirePacket(bukkitPlayer, packet);
            }
        }
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
private void sendOp() {
    Player player = this.<Player>getPlayer().parent;
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();

    PacketConstructor statusCtr = manager.createPacketConstructor(PacketType.Play.Server.ENTITY_STATUS, player, (byte) 28);
    PacketContainer status = statusCtr.createPacket(player, (byte) 28);

    try {
        manager.sendServerPacket(player, status);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example 9
public void sendChunkUpdatePLIB(FaweChunk chunk, FawePlayer... players) {
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    WirePacket packet = null;
    int viewDistance = Bukkit.getViewDistance();
    try {
        for (int i = 0; i < players.length; i++) {
            int cx = chunk.getX();
            int cz = chunk.getZ();

            Player player = ((BukkitPlayer) players[i]).parent;
            Location loc = player.getLocation();

            if (Math.abs((loc.getBlockX() >> 4) - cx) <= viewDistance && Math.abs((loc.getBlockZ() >> 4) - cz) <= viewDistance) {
                if (packet == null) {
                    byte[] data;
                    byte[] buffer = new byte[8192];
                    if (chunk instanceof LazyFaweChunk) {
                        chunk = (FaweChunk) chunk.getChunk();
                    }
                    if (chunk instanceof MCAChunk) {
                        data = new MCAChunkPacket((MCAChunk) chunk, true, true, hasSky()).apply(buffer);
                    } else {
                        data = new FaweChunkPacket(chunk, true, true, hasSky()).apply(buffer);
                    }
                    packet = new WirePacket(PacketType.Play.Server.MAP_CHUNK, data);
                }
                manager.sendWirePacket(player, packet);
            }
        }
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source Project: ChangeSkin   Source File: SkinApplier.java    License: MIT License 5 votes vote down vote up
private void sendPackets(PacketContainer... packets) {
    try {
        ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
        for (PacketContainer packet : packets) {
            protocolManager.sendServerPacket(receiver, packet);
        }
    } catch (InvocationTargetException ex) {
        plugin.getLog().error("Exception sending instant skin change packet for: {}", receiver, ex);
    }
}
 
Example 11
public List<Entity> getPassengers(World world) {
    int[] ids = getPassengerIds();
    List<Entity> passengers = new ArrayList<>();
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();

    for (int id : ids) {
        Entity entity = manager.getEntityFromID(world, id);
        if (entity != null) {
            passengers.add(entity);
        }
    }

    return passengers;
}
 
Example 12
Source Project: CombatLogX   Source File: ForceField.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void registerProtocol() {
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    PacketAdapter adapter = new ForceFieldAdapter(this);
    manager.addPacketListener(adapter);
}
 
Example 13
Source Project: CombatLogX   Source File: AbstractPacket.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void broadcastPacket() {
    ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    manager.broadcastServerPacket(getHandle());
}
 
Example 14
Source Project: UHC   Source File: ActionBarMessenger.java    License: MIT License 4 votes vote down vote up
public ActionBarMessenger(ProtocolManager manager) {
    this.manager = manager;
}
 
Example 15
Source Project: HeavySpleef   Source File: ProtocolLibHook.java    License: GNU General Public License v3.0 4 votes vote down vote up
public ProtocolManager getProtocolManager() {
	return ProtocolLibrary.getProtocolManager();
}
 
Example 16
Source Project: helper   Source File: Protocol.java    License: MIT License 2 votes vote down vote up
/**
 * Gets the protocol manager.
 *
 * @return the protocol manager.
 */
@Nonnull
public static ProtocolManager manager() {
    return ProtocolLibrary.getProtocolManager();
}