Skip to content

Commit

Permalink
EntityMetadataProvider has been added, to allow potential packetevent…
Browse files Browse the repository at this point in the history
…s addons to add on to our metadata abstraction.
  • Loading branch information
retrooper committed Nov 27, 2023
1 parent 4a2146d commit 4196999
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.retrooper.packetevents.protocol.entity.data;

import java.util.List;

public interface EntityMetadataProvider {
List<EntityData> entityData();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataType;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.data.EntityMetadataProvider;
import com.github.retrooper.packetevents.protocol.entity.villager.VillagerData;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
Expand Down Expand Up @@ -773,6 +774,10 @@ public void writeEntityMetadata(List<EntityData> list) {
}
}

public void writeEntityMetadata(EntityMetadataProvider metadata) {
writeEntityMetadata(metadata.entityData());
}

public Dimension readDimension() {
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_19)) {
Dimension dimension = new Dimension(new NBTCompound());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityMetadataProvider;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

Expand All @@ -40,6 +41,10 @@ public WrapperPlayServerEntityMetadata(int entityID, List<EntityData> entityMeta
this.entityMetadata = entityMetadata;
}

public WrapperPlayServerEntityMetadata(int entityID, EntityMetadataProvider metadata) {
this(entityID, metadata.entityData());
}

@Override
public void read() {
entityID = serverVersion.isNewerThanOrEquals(ServerVersion.V_1_8) ? readVarInt() : readInt();
Expand Down Expand Up @@ -77,4 +82,8 @@ public List<EntityData> getEntityMetadata() {
public void setEntityMetadata(List<EntityData> entityMetadata) {
this.entityMetadata = entityMetadata;
}

public void setEntityMetadata(EntityMetadataProvider metadata) {
this.entityMetadata = metadata.entityData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityMetadataProvider;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
Expand Down Expand Up @@ -64,6 +65,10 @@ public WrapperPlayServerSpawnLivingEntity(int entityID, UUID entityUUID, EntityT
this.entityMetadata = entityMetadata;
}

public WrapperPlayServerSpawnLivingEntity(int entityID, UUID entityUUID, EntityType entityType, Vector3d position, float yaw, float pitch, float headPitch, Vector3d velocity, EntityMetadataProvider metadata) {
this(entityID, entityUUID, entityType, position, yaw, pitch, headPitch, velocity, metadata.entityData());
}

public WrapperPlayServerSpawnLivingEntity(int entityId, UUID entityUUID,
EntityType entityType, Location location, float headPitch,
Vector3d velocity,
Expand All @@ -72,6 +77,14 @@ public WrapperPlayServerSpawnLivingEntity(int entityId, UUID entityUUID,
headPitch, velocity, entityMetadata);
}

public WrapperPlayServerSpawnLivingEntity(int entityId, UUID entityUUID,
EntityType entityType, Location location, float headPitch,
Vector3d velocity,
EntityMetadataProvider metadata) {
this(entityId, entityUUID, entityType, location.getPosition(), location.getYaw(), location.getPitch(),
headPitch, velocity, metadata.entityData());
}

@Override
public void read() {
this.entityID = readVarInt();
Expand Down Expand Up @@ -220,4 +233,8 @@ public List<EntityData> getEntityMetadata() {
public void setEntityMetadata(List<EntityData> entityMetadata) {
this.entityMetadata = entityMetadata;
}

public void setEntityMetadata(EntityMetadataProvider metadata) {
this.entityMetadata = metadata.entityData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityMetadataProvider;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
Expand Down Expand Up @@ -50,6 +51,10 @@ public WrapperPlayServerSpawnPlayer(PacketSendEvent event) {
super(event);
}

public WrapperPlayServerSpawnPlayer(int entityId, UUID uuid, Location location, EntityMetadataProvider metadata) {
this(entityId, uuid, location.getPosition(), location.getYaw(), location.getPitch(), metadata.entityData());
}

public WrapperPlayServerSpawnPlayer(int entityId, UUID uuid, Location location, List<EntityData> entityMetadata) {
this(entityId, uuid, location.getPosition(), location.getYaw(), location.getPitch(), entityMetadata);
}
Expand All @@ -69,6 +74,10 @@ public WrapperPlayServerSpawnPlayer(int entityID, UUID uuid, Vector3d position,
this.item = ItemTypes.AIR;
}

public WrapperPlayServerSpawnPlayer(int entityID, UUID uuid, Vector3d position, float yaw, float pitch, EntityMetadataProvider metadata) {
this(entityID, uuid, position, yaw, pitch, metadata.entityData());
}

@Override
public void read() {
entityID = readVarInt();
Expand Down Expand Up @@ -176,6 +185,11 @@ public void setEntityMetadata(List<EntityData> entityMetadata) {
this.entityMetadata = entityMetadata;
}

@Deprecated
public void setEntityMetadata(EntityMetadataProvider metadata) {
this.entityMetadata = metadata.entityData();
}

@Deprecated
public ItemType getItem() {
return item;
Expand Down

0 comments on commit 4196999

Please sign in to comment.