Java Code Examples for com.comphenix.protocol.events.PacketEvent#getPlayer()
The following examples show how to use
com.comphenix.protocol.events.PacketEvent#getPlayer() .
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: 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 2
Source File: ProtocolLibListener.java From FastLogin with MIT License | 6 votes |
@Override public void onPacketReceiving(PacketEvent packetEvent) { if (packetEvent.isCancelled() || plugin.getCore().getAuthPluginHook()== null || !plugin.isServerFullyStarted()) { return; } Player sender = packetEvent.getPlayer(); PacketType packetType = packetEvent.getPacketType(); if (packetType == START) { if (!rateLimiter.tryAcquire()) { plugin.getLog().warn("Rate Limit hit - Ignoring player {}", sender); return; } onLogin(packetEvent, sender); } else { onEncryptionBegin(packetEvent, sender); } }
Example 3
Source File: PacketListener.java From ScoreboardStats with MIT License | 6 votes |
@Override public void onPacketSending(PacketEvent packetEvent) { Player player = packetEvent.getPlayer(); if (packetEvent.isCancelled() || player instanceof Factory) { return; } PacketContainer packet = packetEvent.getPacket(); if (packet.hasMetadata("ScoreboardStats")) { //it's our own packet return; } UUID playerUUID = player.getUniqueId(); //handle async packets by other plugins if (Bukkit.isPrimaryThread()) { ensureMainThread(playerUUID, packet); } else { PacketContainer clone = packet.deepClone(); Bukkit.getScheduler().runTask(plugin, () -> ensureMainThread(playerUUID, clone)); } }
Example 4
Source File: DataUpdaterEvents.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
@Override public void onPacketReceiving(final PacketEvent event) { if (event.getPlayer() == null || event.isPlayerTemporary()) { return; } final User user = UserManager.getUser(event.getPlayer().getUniqueId()); if (user != null) { user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_VELOCITY_CHANGE); // The player wasn't hurt and got velocity for that. if (user.getPlayer().getNoDamageTicks() == 0 // Recent teleports can cause bugs && !user.hasTeleportedRecently(1000)) { final IWrapperPlayPosition position = event::getPacket; final boolean updatedPositiveVelocity = user.getPlayer().getLocation().getY() < position.getY(); if (updatedPositiveVelocity != user.getDataMap().getBoolean(DataKey.POSITIVE_VELOCITY)) { user.getDataMap().setValue(DataKey.POSITIVE_VELOCITY, updatedPositiveVelocity); user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_VELOCITY_CHANGE_NO_EXTERNAL_CAUSES); } } } }
Example 5
Source File: RemoveEffectPacketListener.java From WorldGuardExtraFlagsPlugin with MIT License | 5 votes |
@Override public void onPacketSending(PacketEvent event) { if (!event.isCancelled()) { Player player = event.getPlayer(); if (!player.isValid()) //Work around, getIfPresent is broken inside WG due to using LocalPlayer as key instead of CacheKey { return; } try { Session session = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getSessionManager().get(player); GiveEffectsFlagHandler giveEffectsHandler = session.getHandler(GiveEffectsFlagHandler.class); if (giveEffectsHandler.isSupressRemovePotionPacket()) { event.setCancelled(true); } } catch(IllegalStateException wgBug) { } } }
Example 6
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 7
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); } }