/* * Decompiled with CFR 0.152. * * Could not load the following classes: * javax.annotation.Nullable */ package de.maxhenkel.voicechat.plugins.impl.packets; import de.maxhenkel.voicechat.api.Position; import de.maxhenkel.voicechat.api.packets.ConvertablePacket; import de.maxhenkel.voicechat.api.packets.EntitySoundPacket; import de.maxhenkel.voicechat.api.packets.LocationalSoundPacket; import de.maxhenkel.voicechat.api.packets.SoundPacket; import de.maxhenkel.voicechat.api.packets.StaticSoundPacket; import de.maxhenkel.voicechat.plugins.impl.PositionImpl; import de.maxhenkel.voicechat.plugins.impl.packets.EntitySoundPacketImpl; import de.maxhenkel.voicechat.plugins.impl.packets.LocationalSoundPacketImpl; import de.maxhenkel.voicechat.plugins.impl.packets.StaticSoundPacketImpl; import de.maxhenkel.voicechat.voice.common.GroupSoundPacket; import de.maxhenkel.voicechat.voice.common.LocationSoundPacket; import de.maxhenkel.voicechat.voice.common.PlayerSoundPacket; import de.maxhenkel.voicechat.voice.common.Utils; import java.util.UUID; import javax.annotation.Nullable; public class ConvertablePacketImpl implements ConvertablePacket { @Override public EntitySoundPacket.Builder entitySoundPacketBuilder() { return new GenericEntitySoundPacketBuilder(); } @Override public LocationalSoundPacket.Builder locationalSoundPacketBuilder() { return new GenericLocationalSoundPacketBuilder(); } @Override public StaticSoundPacket.Builder staticSoundPacketBuilder() { return new GenericStaticSoundPacketBuilder(); } @Override public EntitySoundPacket toEntitySoundPacket(UUID entityUuid, boolean whispering) { throw new UnsupportedOperationException(); } @Override public LocationalSoundPacket toLocationalSoundPacket(Position position) { throw new UnsupportedOperationException(); } @Override public StaticSoundPacket toStaticSoundPacket() { throw new UnsupportedOperationException(); } public static class GenericEntitySoundPacketBuilder extends GenericSoundPacketBuilder implements EntitySoundPacket.Builder { protected UUID entityUuid; protected boolean whispering; protected Float distance; @Override public GenericEntitySoundPacketBuilder entityUuid(UUID entityUuid) { this.entityUuid = entityUuid; return this; } @Override public GenericEntitySoundPacketBuilder whispering(boolean whispering) { this.whispering = whispering; return this; } @Override public GenericEntitySoundPacketBuilder distance(float distance) { this.distance = Float.valueOf(distance); return this; } @Override public EntitySoundPacket build() { this.checkRequiredFields(); if (this.entityUuid == null) { throw new IllegalStateException("Entity UUID must be set"); } if (this.distance == null) { this.distance = Float.valueOf(Utils.getDefaultDistance()); } return new EntitySoundPacketImpl(new PlayerSoundPacket(this.channelId, this.entityUuid, this.opusEncodedData, this.sequenceNumber, this.whispering, this.distance.floatValue(), this.category)); } } public static class GenericLocationalSoundPacketBuilder extends GenericSoundPacketBuilder implements LocationalSoundPacket.Builder { protected PositionImpl position; protected Float distance; @Override public GenericLocationalSoundPacketBuilder position(Position position) { this.position = (PositionImpl)position; return this; } @Override public GenericLocationalSoundPacketBuilder distance(float distance) { this.distance = Float.valueOf(distance); return this; } @Override public LocationalSoundPacket build() { this.checkRequiredFields(); if (this.position == null) { throw new IllegalStateException("Position must be set"); } if (this.distance == null) { this.distance = Float.valueOf(Utils.getDefaultDistance()); } return new LocationalSoundPacketImpl(new LocationSoundPacket(this.channelId, this.sender, this.position.getPosition(), this.opusEncodedData, this.sequenceNumber, this.distance.floatValue(), this.category)); } } public static class GenericStaticSoundPacketBuilder extends GenericSoundPacketBuilder implements StaticSoundPacket.Builder { @Override public StaticSoundPacket build() { return new StaticSoundPacketImpl(new GroupSoundPacket(this.channelId, this.sender, this.opusEncodedData, this.sequenceNumber, this.category)); } } public static abstract class GenericSoundPacketBuilder, P extends SoundPacket> implements SoundPacket.Builder { @Nullable protected UUID channelId; @Nullable protected UUID sender; @Nullable protected byte[] opusEncodedData; @Nullable protected Long sequenceNumber; @Nullable protected String category; @Override public T channelId(UUID channelId) { this.channelId = channelId; return (T)this; } @Override public T sender(UUID sender) { this.sender = sender; return (T)this; } @Override public T opusEncodedData(byte[] data) { this.opusEncodedData = data; return (T)this; } @Override public T sequenceNumber(long sequenceNumber) { this.sequenceNumber = sequenceNumber; return (T)this; } @Override public T category(@Nullable String category) { this.category = category; return (T)this; } public void checkRequiredFields() { if (this.channelId == null) { throw new IllegalStateException("Channel id must be set"); } if (this.sequenceNumber == null) { throw new IllegalStateException("Sequence number must be set"); } if (this.opusEncodedData == null) { throw new IllegalStateException("Opus encoded data must be set"); } } } }