mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-29 15:07:36 +02:00
Cleanup
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
2d7e11adaf
commit
8c72bee1dd
@ -7,7 +7,8 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record DeathCombatEventPacket(int playerId, int entityId, Component message) implements ServerPacket {
|
public record DeathCombatEventPacket(int playerId, int entityId,
|
||||||
|
@NotNull Component message) implements ServerPacket {
|
||||||
public DeathCombatEventPacket(BinaryReader reader) {
|
public DeathCombatEventPacket(BinaryReader reader) {
|
||||||
this(reader.readVarInt(), reader.readInt(), reader.readComponent());
|
this(reader.readVarInt(), reader.readInt(), reader.readComponent());
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
public record DisconnectPacket(Component message) implements ComponentHoldingServerPacket {
|
public record DisconnectPacket(@NotNull Component message) implements ComponentHoldingServerPacket {
|
||||||
public DisconnectPacket(BinaryReader reader) {
|
public DisconnectPacket(BinaryReader reader) {
|
||||||
this(reader.readComponent());
|
this(reader.readComponent());
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record EntityEffectPacket(int entityId, Potion potion) implements ServerPacket {
|
public record EntityEffectPacket(int entityId, @NotNull Potion potion) implements ServerPacket {
|
||||||
public EntityEffectPacket(BinaryReader reader) {
|
public EntityEffectPacket(BinaryReader reader) {
|
||||||
this(reader.readVarInt(), new Potion(reader));
|
this(reader.readVarInt(), new Potion(reader));
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record EntityEquipmentPacket(int entityId, Map<EquipmentSlot, ItemStack> equipments) implements ServerPacket {
|
public record EntityEquipmentPacket(int entityId,
|
||||||
|
@NotNull Map<EquipmentSlot, ItemStack> equipments) implements ServerPacket {
|
||||||
public EntityEquipmentPacket {
|
public EntityEquipmentPacket {
|
||||||
equipments = Map.copyOf(equipments);
|
equipments = Map.copyOf(equipments);
|
||||||
}
|
}
|
||||||
@ -39,11 +40,10 @@ public record EntityEquipmentPacket(int entityId, Map<EquipmentSlot, ItemStack>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static Map<EquipmentSlot, ItemStack> readEquipments(BinaryReader reader) {
|
private static Map<EquipmentSlot, ItemStack> readEquipments(BinaryReader reader) {
|
||||||
EnumMap<EquipmentSlot, ItemStack> equipments = new EnumMap<>(EquipmentSlot.class);
|
Map<EquipmentSlot, ItemStack> equipments = new EnumMap<>(EquipmentSlot.class);
|
||||||
boolean hasRemaining = true;
|
while (true) {
|
||||||
while (hasRemaining) {
|
final byte slotEnum = reader.readByte();
|
||||||
byte slotEnum = reader.readByte();
|
if ((slotEnum & 0x80) != 0x80) break;
|
||||||
hasRemaining = (slotEnum & 0x80) == 0x80;
|
|
||||||
equipments.put(EquipmentSlot.values()[slotEnum & 0x7F], reader.readItemStack());
|
equipments.put(EquipmentSlot.values()[slotEnum & 0x7F], reader.readItemStack());
|
||||||
}
|
}
|
||||||
return equipments;
|
return equipments;
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record OpenBookPacket(Player.Hand hand) implements ServerPacket {
|
public record OpenBookPacket(@NotNull Player.Hand hand) implements ServerPacket {
|
||||||
public OpenBookPacket(BinaryReader reader) {
|
public OpenBookPacket(BinaryReader reader) {
|
||||||
this(Player.Hand.values()[reader.readVarInt()]);
|
this(Player.Hand.values()[reader.readVarInt()]);
|
||||||
}
|
}
|
||||||
|
@ -8,39 +8,30 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
public record PlayerListHeaderAndFooterPacket(Component header,
|
public record PlayerListHeaderAndFooterPacket(@NotNull Component header,
|
||||||
Component footer) implements ComponentHoldingServerPacket {
|
@NotNull Component footer) implements ComponentHoldingServerPacket {
|
||||||
public PlayerListHeaderAndFooterPacket(BinaryReader reader) {
|
public PlayerListHeaderAndFooterPacket(BinaryReader reader) {
|
||||||
this(reader.readComponent(), reader.readComponent());
|
this(reader.readComponent(), reader.readComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
writer.writeComponent(Objects.requireNonNullElseGet(header, Component::empty));
|
writer.writeComponent(header);
|
||||||
writer.writeComponent(Objects.requireNonNullElseGet(footer, Component::empty));
|
writer.writeComponent(footer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Collection<Component> components() {
|
public @NotNull Collection<Component> components() {
|
||||||
List<Component> components = new ArrayList<>();
|
return List.of(header, footer);
|
||||||
if (header != null) {
|
|
||||||
components.add(header);
|
|
||||||
}
|
|
||||||
if (footer != null) {
|
|
||||||
components.add(footer);
|
|
||||||
}
|
|
||||||
return components;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull ServerPacket copyWithOperator(@NotNull UnaryOperator<Component> operator) {
|
public @NotNull ServerPacket copyWithOperator(@NotNull UnaryOperator<Component> operator) {
|
||||||
return new PlayerListHeaderAndFooterPacket(header == null ? null : operator.apply(header), footer == null ? null : operator.apply(footer));
|
return new PlayerListHeaderAndFooterPacket(operator.apply(header), operator.apply(footer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,9 +7,11 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record RemoveEntityEffectPacket(int entityId, PotionEffect potionEffect) implements ServerPacket {
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public record RemoveEntityEffectPacket(int entityId, @NotNull PotionEffect potionEffect) implements ServerPacket {
|
||||||
public RemoveEntityEffectPacket(BinaryReader reader) {
|
public RemoveEntityEffectPacket(BinaryReader reader) {
|
||||||
this(reader.readVarInt(), PotionEffect.fromId(reader.readByte()));
|
this(reader.readVarInt(), Objects.requireNonNull(PotionEffect.fromId(reader.readByte())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
|||||||
import net.minestom.server.world.Difficulty;
|
import net.minestom.server.world.Difficulty;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record ServerDifficultyPacket(Difficulty difficulty, boolean locked) implements ServerPacket {
|
public record ServerDifficultyPacket(@NotNull Difficulty difficulty, boolean locked) implements ServerPacket {
|
||||||
public ServerDifficultyPacket(BinaryReader reader) {
|
public ServerDifficultyPacket(BinaryReader reader) {
|
||||||
this(Difficulty.values()[reader.readByte()], reader.readBoolean());
|
this(Difficulty.values()[reader.readByte()], reader.readBoolean());
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,11 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record SetSlotPacket(byte windowId, int stateId, short slot, ItemStack itemStack) implements ServerPacket {
|
public record SetSlotPacket(byte windowId, int stateId, short slot,
|
||||||
|
@NotNull ItemStack itemStack) implements ServerPacket {
|
||||||
public SetSlotPacket(BinaryReader reader) {
|
public SetSlotPacket(BinaryReader reader) {
|
||||||
this(reader.readByte(), reader.readVarInt(), reader.readShort(), reader.readItemStack());
|
this(reader.readByte(), reader.readVarInt(), reader.readShort(),
|
||||||
|
reader.readItemStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record SetTitleSubTitlePacket(Component subtitle) implements ServerPacket {
|
public record SetTitleSubTitlePacket(@NotNull Component subtitle) implements ServerPacket {
|
||||||
public SetTitleSubTitlePacket(BinaryReader reader) {
|
public SetTitleSubTitlePacket(BinaryReader reader) {
|
||||||
this(reader.readComponent());
|
this(reader.readComponent());
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record SetTitleTextPacket(Component title) implements ServerPacket {
|
public record SetTitleTextPacket(@NotNull Component title) implements ServerPacket {
|
||||||
public SetTitleTextPacket(BinaryReader reader) {
|
public SetTitleTextPacket(BinaryReader reader) {
|
||||||
this(reader.readComponent());
|
this(reader.readComponent());
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@ import net.minestom.server.utils.binary.BinaryReader;
|
|||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public record SoundEffectPacket(int soundId, Source source, int x, int y, int z,
|
public record SoundEffectPacket(int soundId, @NotNull Source source,
|
||||||
|
int x, int y, int z,
|
||||||
float volume, float pitch) implements ServerPacket {
|
float volume, float pitch) implements ServerPacket {
|
||||||
public SoundEffectPacket(BinaryReader reader) {
|
public SoundEffectPacket(BinaryReader reader) {
|
||||||
this(reader.readVarInt(), Source.values()[reader.readVarInt()],
|
this(reader.readVarInt(), Source.values()[reader.readVarInt()],
|
||||||
@ -18,8 +19,10 @@ public record SoundEffectPacket(int soundId, Source source, int x, int y, int z,
|
|||||||
reader.readFloat(), reader.readFloat());
|
reader.readFloat(), reader.readFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SoundEffectPacket(SoundEvent sound, Source source, Point position, float volume, float pitch) {
|
public SoundEffectPacket(@NotNull SoundEvent sound, @NotNull Source source,
|
||||||
this(sound.id(), source, (int) position.x(), (int) position.y(), (int) position.z(), volume, pitch);
|
@NotNull Point position, float volume, float pitch) {
|
||||||
|
this(sound.id(), source,
|
||||||
|
(int) position.x(), (int) position.y(), (int) position.z(), volume, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,66 +7,40 @@ import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
|||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Objects;
|
public record StopSoundPacket(byte flags, @Nullable Sound.Source source,
|
||||||
|
@Nullable String sound) implements ServerPacket {
|
||||||
public final class StopSoundPacket implements ServerPacket {
|
public StopSoundPacket(BinaryReader reader) {
|
||||||
private final byte flags;
|
this(read(reader));
|
||||||
private final Sound.Source source;
|
|
||||||
private final String sound;
|
|
||||||
|
|
||||||
public StopSoundPacket(byte flags, Sound.Source source, String sound) {
|
|
||||||
this.flags = flags;
|
|
||||||
this.source = source;
|
|
||||||
this.sound = sound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StopSoundPacket(BinaryReader reader) {
|
private StopSoundPacket(StopSoundPacket packet) {
|
||||||
this.flags = reader.readByte();
|
this(packet.flags, packet.source, packet.sound);
|
||||||
if (flags == 3 || flags == 1) {
|
}
|
||||||
this.source = Sound.Source.values()[reader.readVarInt()];
|
|
||||||
} else this.source = null;
|
private static StopSoundPacket read(BinaryReader reader) {
|
||||||
if (flags == 2 || flags == 3) {
|
var flags = reader.readByte();
|
||||||
this.sound = reader.readSizedString();
|
var source = flags == 3 || flags == 1 ? Sound.Source.values()[reader.readVarInt()] : null;
|
||||||
} else this.sound = null;
|
var sound = flags == 2 || flags == 3 ? reader.readSizedString() : null;
|
||||||
|
return new StopSoundPacket(flags, source, sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
writer.writeByte(flags);
|
writer.writeByte(flags);
|
||||||
if (flags == 3 || flags == 1)
|
if (flags == 3 || flags == 1) {
|
||||||
|
assert source != null;
|
||||||
writer.writeVarInt(AdventurePacketConvertor.getSoundSourceValue(source));
|
writer.writeVarInt(AdventurePacketConvertor.getSoundSourceValue(source));
|
||||||
if (flags == 2 || flags == 3)
|
}
|
||||||
|
if (flags == 2 || flags == 3) {
|
||||||
|
assert sound != null;
|
||||||
writer.writeSizedString(sound);
|
writer.writeSizedString(sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte flags() {
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sound.Source source() {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String sound() {
|
|
||||||
return sound;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return ServerPacketIdentifier.STOP_SOUND;
|
return ServerPacketIdentifier.STOP_SOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof StopSoundPacket that)) return false;
|
|
||||||
return flags == that.flags && source == that.source &&
|
|
||||||
Objects.equals(sound, that.sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(flags, source, sound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user