com.comphenix.protocol.PacketType Java Examples

The following examples show how to use com.comphenix.protocol.PacketType. 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: ProtocolLibListener.java    From FastLogin with MIT License 6 votes vote down vote up
@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 #2
Source File: ChunkPacketProcessor.java    From PacketWrapper with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Construct a chunk packet processor from a givne MAP_CHUNK packet.
 * @param packet - the map chunk packet.
 * @return The chunk packet processor.
 */
public static ChunkPacketProcessor fromMapPacket(PacketContainer packet, World world) {
	if (!packet.getType().equals(PacketType.Play.Server.MAP_CHUNK))
		throw new IllegalArgumentException(packet + " must be a MAP_CHUNK packet.");
	
	StructureModifier<Integer> ints = packet.getIntegers();
	StructureModifier<byte[]> byteArray = packet.getByteArrays();
    
    // Create an info objects
	ChunkPacketProcessor processor = new ChunkPacketProcessor();
	processor.world = world;
    processor.chunkX = ints.read(0); 	 // packet.a;
    processor.chunkZ = ints.read(1); 	 // packet.b;
    processor.chunkMask = ints.read(2);  // packet.c;
    processor.extraMask = ints.read(3);  // packet.d;
    processor.data = byteArray.read(1);  // packet.inflatedBuffer;
    processor.startIndex = 0;

    if (packet.getBooleans().size() > 0) {
    	processor.hasContinous = packet.getBooleans().read(0);
    }
    return processor;
}
 
Example #3
Source File: ProtocolLibHook.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
public void sendPacket(Player player, Entity entity, boolean visible){
    PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
    // Cloning the packet and getting the entity involved.
    WrappedDataWatcher watcher = new WrappedDataWatcher(entity);
    WrappedDataWatcher.Serializer booleanSerializer = WrappedDataWatcher.Registry.get(Boolean.class);
    // Set if the tag is visible or not.
    watcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, booleanSerializer), visible);
    // Writing the stuff to the packet.
    packet.getEntityModifier(entity.getWorld()).write(0, entity);
    packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());

    // Send the new packet.
    try{
        protocolManager.sendServerPacket(player, packet);
    }catch (InvocationTargetException e){
        e.printStackTrace();
    }
}
 
Example #4
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 #5
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 #6
Source File: PacketListener.java    From ScoreboardStats with MIT License 6 votes vote down vote up
private void ensureMainThread(UUID uuid, PacketContainer packet) {
    Player player = Bukkit.getPlayer(uuid);
    if (player == null) {
        return;
    }

    PacketType packetType = packet.getType();
    if (packetType.equals(SCOREBOARD_SCORE)) {
        handleScorePacket(player, packet);
    } else if (packetType.equals(SCOREBOARD_OBJECTIVE)) {
        handleObjectivePacket(player, packet);
    } else if (packetType.equals(SCOREBOARD_DISPLAY_OBJECTIVE)) {
        handleDisplayPacket(player, packet);
    } else if (packetType.equals(SCOREBOARD_TEAM)) {
        handleTeamPacket(player, packet);
    }
}
 
Example #7
Source File: AnimationPattern.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected int process(User user, PacketEvent packetEvent)
{
    if (packetEvent.getPacketType() == PacketType.Play.Client.ARM_ANIMATION) {
        user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, false);
    } else {
        if (user.getDataMap().getBoolean(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED)) {
            user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, false);
            message = "PacketAnalysisData-Verbose | Player: " + user.getPlayer().getName() + " did not send animation packet after an attack.";
            return 10;
        }
    }

    if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
        // Make sure an arm animation packet is sent directly after an attack as it is the next packet in the client
        // code.
        final WrapperPlayClientUseEntity useEntityWrapper = new WrapperPlayClientUseEntity(packetEvent.getPacket());
        if (useEntityWrapper.getType() == EnumWrappers.EntityUseAction.ATTACK) {
            user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_ANIMATION_EXPECTED, true);
        }
        return 0;
    }
    return 0;
}
 
Example #8
Source File: PacketAnalysis.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPacketSending(PacketEvent event)
{
    if (event.isPlayerTemporary()) {
        return;
    }

    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    if (event.getPacketType() == PacketType.Play.Server.POSITION) {
        final WrapperPlayServerPosition newPositionWrapper = new WrapperPlayServerPosition(event.getPacket());

        // Ignore relative teleports.
        if (!newPositionWrapper.getFlags().isEmpty()) {
            return;
        }

        user.getDataMap().setValue(DataKey.PACKET_ANALYSIS_LAST_POSITION_FORCE_LOCATION, newPositionWrapper.getLocation(user.getPlayer().getWorld()));
        user.getTimestampMap().updateTimeStamp(TimestampKey.PACKET_ANALYSIS_LAST_POSITION_FORCE);
    }
}
 
Example #9
Source File: PacketScoreboardTeam.java    From helper with MIT License 6 votes vote down vote up
private PacketContainer newTeamMemberUpdatePacket(String player, MemberAction action) {
    // http://wiki.vg/Protocol#Teams
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_TEAM);

    // set team name - 	String (16)
    packet.getStrings().write(0, getId());

    // set mode
    switch (action) {
        case ADD:
            packet.getIntegers().write(GTEQ_1_13 ? 0 : 1, UpdateType.ADD_PLAYERS.getCode());
            break;
        case REMOVE:
            packet.getIntegers().write(GTEQ_1_13 ? 0 : 1, UpdateType.REMOVE_PLAYERS.getCode());
            break;
        default:
            throw new RuntimeException();
    }

    // set players - Array of String (40)
    packet.getSpecificModifier(Collection.class).write(0, Collections.singletonList(player));
    
    return packet;
}
 
Example #10
Source File: FlagCountdownTitles.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void sendTitle(SpleefPlayer player, String title, String subtitle) throws InvocationTargetException {
	Player bukkitPlayer = player.getBukkitPlayer();
	
	PacketContainer timesPacket = manager.createPacket(PacketType.Play.Server.TITLE);
	timesPacket.getTitleActions().write(0, TitleAction.TIMES);
	timesPacket.getIntegers().write(0, FADE_IN);
	timesPacket.getIntegers().write(1, SHOW_LENGTH);
	timesPacket.getIntegers().write(2, FADE_OUT);
	manager.sendServerPacket(bukkitPlayer, timesPacket);
	
	if (title != null) {
		PacketContainer titlePacket = manager.createPacket(PacketType.Play.Server.TITLE);
		titlePacket.getTitleActions().write(0, TitleAction.TITLE);
		titlePacket.getChatComponents().write(0, getChatComponent(title));
		manager.sendServerPacket(bukkitPlayer, titlePacket);
	}
	
	if (subtitle != null) {
		PacketContainer subtitlePacket = manager.createPacket(PacketType.Play.Server.TITLE);
		subtitlePacket.getTitleActions().write(0, TitleAction.SUBTITLE);
		subtitlePacket.getChatComponents().write(0, getChatComponent(subtitle));
		manager.sendServerPacket(bukkitPlayer, subtitlePacket);
	}
}
 
Example #11
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 #12
Source File: FlagShowBarriers.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
private void spawnBarrier(Vector vector) {
	PacketContainer packet = manager.createPacket(PacketType.Play.Server.WORLD_PARTICLES);
	packet.getParticles().write(0, Particle.BARRIER); //Particle itself
	packet.getFloat().write(0, (float)vector.getX()); //x
	packet.getFloat().write(1, (float)vector.getY()); //y
	packet.getFloat().write(2, (float)vector.getZ()); //z
	packet.getIntegers().write(0, 1); //Number of particles
	
	try {
		for (SpleefPlayer player : game.getPlayers()) {
			Player bukkitPlayer = player.getBukkitPlayer();
			manager.sendServerPacket(bukkitPlayer, packet);
		}
	} catch (InvocationTargetException e) {
		getHeavySpleef().getLogger().log(Level.SEVERE, "Exception occured while sending barrier particle packet", e);
	}
}
 
Example #13
Source File: PacketScoreboardObjective.java    From helper with MIT License 6 votes vote down vote up
private PacketContainer newObjectivePacket(UpdateType mode) {
    // http://wiki.vg/Protocol#Scoreboard_Objective
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.SCOREBOARD_OBJECTIVE);

    // set name - limited to String(16)
    packet.getStrings().write(0, getId());

    // set mode - 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.
    packet.getIntegers().write(0, mode.getCode());

    if (USING_CHAT_COMPONENTS) {
        // set display name - Component
        packet.getChatComponents().write(0, PacketScoreboard.toComponent(getDisplayName()));
    } else {
        // set display name - limited to String(16) - Only if mode is 0 or 2. The text to be displayed for the score
        packet.getStrings().write(1, getDisplayName());
    }

    // set type - either "integer" or "hearts"
    packet.getEnumModifier(HealthDisplay.class, 2).write(0, HealthDisplay.INTEGER);

    return packet;
}
 
Example #14
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 #15
Source File: ProtocolLibHandler.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override // Handshake
public void onPacketReceiving(PacketEvent event) {
    if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet

    PacketContainer packet = event.getPacket();
    if (packet.getProtocols().read(0) != PacketType.Protocol.STATUS) return;

    StatusRequest request = bukkit.getRequest(event.getPlayer().getAddress());
    request.setProtocolVersion(packet.getIntegers().read(0));

    String host = packet.getStrings().read(0);
    int port = packet.getIntegers().read(1);
    request.setTarget(host, port);
}
 
Example #16
Source File: AbstractPacket.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
    Preconditions.checkNotNull(handle, "Packet handle cannot be NULL.");
    Preconditions.checkArgument(Objects.equal(handle.getType(), type), handle.getHandle() + " is not a packet of type " + type);
    this.handle = handle;
}
 
Example #17
Source File: ProtocolLibPacketHandler.java    From NameTagChanger with MIT License 5 votes vote down vote up
@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 #18
Source File: TabCompletePacketAdapter.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPacketReceiving(PacketEvent event) {
    if (event.getPacketType() == PacketType.Play.Client.TAB_COMPLETE) {
        try {
            if (!playerCache.isAuthenticated(event.getPlayer().getName())) {
                event.setCancelled(true);
            }
        } catch (FieldAccessException e) {
            logger.logException("Couldn't access field:", e);
        }
    }
}
 
Example #19
Source File: ChunkPacketProcessor.java    From PacketWrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Construct an array of chunk packet processors from a given MAP_CHUNK_BULK packet.
 * @param packet - the map chunk bulk packet.
 * @return The chunk packet processors.
 */
public static ChunkPacketProcessor[] fromMapBulkPacket(PacketContainer packet, World world) {
	if (!packet.getType().equals(PacketType.Play.Server.MAP_CHUNK_BULK))
		throw new IllegalArgumentException(packet + " must be a MAP_CHUNK_BULK packet.");
	
	StructureModifier<int[]> intArrays = packet.getIntegerArrays();
	StructureModifier<byte[]> byteArrays = packet.getByteArrays();
	
    int[] x = intArrays.read(0); // packet.c;
    int[] z = intArrays.read(1); // packet.d;
	
    ChunkPacketProcessor[] processors = new ChunkPacketProcessor[x.length];

    int[] chunkMask = intArrays.read(2); // packet.a;
    int[] extraMask = intArrays.read(3); // packet.b;
    int dataStartIndex = 0;
    
    for (int chunkNum = 0; chunkNum < processors.length; chunkNum++) {
        // Create an info objects
    	ChunkPacketProcessor processor = new ChunkPacketProcessor();
        processors[chunkNum] = processor;
        processor.world = world;
        processor.chunkX = x[chunkNum];
        processor.chunkZ = z[chunkNum];
        processor.chunkMask = chunkMask[chunkNum];
        processor.extraMask = extraMask[chunkNum];
        processor.hasContinous = true; // Always true
        processor.data = byteArrays.read(1); //packet.buildBuffer;
        
        // Check for Spigot
        if (processor.data == null || processor.data.length == 0) {
        	processor.data = packet.getSpecificModifier(byte[][].class).read(0)[chunkNum];
        } else {
        	processor.startIndex = dataStartIndex;
        }
        dataStartIndex += processor.size;
    }
    return processors;
}
 
Example #20
Source File: AbstractPacket.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
/**
 * 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: SkullPlaceHolders.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
public void init() {
    Bukkit.getPluginManager().registerEvents(this, voxelGamesLib);

    registerPlaceholders();

    // listener
    protocolManager.addPacketListener(new PacketAdapter(voxelGamesLib, PacketType.Play.Server.TILE_ENTITY_DATA) {
        @Override
        public void onPacketSending(PacketEvent event) {
            WrapperPlayServerTileEntityData packet = new WrapperPlayServerTileEntityData(event.getPacket());
            event.setPacket(modifySkull(packet, event.getPlayer()));
        }
    });

    // search for already loaded skulls
    Bukkit.getWorlds().stream()
            .flatMap(w -> Arrays.stream(w.getLoadedChunks()))
            .flatMap(s -> Arrays.stream(s.getTileEntities()))
            .filter(s -> s instanceof Skull)
            .map(s -> (Skull) s)
            .forEach(s -> lastSeenSkulls.put(s.getLocation(), s));

    // update task
    new BukkitRunnable() {

        @Override
        public void run() {
            lastSeenSkulls.forEach((loc, skull) -> skull.update());
        }
    }.runTaskTimer(voxelGamesLib, 20, 20);
}
 
Example #22
Source File: AbstractPacket.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #23
Source File: KeepAlive.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
public KeepAlive()
{
    super(AACAdditionPro.getInstance(), ListenerPriority.LOW,
          // --------------- Server --------------- //
          // KeepAlive analysis
          PacketType.Play.Server.KEEP_ALIVE,
          // --------------- Client --------------- //
          // KeepAlive analysis
          PacketType.Play.Client.KEEP_ALIVE);
}
 
Example #24
Source File: Inventory.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
public Inventory()
{
    super(AACAdditionPro.getInstance(), ListenerPriority.LOWEST,
          // Look
          PacketType.Play.Client.LOOK,
          // Move
          PacketType.Play.Client.POSITION,
          PacketType.Play.Client.POSITION_LOOK);
}
 
Example #25
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 #26
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 #27
Source File: PacketAnalysis.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
public PacketAnalysis()
{
    super(AACAdditionPro.getInstance(), ListenerPriority.LOW,
          // --------------- Server --------------- //
          // Compare
          PacketType.Play.Server.POSITION,
          // --------------- Client --------------- //
          // CombatOrder
          PacketType.Play.Client.USE_ENTITY,
          PacketType.Play.Client.ARM_ANIMATION,
          // EqualRotation
          PacketType.Play.Client.LOOK,
          // EqualRotation + Compare
          PacketType.Play.Client.POSITION_LOOK);
}
 
Example #28
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private void sendBlockChange(Player plr, Vector pt, BaseBlock block) {
    PacketContainer container = new PacketContainer(PacketType.Play.Server.BLOCK_CHANGE);
    // Block position
    // block combined id
    container.getBlockPositionModifier().write(0, new BlockPosition(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()));
    WrappedBlockData bd = WrappedBlockData.createData(Material.getMaterial(block.getId()), block.getData());
    container.getBlockData().write(0, bd);
    try {
        protocolmanager.sendWirePacket(plr, WirePacket.fromPacket(container));
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example #29
Source File: HandshakeListener.java    From ChatItem with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPacketReceiving(final PacketEvent e){
    PacketType.Protocol p = e.getPacket().getProtocols().read(0);
    if(p == PacketType.Protocol.STATUS || p == PacketType.Protocol.LEGACY){
        return;
    }
    final int version = e.getPacket().getIntegers().readSafely(0);
    //Delay the mapping to make sure the true address of the player was received when using bungeecord or other types of proxies
    Bukkit.getScheduler().scheduleSyncDelayedTask(ChatItem.getInstance(), () ->
            ProtocolVersion.getPlayerVersionMap().put(ProtocolVersion.stringifyAdress(e.getPlayer().getAddress()), version), 10L);

}
 
Example #30
Source File: ChatPacketListener.java    From ChatItem with GNU General Public License v3.0 5 votes vote down vote up
public ChatPacketListener(Plugin plugin, ListenerPriority listenerPriority, Storage s, PacketType... types) {
    super(plugin, listenerPriority, types);
    if(ChatItem.supportsShulkerBoxes()){
        SHULKER_BOXES.addAll(Arrays.asList(Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
                Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX,
                Material.LIGHT_BLUE_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
                Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX,
                Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX));
    }
    c = s;
}