mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Even more inline packets
This commit is contained in:
parent
081266775c
commit
9db4ac06cc
@ -1367,12 +1367,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
|||||||
*
|
*
|
||||||
* @return The {@link EntityMetaDataPacket} related to this entity
|
* @return The {@link EntityMetaDataPacket} related to this entity
|
||||||
*/
|
*/
|
||||||
@NotNull
|
public @NotNull EntityMetaDataPacket getMetadataPacket() {
|
||||||
public EntityMetaDataPacket getMetadataPacket() {
|
return new EntityMetaDataPacket(getEntityId(), metadata.getEntries());
|
||||||
EntityMetaDataPacket metaDataPacket = new EntityMetaDataPacket();
|
|
||||||
metaDataPacket.entityId = getEntityId();
|
|
||||||
metaDataPacket.entries = metadata.getEntries();
|
|
||||||
return metaDataPacket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package net.minestom.server.entity;
|
|||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.chat.ColoredText;
|
|
||||||
import net.minestom.server.chat.JsonMessage;
|
import net.minestom.server.chat.JsonMessage;
|
||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
import net.minestom.server.coordinate.Vec;
|
import net.minestom.server.coordinate.Vec;
|
||||||
@ -254,11 +253,7 @@ public class Metadata {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EntityMetaDataPacket metaDataPacket = new EntityMetaDataPacket();
|
this.entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), Collections.singleton(entry)));
|
||||||
metaDataPacket.entityId = this.entity.getEntityId();
|
|
||||||
metaDataPacket.entries = Collections.singleton(entry);
|
|
||||||
|
|
||||||
this.entity.sendPacketToViewersAndSelf(metaDataPacket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +261,6 @@ public class Metadata {
|
|||||||
if (this.notifyAboutChanges == notifyAboutChanges) {
|
if (this.notifyAboutChanges == notifyAboutChanges) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<Entry<?>> entries = null;
|
Collection<Entry<?>> entries = null;
|
||||||
synchronized (this.notNotifiedChanges) {
|
synchronized (this.notNotifiedChanges) {
|
||||||
this.notifyAboutChanges = notifyAboutChanges;
|
this.notifyAboutChanges = notifyAboutChanges;
|
||||||
@ -278,16 +272,10 @@ public class Metadata {
|
|||||||
this.notNotifiedChanges.clear();
|
this.notNotifiedChanges.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries == null || this.entity == null || !this.entity.isActive()) {
|
if (entries == null || this.entity == null || !this.entity.isActive()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.entity.sendPacketToViewersAndSelf(new EntityMetaDataPacket(entity.getEntityId(), entries));
|
||||||
EntityMetaDataPacket metaDataPacket = new EntityMetaDataPacket();
|
|
||||||
metaDataPacket.entityId = this.entity.getEntityId();
|
|
||||||
metaDataPacket.entries = entries;
|
|
||||||
|
|
||||||
this.entity.sendPacketToViewersAndSelf(metaDataPacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -232,18 +232,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
playerConnection.sendPacket(joinGamePacket);
|
playerConnection.sendPacket(joinGamePacket);
|
||||||
|
|
||||||
// Server brand name
|
// Server brand name
|
||||||
{
|
playerConnection.sendPacket(PluginMessagePacket.getBrandPacket());
|
||||||
playerConnection.sendPacket(PluginMessagePacket.getBrandPacket());
|
// Difficulty
|
||||||
}
|
playerConnection.sendPacket(new ServerDifficultyPacket(MinecraftServer.getDifficulty(), true));
|
||||||
|
|
||||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
playerConnection.sendPacket(new SpawnPositionPacket(respawnPoint, 0));
|
||||||
serverDifficultyPacket.difficulty = MinecraftServer.getDifficulty();
|
|
||||||
serverDifficultyPacket.locked = true;
|
|
||||||
playerConnection.sendPacket(serverDifficultyPacket);
|
|
||||||
|
|
||||||
SpawnPositionPacket spawnPositionPacket = new SpawnPositionPacket();
|
|
||||||
spawnPositionPacket.position = respawnPoint;
|
|
||||||
playerConnection.sendPacket(spawnPositionPacket);
|
|
||||||
|
|
||||||
// Add player to list with spawning skin
|
// Add player to list with spawning skin
|
||||||
PlayerSkinInitEvent skinInitEvent = new PlayerSkinInitEvent(this, skin);
|
PlayerSkinInitEvent skinInitEvent = new PlayerSkinInitEvent(this, skin);
|
||||||
@ -291,7 +284,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
// Tags
|
// Tags
|
||||||
this.playerConnection.sendPacket(TagsPacket.getRequiredTagsPacket());
|
this.playerConnection.sendPacket(TagsPacket.getRequiredTagsPacket());
|
||||||
|
|
||||||
// Some client update
|
// Some client updates
|
||||||
this.playerConnection.sendPacket(getPropertiesPacket()); // Send default properties
|
this.playerConnection.sendPacket(getPropertiesPacket()); // Send default properties
|
||||||
refreshHealth(); // Heal and send health packet
|
refreshHealth(); // Heal and send health packet
|
||||||
refreshAbilities(); // Send abilities packet
|
refreshAbilities(); // Send abilities packet
|
||||||
@ -606,11 +599,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
* @param channel the message channel
|
* @param channel the message channel
|
||||||
* @param data the message data
|
* @param data the message data
|
||||||
*/
|
*/
|
||||||
public void sendPluginMessage(@NotNull String channel, @NotNull byte[] data) {
|
public void sendPluginMessage(@NotNull String channel, byte @NotNull [] data) {
|
||||||
PluginMessagePacket pluginMessagePacket = new PluginMessagePacket();
|
playerConnection.sendPacket(new PluginMessagePacket(channel, data));
|
||||||
pluginMessagePacket.channel = channel;
|
|
||||||
pluginMessagePacket.data = data;
|
|
||||||
playerConnection.sendPacket(pluginMessagePacket);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -622,8 +612,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
* @param message the message
|
* @param message the message
|
||||||
*/
|
*/
|
||||||
public void sendPluginMessage(@NotNull String channel, @NotNull String message) {
|
public void sendPluginMessage(@NotNull String channel, @NotNull String message) {
|
||||||
final byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
|
sendPluginMessage(channel, message.getBytes(StandardCharsets.UTF_8));
|
||||||
sendPluginMessage(channel, bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +8,7 @@ import net.minestom.server.utils.binary.BinaryWriter;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class EntityMetaDataPacket implements ServerPacket {
|
public class EntityMetaDataPacket implements ServerPacket {
|
||||||
@ -15,13 +16,20 @@ public class EntityMetaDataPacket implements ServerPacket {
|
|||||||
public int entityId;
|
public int entityId;
|
||||||
public Collection<Metadata.Entry<?>> entries;
|
public Collection<Metadata.Entry<?>> entries;
|
||||||
|
|
||||||
public EntityMetaDataPacket() {}
|
public EntityMetaDataPacket(int entityId, Collection<Metadata.Entry<?>> entries) {
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.entries = entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMetaDataPacket() {
|
||||||
|
this(0, Collections.emptyList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
writer.writeVarInt(entityId);
|
writer.writeVarInt(entityId);
|
||||||
|
|
||||||
if(entries != null) {
|
if (entries != null) {
|
||||||
// Write all the fields
|
// Write all the fields
|
||||||
for (Metadata.Entry<?> entry : entries) {
|
for (Metadata.Entry<?> entry : entries) {
|
||||||
entry.write(writer);
|
entry.write(writer);
|
||||||
@ -36,10 +44,10 @@ public class EntityMetaDataPacket implements ServerPacket {
|
|||||||
entityId = reader.readVarInt();
|
entityId = reader.readVarInt();
|
||||||
|
|
||||||
entries = new LinkedList<>();
|
entries = new LinkedList<>();
|
||||||
while(true) {
|
while (true) {
|
||||||
byte index = reader.readByte();
|
byte index = reader.readByte();
|
||||||
|
|
||||||
if(index == (byte) 0xFF) { // reached the end
|
if (index == (byte) 0xFF) { // reached the end
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,8 +9,17 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class PluginMessagePacket implements ServerPacket {
|
public class PluginMessagePacket implements ServerPacket {
|
||||||
|
|
||||||
public String channel = "none";
|
public String channel;
|
||||||
public byte[] data = new byte[0];
|
public byte[] data;
|
||||||
|
|
||||||
|
public PluginMessagePacket(String channel, byte[] data) {
|
||||||
|
this.channel = channel;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PluginMessagePacket() {
|
||||||
|
this("none", new byte[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(@NotNull BinaryWriter writer) {
|
public void write(@NotNull BinaryWriter writer) {
|
||||||
|
@ -12,8 +12,13 @@ public class ServerDifficultyPacket implements ServerPacket {
|
|||||||
public Difficulty difficulty;
|
public Difficulty difficulty;
|
||||||
public boolean locked;
|
public boolean locked;
|
||||||
|
|
||||||
|
public ServerDifficultyPacket(Difficulty difficulty, boolean locked) {
|
||||||
|
this.difficulty = difficulty;
|
||||||
|
this.locked = locked;
|
||||||
|
}
|
||||||
|
|
||||||
public ServerDifficultyPacket() {
|
public ServerDifficultyPacket() {
|
||||||
difficulty = Difficulty.NORMAL;
|
this(Difficulty.NORMAL, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
|
import net.minestom.server.coordinate.Point;
|
||||||
|
import net.minestom.server.coordinate.Vec;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
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 net.minestom.server.coordinate.Point;
|
|
||||||
import net.minestom.server.coordinate.Vec;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class SpawnPositionPacket implements ServerPacket {
|
public class SpawnPositionPacket implements ServerPacket {
|
||||||
|
|
||||||
public Point position = Vec.ZERO;
|
public Point position;
|
||||||
public float angle;
|
public float angle;
|
||||||
|
|
||||||
|
public SpawnPositionPacket(Point position, float angle) {
|
||||||
|
this.position = position;
|
||||||
|
this.angle = angle;
|
||||||
|
}
|
||||||
|
|
||||||
public SpawnPositionPacket() {
|
public SpawnPositionPacket() {
|
||||||
|
this(Vec.ZERO, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user