Skip to content

Commit

Permalink
Merge pull request #9 from SuperMax8/master
Browse files Browse the repository at this point in the history
Fix getCustomName() in EntityMeta, update protocolVersion for 1.20.6, new method to use MetaData in packetevents listener
  • Loading branch information
Tofaa2 authored Jun 1, 2024
2 parents 5efd0da + 31d04c9 commit 0da1d44
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/me/tofaa/entitylib/meta/EntityMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void setAirTicks(short value) {
}

public Component getCustomName() {
Optional<Component> component = this.metadata.getIndex(customNameOffset(), null);
Optional<Component> component = this.metadata.getIndex(customNameOffset(), Optional.empty());
return component.orElse(null);
}

Expand Down
80 changes: 40 additions & 40 deletions api/src/main/java/me/tofaa/entitylib/meta/MetaOffsetConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,55 @@ private MetaOffsetConverter() {}
public static final class EntityMetaOffsets {
public static byte airTicksOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 1;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte customNameOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 2;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte customNameVisibleOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 3;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte silentOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 4;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte hasNoGravityOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 5;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte poseOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 6;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte ticksFrozenInPowderedSnowOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 47 && protocolVersion <= 765) {
if (protocolVersion >= 47 && protocolVersion <= 766) {
return 7;
}
throw new RuntimeException("Unknown protocol version for this method");
Expand All @@ -72,31 +72,31 @@ public static byte ticksFrozenInPowderedSnowOffset() {
public static final class AbstractDisplayMetaOffsets {
public static byte interpolationDelayOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 762 && protocolVersion <= 765) {
if (protocolVersion >= 762 && protocolVersion <= 766) {
return 8;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte transformationDurationOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 762 && protocolVersion <= 765) {
if (protocolVersion >= 762 && protocolVersion <= 766) {
return 9;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte positionRotationInterpolationDurationOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 10;
}
throw new RuntimeException("Unknown protocol version for this method");
}

public static byte translationOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 11;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -107,7 +107,7 @@ public static byte translationOffset() {

public static byte scaleOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 12;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -118,7 +118,7 @@ public static byte scaleOffset() {

public static byte leftRotationOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 13;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -129,7 +129,7 @@ public static byte leftRotationOffset() {

public static byte rightRotationOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 14;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -140,7 +140,7 @@ public static byte rightRotationOffset() {

public static byte billboardConstraintsOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 15;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -151,7 +151,7 @@ public static byte billboardConstraintsOffset() {

public static byte brightnessOverrideOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 16;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -162,7 +162,7 @@ public static byte brightnessOverrideOffset() {

public static byte viewRangeOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 17;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -173,7 +173,7 @@ public static byte viewRangeOffset() {

public static byte shadowRadiusOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 18;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -184,7 +184,7 @@ public static byte shadowRadiusOffset() {

public static byte shadowStrengthOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 19;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -195,7 +195,7 @@ public static byte shadowStrengthOffset() {

public static byte widthOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 20;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -206,7 +206,7 @@ public static byte widthOffset() {

public static byte heightOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 21;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -217,7 +217,7 @@ public static byte heightOffset() {

public static byte glowColorOverrideOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 22;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -230,7 +230,7 @@ public static byte glowColorOverrideOffset() {
public static final class BlockDisplayMetaOffsets {
public static byte blockIdOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 23;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -243,7 +243,7 @@ public static byte blockIdOffset() {
public static final class ItemDisplayMetaOffsets {
public static byte itemOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 24;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -254,7 +254,7 @@ public static byte itemOffset() {

public static byte displayTypeOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 25;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -267,7 +267,7 @@ public static byte displayTypeOffset() {
public static final class TextDisplayMetaOffsets {
public static byte textOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 26;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -278,7 +278,7 @@ public static byte textOffset() {

public static byte textColorOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 27;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -289,7 +289,7 @@ public static byte textColorOffset() {

public static byte textBackgroundColorOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 28;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -300,7 +300,7 @@ public static byte textBackgroundColorOffset() {

public static byte textBackgroundOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 29;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -311,7 +311,7 @@ public static byte textBackgroundOffset() {

public static byte textScaleOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 30;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -322,7 +322,7 @@ public static byte textScaleOffset() {

public static byte textAlignmentOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 31;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -333,7 +333,7 @@ public static byte textAlignmentOffset() {

public static byte lineWidthOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 32;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -344,7 +344,7 @@ public static byte lineWidthOffset() {

public static byte backgroundColorOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 33;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -355,7 +355,7 @@ public static byte backgroundColorOffset() {

public static byte textOpacityOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 34;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -366,7 +366,7 @@ public static byte textOpacityOffset() {

public static byte shadowOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 35;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -377,7 +377,7 @@ public static byte shadowOffset() {

public static byte seeThroughOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 36;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -388,7 +388,7 @@ public static byte seeThroughOffset() {

public static byte useDefaultBackgroundOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 37;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -399,7 +399,7 @@ public static byte useDefaultBackgroundOffset() {

public static byte allighnLeftOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 38;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -410,7 +410,7 @@ public static byte allighnLeftOffset() {

public static byte allighnRightOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 39;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand All @@ -421,7 +421,7 @@ public static byte allighnRightOffset() {

public static byte allighnCenterOffset() {
int protocolVersion = getApi().getPacketEvents().getServerManager().getVersion().getProtocolVersion();
if (protocolVersion >= 764 && protocolVersion <= 765) {
if (protocolVersion >= 764 && protocolVersion <= 766) {
return 40;
}
if (protocolVersion >= 762 && protocolVersion <= 763) {
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/java/me/tofaa/entitylib/meta/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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.wrapper.play.server.WrapperPlayServerEntityMetadata;
import me.tofaa.entitylib.EntityLib;
import me.tofaa.entitylib.EntityLibAPI;
Expand Down Expand Up @@ -74,6 +75,11 @@ public void setNotifyAboutChanges(boolean notifyAboutChanges) {
entity.sendPacketsToViewers(packet);
}

public void setMetaFromPacket(WrapperPlayServerEntityMetadata wrapper) {
for (EntityData data : wrapper.getEntityMetadata()) {
metadataMap.put((byte) data.getIndex(), data);
}
}

public boolean isNotifyingChanges() {
return notifyAboutChanges;
Expand Down

0 comments on commit 0da1d44

Please sign in to comment.