com.comphenix.protocol.ProtocolLibrary Java Examples

The following examples show how to use com.comphenix.protocol.ProtocolLibrary. 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: ChatItem.java    From ChatItem with GNU General Public License v3.0 6 votes vote down vote up
public static void reload(CommandSender sender) {
    ChatItem obj = getInstance();
    obj.pm = ProtocolLibrary.getProtocolManager();
    obj.saveDefaultConfig();
    obj.reloadConfig();
    obj.storage = new Storage(obj.getConfig());
    obj.packetListener.setStorage(obj.storage);
    obj.packetValidator.setStorage(obj.storage);
    obj.chatEventListener.setStorage(obj.storage);
    obj.filter.setStorage(obj.storage);
    APIImplementation api = (APIImplementation) Bukkit.getServicesManager().getRegistration(ChatItemAPI.class).getProvider();
    api.setStorage(obj.storage);
    api.updateLogger();
    if (!obj.storage.RELOAD_MESSAGE.isEmpty())
        sender.sendMessage(obj.storage.RELOAD_MESSAGE);
}
 
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: ProtocolLibLoginSource.java    From FastLogin with MIT License 6 votes vote down vote up
@Override
public void setOnlineMode() throws Exception {
    verifyToken = EncryptionUtil.generateVerifyToken(random);

    /*
     * Packet Information: https://wiki.vg/Protocol#Encryption_Request
     *
     * ServerID="" (String) key=public server key verifyToken=random 4 byte array
     */
    PacketContainer newPacket = new PacketContainer(ENCRYPTION_BEGIN);

    newPacket.getStrings().write(0, serverId);
    newPacket.getSpecificModifier(PublicKey.class).write(0, publicKey);

    newPacket.getByteArrays().write(0, verifyToken);

    //serverId is a empty string
    ProtocolLibrary.getProtocolManager().sendServerPacket(player, newPacket);
}
 
Example #4
Source File: ProtocolLibPacketHandler.java    From NameTagChanger with MIT License 6 votes vote down vote up
@Override
public void sendNamedEntitySpawnPacket(Player playerToSpawn, Player seer) {
    PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
    packet.getIntegers().write(0, playerToSpawn.getEntityId());
    packet.getUUIDs().write(0, playerToSpawn.getUniqueId());
    if (ReflectUtil.isVersionHigherThan(1, 8, 8)) {
        packet.getDoubles().write(0, playerToSpawn.getLocation().getX());
        packet.getDoubles().write(1, playerToSpawn.getLocation().getY());
        packet.getDoubles().write(2, playerToSpawn.getLocation().getZ());
    } else {
        packet.getIntegers().write(0, (int) Math.floor(playerToSpawn.getLocation().getX() * 32D));
        packet.getIntegers().write(1, (int) Math.floor(playerToSpawn.getLocation().getY() * 32D));
        packet.getIntegers().write(2, (int) Math.floor(playerToSpawn.getLocation().getZ() * 32D));
    }
    packet.getBytes().write(0, (byte) (playerToSpawn.getLocation().getYaw() * 256F / 360F));
    packet.getBytes().write(1, (byte) (playerToSpawn.getLocation().getPitch() * 256F / 360F));
    packet.getDataWatcherModifier().write(0, WrappedDataWatcher.getEntityWatcher(playerToSpawn));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet);
    } catch (InvocationTargetException e) {
        logMessage(Level.SEVERE, "Failed to send named entity spawn packet!", e);
    }
}
 
Example #5
Source File: AACAdditionPro.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDisable()
{
    // Plugin is already disabled -> VerboseSender is not allowed to register a task
    VerboseSender.getInstance().setAllowedToRegisterTasks(false);

    // Remove all the Listeners, PacketListeners
    ProtocolLibrary.getProtocolManager().removePacketListeners(this);
    HandlerList.unregisterAll(AACAdditionPro.getInstance());

    DataUpdaterEvents.INSTANCE.unregister();

    VerboseSender.getInstance().sendVerboseMessage("AACAdditionPro disabled.", true, false);
    VerboseSender.getInstance().sendVerboseMessage(" ", true, false);

    // Task scheduling
    loaded = false;
}
 
Example #6
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 #7
Source File: VanishIndication.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendPlayerInfoChangeGameModePacket(Player p, Player change, boolean spectator) {
    PacketContainer packet = new PacketContainer(PLAYER_INFO);
    packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
    List<PlayerInfoData> data = new ArrayList<>();
    int ping = ThreadLocalRandom.current().nextInt(20) + 15;
    data.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(change), ping,
            spectator ? EnumWrappers.NativeGameMode.SPECTATOR
                    : EnumWrappers.NativeGameMode.fromBukkit(change.getGameMode()),
            WrappedChatComponent.fromText(change.getPlayerListName())));
    packet.getPlayerInfoDataLists().write(0, data);
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example #8
Source File: PlayerHider.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void modifyInformation(final Player observer, final Entity entity)
{
    validate(observer, entity);

    if (setModifyInformation(observer, entity.getEntityId(), false)) {
        //Create new packet which destroys the entity
        final PacketContainer destroyEntity = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
        destroyEntity.getIntegerArrays().write(0, new int[]{entity.getEntityId()});

        // Make the entity disappear
        try {
            ProtocolLibrary.getProtocolManager().sendServerPacket(observer, destroyEntity);
        } catch (final InvocationTargetException e) {
            throw new RuntimeException("Cannot send server packet.", e);
        }
    }
}
 
Example #9
Source File: NightVision.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendAddPotionEffect(Player p, PotionEffect effect) {
    PacketContainer packet = new PacketContainer(ENTITY_EFFECT);
    //noinspection deprecation
    int effectID = effect.getType().getId();
    int amplifier = effect.getAmplifier();
    int duration = effect.getDuration();
    int entityID = p.getEntityId();
    packet.getIntegers().write(0, entityID);
    packet.getBytes().write(0, (byte) effectID);
    packet.getBytes().write(1, (byte) amplifier);
    packet.getIntegers().write(1, duration);
    // hide particles in 1.9
    packet.getBytes().write(2, (byte) 0);
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example #10
Source File: NightVision.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendRemovePotionEffect(Player p, PotionEffectType type) {
    PacketContainer packet = new PacketContainer(REMOVE_ENTITY_EFFECT);
    //noinspection deprecation
    final int effectID = type.getId();
    final int entityID = p.getEntityId();
    // 1.7 and below
    if (!plugin.getVersionUtil().isOneDotXOrHigher(8)) {
        packet.getIntegers().write(0, entityID);
        packet.getBytes().write(0, (byte) effectID);
    } else if (plugin.getVersionUtil().isOneDotX(8)) {
        // 1.8
        packet.getIntegers().write(0, entityID);
        packet.getIntegers().write(1, effectID);
    } else {
        // 1.9 and higher
        packet.getEffectTypes().write(0, type);
        packet.getIntegers().write(0, entityID);
    }
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example #11
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 #12
Source File: NameCheckTask.java    From FastLogin with MIT License 5 votes vote down vote up
@Override
public void run() {
    try {
        super.onLogin(username, new ProtocolLibLoginSource(packetEvent, player, random, publicKey));
    } finally {
        ProtocolLibrary.getProtocolManager().getAsynchronousManager().signalPacketTransmission(packetEvent);
    }
}
 
Example #13
Source File: PacketInterceptor.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
public PacketInterceptor(Conversation conv, String playerID) {
    this.conv = conv;
    this.player = PlayerConverter.getPlayer(playerID);

    // Intercept Packets
    packetAdapter = new PacketAdapter(BetonQuest.getInstance(), ListenerPriority.HIGHEST,
            PacketType.Play.Server.CHAT

    ) {
        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPlayer() != player) {
                return;
            }

            if (event.getPacketType().equals(PacketType.Play.Server.CHAT)) {
                PacketContainer packet = event.getPacket();
                BaseComponent[] bc = (BaseComponent[]) packet.getModifier().read(1);
                if (bc != null && bc.length > 0 && ((TextComponent) bc[0]).getText().contains("_bq_")) {
                    packet.getModifier().write(1, Arrays.copyOfRange(bc, 1, bc.length));
                    event.setPacket(packet);
                    return;
                }

                // Else save message to replay later
                WrapperPlayServerChat chat = new WrapperPlayServerChat(event.getPacket());
                event.setCancelled(true);
                messages.add(chat);
            }
        }
    };

    ProtocolLibrary.getProtocolManager().addPacketListener(packetAdapter);
}
 
Example #14
Source File: EntityHider.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Construct a new entity hider.
 *
 * @param plugin - the plugin that controls this entity hider.
 * @param policy - the default visibility policy.
 */
public EntityHider(Plugin plugin, Policy policy) {
    Preconditions.checkNotNull(plugin, "plugin cannot be NULL.");

    // Save policy
    this.policy = policy;
    this.manager = ProtocolLibrary.getProtocolManager();

    // Register events and packet listener
    plugin.getServer().getPluginManager().registerEvents(
            bukkitListener = constructBukkit(), plugin);
    manager.addPacketListener(
            protocolListener = constructProtocol(plugin));
}
 
Example #15
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 #16
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 #17
Source File: PlayerScoreboard.java    From ScoreboardStats with MIT License 5 votes vote down vote up
void sendPacket(PacketContainer packet) {
    //add metadata that we ignore our packets on the listener
    packet.addMetadata("ScoreboardStats", true);

    try {
        //false so we don't listen to our own packets
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
    } catch (InvocationTargetException ex) {
        //just log it for now.
        plugin.getLog().info("Failed to send packet", ex);
    }
}
 
Example #18
Source File: PacketInterceptor.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void end() {
    // Stop Listening for Packets
    ProtocolLibrary.getProtocolManager().removePacketListener(packetAdapter);

    // Send all messages to player
    for (WrapperPlayServerChat message : messages) {
        message.sendPacket(player);
    }
}
 
Example #19
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 #20
Source File: HardcoreHeartsModule.java    From UHC with MIT License 5 votes vote down vote up
@Override
public void initialize() throws InvalidConfigurationException {
    // make sure to enable the respawn module
    respawnModule.enable();

    if (!respawnModule.isEnabled()) {
        throw new InvalidConfigurationException(
                "Error enabling the respawn module. The respawn module is required to run hardcore hearts"
        );
    }

    ProtocolLibrary.getProtocolManager().addPacketListener(new HardcoreHeartsListener());

    this.icon.setLore(messages.getRawStrings("lore"));
}
 
Example #21
Source File: ProtocolLibChannelInjector.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public void sendPacket(Player observer, Object packet) {
	try {
		ProtocolLibrary.getProtocolManager().sendServerPacket(observer, PacketContainer.fromPacket(packet));
	} catch(InvocationTargetException e) {
		if(VersionHelper.debug()) {
			iDisguise.getInstance().getLogger().log(Level.INFO, "Cannot send packet: " + packet.getClass().getSimpleName() + " to " + observer.getName(), e);
		}
	}
}
 
Example #22
Source File: VerifyResponseTask.java    From FastLogin with MIT License 5 votes vote down vote up
private void kickPlayer(String reason) {
    PacketContainer kickPacket = new PacketContainer(DISCONNECT);
    kickPacket.getChatComponents().write(0, WrappedChatComponent.fromText(reason));
    try {
        //send kick packet at login state
        //the normal event.getPlayer.kickPlayer(String) method does only work at play state
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, kickPacket);
        //tell the server that we want to close the connection
        player.kickPlayer("Disconnect");
    } catch (InvocationTargetException ex) {
        plugin.getLog().error("Error sending kick packet for: {}", player, ex);
    }
}
 
Example #23
Source File: ProtocolLibHandler.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean unregister() {
    if (listener != null) {
        ProtocolLibrary.getProtocolManager().removePacketListener(listener);
        this.listener = null;
        return true;
    } else
        return false;
}
 
Example #24
Source File: Packets.java    From tabbed with MIT License 5 votes vote down vote up
/**
 * Sends a list of ProtocolLib packets to a player.
 * @param player
 * @param packets
 * @return
 */
public static void send(Player player, List<PacketContainer> packets) {
    try {
        for (PacketContainer packet : packets)
            ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example #25
Source File: ServerUtils.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
public static int getProtocolVersion(Player p) {
    if(Hawk.USING_PLIB)
        return ProtocolLibrary.getProtocolManager().getProtocolVersion(p);
    if(Hawk.getServerVersion() == 7) {
        net.minecraft.server.v1_7_R4.PlayerConnection pConnection = ((org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer) p).getHandle().playerConnection;
        if(pConnection == null)
            return 5;
        return pConnection.networkManager.getVersion();
    }
    return 47;
}
 
Example #26
Source File: SpigotProtocolHackPacketListener.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
public SpigotProtocolHackPacketListener(EchoPetPlugin echoPetPlugin) {
    super(echoPetPlugin,
            ListenerPriority.HIGHEST,
            PacketType.Play.Server.SPAWN_ENTITY_LIVING,
            PacketType.Play.Server.ENTITY_METADATA);
    this.echoPetPlugin = echoPetPlugin;
    ProtocolLibrary.getProtocolManager().addPacketListener(this);
}
 
Example #27
Source File: AbstractPacket.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Send the current packet to the given receiver.
 *
 * @param receiver - the receiver.
 * @throws RuntimeException If the packet cannot be sent.
 */
public void sendPacket(Player receiver) {
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
                getHandle());
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet.", e);
    }
}
 
Example #28
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 #29
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 #30
Source File: TitledTabList.java    From tabbed with MIT License 5 votes vote down vote up
private void updateHeaderFooter() {
    PacketContainer packet = new PacketContainer(Server.PLAYER_LIST_HEADER_FOOTER);
    packet.getChatComponents().write(0, WrappedChatComponent.fromText(this.header == null ? "" : this.header));
    packet.getChatComponents().write(1, WrappedChatComponent.fromText(this.footer == null ? "" : this.footer));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(this.player, packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}