com.comphenix.protocol.events.PacketContainer Java Examples
The following examples show how to use
com.comphenix.protocol.events.PacketContainer.
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: ProtocolLibLoginSource.java From FastLogin with MIT License | 6 votes |
@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 #2
Source File: NightVision.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
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 #3
Source File: ForceFieldAdapter.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@Override public void onPacketSending(PacketEvent e) { if(e.isCancelled()) return; Player player = e.getPlayer(); ICombatManager combatManager = this.plugin.getCombatManager(); if(!combatManager.isInCombat(player)) return; UUID uuid = player.getUniqueId(); PacketContainer packet = e.getPacket(); World world = player.getWorld(); WrapperPlayServerBlockChange block = new WrapperPlayServerBlockChange(packet); Location location = packet.getBlockPositionModifier().read(0).toLocation(world); if(this.forceField.fakeBlocks.containsKey(uuid) && this.forceField.isSafe(location, player) && this.forceField.isSafeSurround(location, player) && ForceField.canPlace(location) && this.forceField.fakeBlocks.get(uuid).contains(location)) { block.setBlockData(this.forceField.wrappedData(block.getBlockData())); } }
Example #4
Source File: SkinApplier.java From ChangeSkin with MIT License | 6 votes |
private PacketContainer createRespawnPacket(NativeGameMode gamemode) throws ReflectiveOperationException { PacketContainer respawn = new PacketContainer(RESPAWN); Difficulty difficulty = EnumWrappers.getDifficultyConverter().getSpecific(receiver.getWorld().getDifficulty()); //<= 1.13.1 int dimensionId = receiver.getWorld().getEnvironment().getId(); respawn.getIntegers().writeSafely(0, dimensionId); //> 1.13.1 if (MinecraftVersion.getCurrentVersion().compareTo(MinecraftVersion.AQUATIC_UPDATE) > 0) { try { respawn.getDimensions().writeSafely(0, dimensionId); } catch (NoSuchMethodError noSuchMethodError) { throw new ReflectiveOperationException("Unable to find dimension setter. " + "Your ProtocolLib version is incompatible with this plugin version in combination with " + "Minecraft 1.13.1. " + "Try to download an update of ProtocolLib.", noSuchMethodError); } } respawn.getDifficulties().writeSafely(0, difficulty); respawn.getGameModes().write(0, gamemode); respawn.getWorldTypeModifier().write(0, receiver.getWorld().getWorldType()); return respawn; }
Example #5
Source File: PacketScoreboardObjective.java From helper with MIT License | 6 votes |
private PacketContainer newScorePacket(String name, int value, ScoreboardAction action) { // http://wiki.vg/Protocol#Update_Score PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_SCORE); // set "Entity name" - aka the name of the score - limited to 40. packet.getStrings().write(0, name); // set the action - 0 to create/update an item. 1 to remove an item. packet.getScoreboardActions().write(0, action); // set objective name - The name of the objective the score belongs to packet.getStrings().write(1, getId()); // set value of the score- The score to be displayed next to the entry. Only sent when Action does not equal 1. packet.getIntegers().write(0, value); return packet; }
Example #6
Source File: ProtocolLibPacketHandler.java From NameTagChanger with MIT License | 6 votes |
@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 #7
Source File: StructureCUI.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
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 #8
Source File: Packets.java From tabbed with MIT License | 5 votes |
/** * 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 #9
Source File: Objective.java From ScoreboardStats with MIT License | 5 votes |
private void sendScorePacket(String name, int score, ScoreboardAction action) { PacketContainer packet = new PacketContainer(SCOREBOARD_SCORE); packet.getStrings().write(0, name); packet.getStrings().write(1, objectiveId); packet.getIntegers().write(0, score); packet.getScoreboardActions().write(0, action); scoreboard.sendPacket(packet); }
Example #10
Source File: PacketIndividualHologramFactory.java From helper with MIT License | 5 votes |
@Override public void removeViewer(@Nonnull Player player) { if (!this.viewers.remove(player)) { return; } // handle removing the existing entity? PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); // set ids int[] ids = this.spawnedEntities.stream().mapToInt(HologramEntity::getId).toArray(); destroyPacket.getIntegerArrays().write(0, ids); Protocol.sendPacket(player, destroyPacket); }
Example #11
Source File: ProtocolLibPacketHandler.java From NameTagChanger with MIT License | 5 votes |
@Override public void sendEntityDestroyPacket(Player playerToDestroy, Player seer) { PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY); packet.getIntegerArrays().write(0, new int[] {playerToDestroy.getEntityId()}); try { ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet); } catch (InvocationTargetException e) { logMessage(Level.SEVERE, "Failed to send entity destroy packet!", e); } }
Example #12
Source File: ProtocolLibPacketHandler.java From NameTagChanger with MIT License | 5 votes |
@Override public void sendTabListRemovePacket(Player playerToRemove, Player seer) { PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); PlayerInfoData playerInfoData = new PlayerInfoData(WrappedGameProfile.fromPlayer(playerToRemove), 0, EnumWrappers.NativeGameMode.NOT_SET, null); packet.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); try { ProtocolLibrary.getProtocolManager().sendServerPacket(seer, packet); } catch (InvocationTargetException e) { logMessage(Level.SEVERE, "Failed to send tab list remove packet!", e); } }
Example #13
Source File: AbstractPacket.java From HolographicDisplays with GNU General Public License v3.0 | 5 votes |
/** * Constructs a new strongly typed wrapper for the given packet. * @param handle - handle to the raw packet data. * @param type - the packet type. */ protected AbstractPacket(PacketContainer handle, PacketType type) { // Make sure we're given a valid packet if (handle == null) throw new IllegalArgumentException("Packet handle cannot be NULL."); if (!Objects.equal(handle.getType(), type)) throw new IllegalArgumentException( handle.getHandle() + " is not a packet of type " + type); this.handle = handle; }
Example #14
Source File: StructureCUI.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
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 #15
Source File: ProtocolHandshakeListener.java From BungeeGuard with MIT License | 5 votes |
private static void closeConnection(Player player, String kickMessage) throws Exception { PacketContainer packet = new PacketContainer(PacketType.Login.Server.DISCONNECT); packet.getModifier().writeDefaults(); WrappedChatComponent component = WrappedChatComponent.fromJson(ComponentSerializer.toString(TextComponent.fromLegacyText(kickMessage))); packet.getChatComponents().write(0, component); ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); TemporaryPlayerFactory.getInjectorFromPlayer(player).getSocket().close(); }
Example #16
Source File: PacketInterceptor.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
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 #17
Source File: InventoryPacketAdapter.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Override public void onPacketSending(PacketEvent packetEvent) { Player player = packetEvent.getPlayer(); PacketContainer packet = packetEvent.getPacket(); int windowId = packet.getIntegers().read(0); if (windowId == PLAYER_INVENTORY && shouldHideInventory(player.getName())) { packetEvent.setCancelled(true); } }
Example #18
Source File: Objective.java From ScoreboardStats with MIT License | 5 votes |
void sendShowPacket() { PacketContainer packet = new PacketContainer(SCOREBOARD_DISPLAY_OBJECTIVE); packet.getStrings().write(0, objectiveId); packet.getIntegers().write(0, SIDEBAR_SLOT); scoreboard.sendPacket(packet); }
Example #19
Source File: VerifyResponseTask.java From FastLogin with MIT License | 5 votes |
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 #20
Source File: AbstractPacket.java From PacketWrapper with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructs a new strongly typed wrapper for the given packet. * @param handle - handle to the raw packet data. * @param type - the packet type. */ protected AbstractPacket(PacketContainer handle, PacketType type) { // Make sure we're given a valid packet if (handle == null) throw new IllegalArgumentException("Packet handle cannot be NULL."); if (!Objects.equal(handle.getType(), type)) throw new IllegalArgumentException( handle.getHandle() + " is not a packet of type " + type); this.handle = handle; }
Example #21
Source File: VirtualDisplayItem.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
private void sendPacket(@NotNull Player player, @NotNull PacketContainer packet) { try { protocolManager.sendServerPacket(player, packet); } catch (InvocationTargetException e) { throw new RuntimeException("An error occurred when sending a packet", e); } }
Example #22
Source File: WrapperPlayClientPosition.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayClientPosition() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); }
Example #23
Source File: ChatPacketValidator.java From ChatItem with GNU General Public License v3.0 | 4 votes |
public void onPacketSending(PacketEvent e){ if(ChatItem.supportsActionBar()) { //only if action bar messages are supported in this version of minecraft if(ChatItem.supportsChatTypeEnum()){ if(((Enum)e.getPacket().getSpecificModifier(ChatItem.getChatMessageTypeClass()).read(0)).name().equals("GAME_INFO")){ return; //It means it's an actionbar message, and we ain't intercepting those } }else if (e.getPacket().getBytes().readSafely(0) == (byte) 2) { return; //It means it's an actionbar message, and we ain't intercepting those } } boolean usesBaseComponents = false; PacketContainer packet = e.getPacket(); String json; if(packet.getChatComponents().readSafely(0)==null){ //null check for some cases of messages sent using spigot's Chat Component API or other means if(ChatItem.supportsChatComponentApi()){ //only if the API is supported in this server distribution BaseComponent[] components = packet.getSpecificModifier(BaseComponent[].class).readSafely(0); if(components == null){ return; } json = ComponentSerializer.toString(components); usesBaseComponents = true; }else{ return; //We don't know how to deal with anything else. Most probably some mod message we shouldn't mess with anyways } }else{ json = packet.getChatComponents().readSafely(0).getJson(); } boolean found = false; for (String rep : c.PLACEHOLDERS) if (json.contains(rep)) { found = true; break; } if (!found) { return; //then it's just a normal message without placeholders, so we leave it alone } if(json.lastIndexOf("\\u0007")==-1){ //if the message doesn't contain the BELL separator, then it's certainly NOT a message we want to parse return; } packet.addMetadata("parse", true); //We mark this packet to be parsed by the packet listener packet.addMetadata("base-component", usesBaseComponents); //We also tell it whether this packet uses the base component API packet.addMetadata("json", json); //And we finally provide it with the json we already got from the packet }
Example #24
Source File: WrapperPlayClientFlying.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayClientFlying(PacketContainer packet) { super(packet, TYPE); }
Example #25
Source File: WrapperPlayServerTileEntityData.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayServerTileEntityData() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); }
Example #26
Source File: WrapperPlayServerGameStateChange.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayServerGameStateChange(PacketContainer packet) { super(packet, TYPE); }
Example #27
Source File: WrapperPlayServerCraftProgressBar.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayServerCraftProgressBar(PacketContainer packet) { super(packet, TYPE); }
Example #28
Source File: WrapperPlayServerNamedEntitySpawn.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) { super(packet, TYPE); }
Example #29
Source File: WrapperPlayServerScoreboardDisplayObjective.java From PacketWrapper with GNU Lesser General Public License v3.0 | 4 votes |
public WrapperPlayServerScoreboardDisplayObjective(PacketContainer packet) { super(packet, TYPE); }
Example #30
Source File: WrapperPlayServerEntityMetadata.java From AACAdditionPro with GNU General Public License v3.0 | 4 votes |
public WrapperPlayServerEntityMetadata() { super(new PacketContainer(TYPE), TYPE); handle.getModifier().writeDefaults(); }