com.comphenix.protocol.ProtocolManager Java Examples

The following examples show how to use com.comphenix.protocol.ProtocolManager. 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
Source File: StructureCUI.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
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 File: ProtocolLibLoginSource.java    From FastLogin with 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
Source File: InventoryPacketAdapter.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: ForceField.java    From CombatLogX with 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 File: AbstractPacket.java    From CombatLogX with 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 File: AbstractPacket.java    From CombatLogX with 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
Source File: BukkitQueue_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@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
Source File: StructureCUI.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: BukkitQueue_0.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
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 File: SkinApplier.java    From ChangeSkin with 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
Source File: WrapperPlayServerMount.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
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 File: ForceField.java    From CombatLogX with 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 File: AbstractPacket.java    From CombatLogX with 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 File: ActionBarMessenger.java    From UHC with MIT License 4 votes vote down vote up
public ActionBarMessenger(ProtocolManager manager) {
    this.manager = manager;
}
 
Example #15
Source File: ProtocolLibHook.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public ProtocolManager getProtocolManager() {
	return ProtocolLibrary.getProtocolManager();
}
 
Example #16
Source File: Protocol.java    From helper with MIT License 2 votes vote down vote up
/**
 * Gets the protocol manager.
 *
 * @return the protocol manager.
 */
@Nonnull
public static ProtocolManager manager() {
    return ProtocolLibrary.getProtocolManager();
}