Fix ProtocolLib related errors on 1.15

This commit is contained in:
filoghost 2019-12-20 15:07:07 +01:00
parent a01db29dda
commit 473d46deac
3 changed files with 57 additions and 13 deletions

View File

@ -42,6 +42,7 @@ public class MetadataHelper {
private int customNameVisibleIndex;
private int noGravityIndex;
private int armorStandStatusIndex;
private int slimeSizeIndex;
public MetadataHelper() {
@ -55,12 +56,18 @@ public class MetadataHelper {
itemSlotIndex = 10;
}
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
armorStandStatusIndex = 14;
} else {
armorStandStatusIndex = 11;
}
entityStatusIndex = 0;
airLevelWatcherIndex = 1;
customNameIndex = 2;
customNameVisibleIndex = 3;
noGravityIndex = 5;
armorStandStatusIndex = 11;
slimeSizeIndex = 15;
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
itemSerializer = Registry.get(MinecraftReflection.getItemStackClass());
@ -129,12 +136,15 @@ public class MetadataHelper {
}
public void setEntityStatus_v1_9(WrappedDataWatcher dataWatcher, byte statusBitmask) {
public void setEntityStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) {
requireMinimumVersion(NMSVersion.v1_9_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), statusBitmask);
}
public void setCustomName_v1_9(WrappedDataWatcher dataWatcher, String customName) {
public void setCustomName(WrappedDataWatcher dataWatcher, String customName) {
requireMinimumVersion(NMSVersion.v1_9_R1);
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.of(WrappedChatComponent.fromText(customName).getHandle()));
} else {
@ -143,17 +153,20 @@ public class MetadataHelper {
}
public void setCustomNameVisible_v1_9(WrappedDataWatcher dataWatcher, boolean customNameVisible) {
public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) {
requireMinimumVersion(NMSVersion.v1_9_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible);
}
public void setNoGravity_v1_9(WrappedDataWatcher dataWatcher, boolean noGravity) {
public void setNoGravity(WrappedDataWatcher dataWatcher, boolean noGravity) {
requireMinimumVersion(NMSVersion.v1_9_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(noGravityIndex, booleanSerializer), noGravity);
}
public void setArmorStandStatus_v1_9(WrappedDataWatcher dataWatcher, byte statusBitmask) {
public void setArmorStandStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) {
requireMinimumVersion(NMSVersion.v1_9_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(armorStandStatusIndex, byteSerializer), statusBitmask);
}
@ -174,4 +187,17 @@ public class MetadataHelper {
}
}
public void setSlimeSize(WrappedDataWatcher dataWatcher, int size) {
requireMinimumVersion(NMSVersion.v1_15_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(slimeSizeIndex, intSerializer), size);
}
private static void requireMinimumVersion(NMSVersion minimumVersion) {
if (!NMSVersion.isGreaterEqualThan(minimumVersion)) {
throw new UnsupportedOperationException("Method only available from NMS version " + minimumVersion);
}
}
}

View File

@ -54,16 +54,16 @@ public class PacketHelper {
WrapperPlayServerEntityMetadata dataPacket = new WrapperPlayServerEntityMetadata();
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
metadataHelper.setEntityStatus_v1_9(dataWatcher, (byte) 0x20); // Invisible
metadataHelper.setEntityStatus(dataWatcher, (byte) 0x20); // Invisible
String customName = armorStand.getCustomNameNMS();
if (customName != null && !customName.isEmpty()) {
metadataHelper.setCustomName_v1_9(dataWatcher, customName);
metadataHelper.setCustomNameVisible_v1_9(dataWatcher, true);
metadataHelper.setCustomName(dataWatcher, customName);
metadataHelper.setCustomNameVisible(dataWatcher, true);
}
metadataHelper.setNoGravity_v1_9(dataWatcher, true);
metadataHelper.setArmorStandStatus_v1_9(dataWatcher, (byte) (0x01 | 0x08 | 0x10)); // Small, no base plate, marker
metadataHelper.setNoGravity(dataWatcher, true);
metadataHelper.setArmorStandStatus(dataWatcher, (byte) (0x01 | 0x08 | 0x10)); // Small, no base plate, marker
dataPacket.setEntityMetadata(dataWatcher.getWatchableObjects());
dataPacket.setEntityID(armorStand.getIdNMS());
@ -83,8 +83,20 @@ public class PacketHelper {
public void sendSpawnSlimePacket(Player receiver, NMSSlime slime) {
AbstractPacket packet = new WrapperPlayServerSpawnEntityLiving(slime.getBukkitEntityNMS());
packet.sendPacket(receiver);
AbstractPacket spawnPacket = new WrapperPlayServerSpawnEntityLiving(slime.getBukkitEntityNMS());
spawnPacket.sendPacket(receiver);
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
WrapperPlayServerEntityMetadata dataPacket = new WrapperPlayServerEntityMetadata();
WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
metadataHelper.setEntityStatus(dataWatcher, (byte) 0x20); // Invisible
metadataHelper.setSlimeSize(dataWatcher, 1); // Size 1 = small
dataPacket.setEntityMetadata(dataWatcher.getWatchableObjects());
dataPacket.setEntityID(slime.getIdNMS());
dataPacket.sendPacket(receiver);
}
}

View File

@ -47,6 +47,7 @@ import com.gmail.filoghost.holographicdisplays.object.line.CraftTextLine;
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchSlimeLine;
import com.gmail.filoghost.holographicdisplays.object.line.CraftTouchableLine;
import com.gmail.filoghost.holographicdisplays.placeholder.RelativePlaceholder;
import com.gmail.filoghost.holographicdisplays.util.NMSVersion;
/**
* This is for the ProtocolLib versions containing the WrappedDataWatcher.WrappedDataWatcherObject class.
@ -103,6 +104,11 @@ public class ProtocolLibHookImpl implements ProtocolLibHook {
return;
}
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
// There's no metadata field in 1.15+ on the spawn entity packet
return;
}
if (!hologramLine.getParent().isAllowPlaceholders() || !hologramLine.hasRelativePlaceholders()) {
return;
}