com.comphenix.protocol.reflect.StructureModifier Java Examples

The following examples show how to use com.comphenix.protocol.reflect.StructureModifier. 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: 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 #2
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 #3
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector getRelPos(PacketEvent event, VirtualWorld generator) {
    PacketContainer packet = event.getPacket();
    StructureModifier<BlockPosition> position = packet.getBlockPositionModifier();
    BlockPosition loc = position.readSafely(0);
    if (loc == null) return null;
    Vector origin = generator.getOrigin();
    Vector pt = new Vector(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ());
    return pt;
}
 
Example #4
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private Vector getRelative(PacketEvent container, Vector pt) {
    PacketContainer packet = container.getPacket();
    StructureModifier<EnumWrappers.Direction> dirs = packet.getDirections();
    EnumWrappers.Direction dir = dirs.readSafely(0);
    if (dir == null) return pt;
    switch (dir.ordinal()) {
        case 0: return pt.add(0, -1, 0);
        case 1: return pt.add(0, 1, 0);
        case 2: return pt.add(0, 0, -1);
        case 3: return pt.add(0, 0, 1);
        case 4: return pt.add(-1, 0, 0);
        case 5: return pt.add(1, 0, 0);
        default: return pt;
    }
}
 
Example #5
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 #6
Source File: WrapperPlayServerPosition.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier()
{
    return handle.getSets(EnumWrappers.getGenericConverter(FLAGS_CLASS, PlayerTeleportFlag.class));
}