Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
hax0r31337 committed Apr 23, 2023
1 parent d03a44e commit b366437
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ default Object readTagLE(ByteBuf buffer) {

void readPlayerAbilities(ByteBuf buffer, PlayerAbilityHolder abilityHolder);

PlayerPermission readPlayerPermission(ByteBuf buffer);
PlayerPermission readPlayerPermission(int ordinal);

void writePlayerPermission(ByteBuf buffer, PlayerPermission permission);
int writePlayerPermission(PlayerPermission permission);
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ public void readPlayerAbilities(ByteBuf buffer, PlayerAbilityHolder abilityHolde
}

@Override
public PlayerPermission readPlayerPermission(ByteBuf buffer) {
public PlayerPermission readPlayerPermission(final int ordinal) {
throw new UnsupportedOperationException();
}

@Override
public void writePlayerPermission(ByteBuf buffer, PlayerPermission permission) {
public int writePlayerPermission(PlayerPermission permission) {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ public <T> void writeOptional(ByteBuf buffer, Predicate<T> isPresent, T object,
}

@Override
public PlayerPermission readPlayerPermission(ByteBuf buffer) {
final int ordinal = VarInts.readInt(buffer);
public PlayerPermission readPlayerPermission(final int ordinal) {
if (ordinal < 0 || ordinal >= PLAYER_PERMISSIONS.length) {
return null;
} else {
Expand All @@ -398,7 +397,7 @@ public PlayerPermission readPlayerPermission(ByteBuf buffer) {
}

@Override
public void writePlayerPermission(ByteBuf buffer, PlayerPermission permission) {
VarInts.writeInt(buffer, permission == null ? -1 : permission.ordinal());
public int writePlayerPermission(PlayerPermission permission) {
return permission == null ? -1 : permission.ordinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
buffer.writeBoolean(packet.isTrustingPlayers());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal());
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.getPlatformBroadcastMode() != GamePublishSetting.NO_MULTI_PLAY);
Expand Down Expand Up @@ -136,7 +136,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setTrustingPlayers(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
buffer.readBoolean(); // Broadcasting to Platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
helper.writeArray(buffer, packet.getGamerules(), helper::writeGameRule);
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -72,7 +72,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
helper.readArray(buffer, packet.getGamerules(), helper::readGameRule);
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
helper.writeArray(buffer, packet.getGamerules(), helper::writeGameRule);
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
helper.readArray(buffer, packet.getGamerules(), helper::readGameRule);
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -161,7 +161,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -94,7 +94,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.NoArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.cloudburstmc.protocol.bedrock.codec.EntityDataTypeMap;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.AvailableCommandsSerializer_v291;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.EntityEventSerializer_v291;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelEventSerializer_v291;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelSoundEvent1Serializer_v291;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.cloudburstmc.protocol.bedrock.data.Ability;
import org.cloudburstmc.protocol.bedrock.data.AbilityLayer;
import org.cloudburstmc.protocol.bedrock.data.PlayerAbilityHolder;
import org.cloudburstmc.protocol.bedrock.data.PlayerPermission;
import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestActionType;
Expand All @@ -35,7 +34,7 @@ public BedrockCodecHelper_v534(EntityDataTypeMap entityData, TypeMap<Class<?>> g
@Override
public void readPlayerAbilities(ByteBuf buffer, PlayerAbilityHolder abilityHolder) {
abilityHolder.setUniqueEntityId(buffer.readLongLE());
abilityHolder.setPlayerPermission(PLAYER_PERMISSIONS[buffer.readUnsignedByte()]);
abilityHolder.setPlayerPermission(readPlayerPermission(buffer.readUnsignedByte()));
abilityHolder.setCommandPermission(CommandPermission.values()[buffer.readUnsignedByte()]);
this.readArray(buffer, abilityHolder.getAbilityLayers(), this::readAbilityLayer);
}
Expand All @@ -53,7 +52,7 @@ protected AbilityLayer readAbilityLayer(ByteBuf buffer) {
@Override
public void writePlayerAbilities(ByteBuf buffer, PlayerAbilityHolder abilityHolder) {
buffer.writeLongLE(abilityHolder.getUniqueEntityId());
buffer.writeByte(abilityHolder.getPlayerPermission().ordinal());
buffer.writeByte(writePlayerPermission(abilityHolder.getPlayerPermission()));
buffer.writeByte(abilityHolder.getCommandPermission().ordinal());
this.writeArray(buffer, abilityHolder.getAbilityLayers(), this::writeAbilityLayer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelSoundEvent1Serializer_v291;
import org.cloudburstmc.protocol.bedrock.codec.v313.serializer.LevelSoundEvent2Serializer_v313;
import org.cloudburstmc.protocol.bedrock.codec.v332.serializer.LevelSoundEventSerializer_v332;
import org.cloudburstmc.protocol.bedrock.codec.v503.BedrockCodecHelper_v503;
import org.cloudburstmc.protocol.bedrock.codec.v527.Bedrock_v527;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.*;
import org.cloudburstmc.protocol.bedrock.data.Ability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -96,7 +96,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.AddPlayerSerializer_v534;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.UpdateAbilitiesSerializer_v534;
import org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer;
import org.cloudburstmc.protocol.bedrock.codec.v534.serializer.UpdateAbilitiesSerializer_v534;
import org.cloudburstmc.protocol.bedrock.packet.ClientCheatAbilityPacket;

public class ClientCheatAbilitySerializer_v567 implements BedrockPacketSerializer<ClientCheatAbilityPacket> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -94,7 +94,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import lombok.NoArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer;
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
import org.cloudburstmc.protocol.bedrock.data.TrimPattern;
import org.cloudburstmc.protocol.bedrock.packet.OpenSignPacket;
import org.cloudburstmc.protocol.bedrock.packet.TrimDataPacket;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OpenSignSerializer_v582 implements BedrockPacketSerializer<OpenSignPacket> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void writeLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Sta
buffer.writeBoolean(packet.isExperimentsPreviouslyToggled());
buffer.writeBoolean(packet.isBonusChestEnabled());
buffer.writeBoolean(packet.isStartingWithMap());
helper.writePlayerPermission(buffer, packet.getDefaultPlayerPermission());
VarInts.writeInt(buffer, helper.writePlayerPermission(packet.getDefaultPlayerPermission()));
buffer.writeIntLE(packet.getServerChunkTickRange());
buffer.writeBoolean(packet.isBehaviorPackLocked());
buffer.writeBoolean(packet.isResourcePackLocked());
Expand Down Expand Up @@ -110,7 +110,7 @@ protected void readLevelSettings(ByteBuf buffer, BedrockCodecHelper helper, Star
packet.setExperimentsPreviouslyToggled(buffer.readBoolean());
packet.setBonusChestEnabled(buffer.readBoolean());
packet.setStartingWithMap(buffer.readBoolean());
packet.setDefaultPlayerPermission(helper.readPlayerPermission(buffer));
packet.setDefaultPlayerPermission(helper.readPlayerPermission(VarInts.readInt(buffer)));
packet.setServerChunkTickRange(buffer.readIntLE());
packet.setBehaviorPackLocked(buffer.readBoolean());
packet.setResourcePackLocked(buffer.readBoolean());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer;
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe;

import lombok.*;
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.CraftingDataType;
import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemDescriptorWithCount;

Expand Down

0 comments on commit b366437

Please sign in to comment.