Java Code Examples for com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket#Flag

The following examples show how to use com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket#Flag . 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: AdventureSettingsSerializer_v354.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 2
Source File: AdventureSettingsSerializer_v354.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 3
Source File: AdventureSettingsSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 4
Source File: AdventureSettingsSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 5
Source File: AdventureSettingsSerializer_v340.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 6
Source File: AdventureSettingsSerializer_v340.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 7
Source File: AdventureSettingsSerializer_v313.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 8
Source File: AdventureSettingsSerializer_v313.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 9
Source File: AdventureSettingsSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 10
Source File: AdventureSettingsSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 11
Source File: AdventureSettingsSerializer_v332.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 12
Source File: AdventureSettingsSerializer_v332.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 13
Source File: AdventureSettingsSerializer_v291.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = 0;
    int flags2 = 0;
    for (AdventureSettingsPacket.Flag flag : packet.getFlags()) {
        if (FLAGS_TO_BIT_1.containsKey(flag)) {
            flags1 |= FLAGS_TO_BIT_1.get(flag);
        } else if (FLAGS_TO_BIT_2.containsKey(flag)) {
            flags2 |= FLAGS_TO_BIT_2.get(flag);
        }
    }
    VarInts.writeUnsignedInt(buffer, flags1);
    VarInts.writeUnsignedInt(buffer, packet.getCommandPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, flags2);
    VarInts.writeUnsignedInt(buffer, packet.getPlayerPermission().ordinal());
    VarInts.writeUnsignedInt(buffer, 0); // Useless
    buffer.writeLongLE(packet.getUniqueEntityId());
}
 
Example 14
Source File: AdventureSettingsSerializer_v291.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AdventureSettingsPacket packet) {
    int flags1 = VarInts.readUnsignedInt(buffer);
    packet.setCommandPermission(COMMAND_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    int flags2 = VarInts.readUnsignedInt(buffer);
    packet.setPlayerPermission(PLAYER_PERMISSIONS[VarInts.readUnsignedInt(buffer)]);
    VarInts.readUnsignedInt(buffer); // useless
    packet.setUniqueEntityId(buffer.readLongLE());

    Set<AdventureSettingsPacket.Flag> flags = packet.getFlags();
    for (int i = 0; i < FLAGS_1.length; i++) {
        if ((flags1 & (1 << i)) != 0) {
            flags.add(FLAGS_1[i]);
        }
    }

    for (int i = 0; i < FLAGS_2.length; i++) {
        if ((flags2 & (1 << i)) != 0) {
            flags.add(FLAGS_2[i]);
        }
    }
}
 
Example 15
Source File: JavaPlayerAbilitiesTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerPlayerAbilitiesPacket packet, GeyserSession session) {
    Entity entity = session.getPlayerEntity();
    if (entity == null)
        return;

    EntityDataMap metadata = entity.getMetadata();
    metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());

    SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
    entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
    entityDataPacket.getMetadata().putAll(metadata);
    session.sendUpstreamPacket(entityDataPacket);

    Set<AdventureSettingsPacket.Flag> playerFlags = new ObjectOpenHashSet<>();
    playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
    if (packet.isCanFly())
        playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);

    if (packet.isFlying())
        playerFlags.add(AdventureSettingsPacket.Flag.FLYING);

    AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
    adventureSettingsPacket.setPlayerPermission(PlayerPermission.MEMBER);
    // Required or the packet simply is not sent
    adventureSettingsPacket.setCommandPermission(CommandPermission.NORMAL);
    adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
    adventureSettingsPacket.getFlags().addAll(playerFlags);
    session.sendUpstreamPacket(adventureSettingsPacket);
}