fix metadata not being sent
This commit is contained in:
parent
ec1b5666c6
commit
08af20f5ad
4 changed files with 41 additions and 17 deletions
|
@ -31,6 +31,11 @@ public class WrapperEntity {
|
||||||
this.meta = meta;
|
this.meta = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
if (!spawned) return;
|
||||||
|
sendPacketToViewers(meta.createPacket());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean spawn(Location location) {
|
public boolean spawn(Location location) {
|
||||||
if (spawned) return false;
|
if (spawned) return false;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
@ -48,6 +53,7 @@ public class WrapperEntity {
|
||||||
Optional.empty()
|
Optional.empty()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
sendPacketToViewers(meta.createPacket());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +110,7 @@ public class WrapperEntity {
|
||||||
Optional.empty()
|
Optional.empty()
|
||||||
);
|
);
|
||||||
EntityLib.sendPacket(uuid, packet);
|
EntityLib.sendPacket(uuid, packet);
|
||||||
|
EntityLib.sendPacket(uuid, meta.createPacket());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,12 +77,25 @@ public class EntityMeta implements EntityMetadataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getCustomName() {
|
public Component getCustomName() {
|
||||||
return this.metadata.getIndex((byte) 2, null);
|
return this.metadata.getIndex(offset(OFFSET, 2), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomName(Component value) {
|
||||||
|
this.metadata.setIndex(offset(OFFSET, 2), EntityDataTypes.COMPONENT, GsonComponentSerializer.gson().serialize(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCustomNameVisible() {
|
||||||
|
return this.metadata.getIndex(offset(OFFSET, 3), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomNameVisible(boolean value) {
|
||||||
|
this.metadata.setIndex(offset(OFFSET, 3), EntityDataTypes.BOOLEAN, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasGlowingEffect() {
|
public boolean hasGlowingEffect() {
|
||||||
return getMaskBit(OFFSET, HAS_GLOWING_EFFECT_BIT);
|
return getMaskBit(OFFSET, HAS_GLOWING_EFFECT_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSwimming() {
|
public boolean isSwimming() {
|
||||||
return getMaskBit(OFFSET, SWIMMING_BIT);
|
return getMaskBit(OFFSET, SWIMMING_BIT);
|
||||||
}
|
}
|
||||||
|
@ -103,18 +116,6 @@ public class EntityMeta implements EntityMetadataProvider {
|
||||||
setMaskBit(OFFSET, FLYING_WITH_ELYTRA_BIT, value);
|
setMaskBit(OFFSET, FLYING_WITH_ELYTRA_BIT, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCustomName(Component value) {
|
|
||||||
this.metadata.setIndex((byte) 2, EntityDataTypes.COMPONENT, GsonComponentSerializer.gson().serialize(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCustomNameVisible() {
|
|
||||||
return this.metadata.getIndex((byte) 3, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCustomNameVisible(boolean value) {
|
|
||||||
this.metadata.setIndex((byte) 3, EntityDataTypes.BOOLEAN, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSilent() {
|
public boolean isSilent() {
|
||||||
return this.metadata.getIndex((byte) 4, false);
|
return this.metadata.getIndex((byte) 4, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
||||||
|
id("io.papermc.paperweight.userdev") version "1.5.11"
|
||||||
|
id 'xyz.jpenilla.run-paper' version '2.2.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'me.tofaa.peentitymeta'
|
group = 'me.tofaa.peentitymeta'
|
||||||
|
@ -24,7 +25,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly('org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT')
|
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
|
||||||
compileOnly('com.github.retrooper.packetevents:spigot:2.0.2')
|
compileOnly('com.github.retrooper.packetevents:spigot:2.0.2')
|
||||||
implementation project(':')
|
implementation project(':')
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import io.github.retrooper.packetevents.util.SpigotConversionUtil;
|
||||||
import me.tofaa.entitylib.entity.WrapperEntity;
|
import me.tofaa.entitylib.entity.WrapperEntity;
|
||||||
import me.tofaa.entitylib.entity.WrapperLivingEntity;
|
import me.tofaa.entitylib.entity.WrapperLivingEntity;
|
||||||
import me.tofaa.entitylib.meta.EntityMeta;
|
import me.tofaa.entitylib.meta.EntityMeta;
|
||||||
|
import me.tofaa.entitylib.meta.other.ArmorStandMeta;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
@ -25,7 +27,6 @@ public class TestEntityCommand implements CommandExecutor {
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
if (!(sender instanceof Player)) return false;
|
if (!(sender instanceof Player)) return false;
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
entity = (WrapperLivingEntity) EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ZOMBIE);
|
entity = (WrapperLivingEntity) EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ZOMBIE);
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
|
@ -42,9 +43,23 @@ public class TestEntityCommand implements CommandExecutor {
|
||||||
EntityMeta meta = entity.getMeta();
|
EntityMeta meta = entity.getMeta();
|
||||||
meta.setOnFire(!meta.isOnFire());
|
meta.setOnFire(!meta.isOnFire());
|
||||||
meta.setHasGlowingEffect(!meta.hasGlowingEffect());
|
meta.setHasGlowingEffect(!meta.hasGlowingEffect());
|
||||||
|
|
||||||
|
meta.setCustomNameVisible(!meta.isCustomNameVisible());
|
||||||
|
meta.setCustomName(Component.text("test"));
|
||||||
|
|
||||||
player.sendMessage("on fire: " + meta.isOnFire());
|
player.sendMessage("on fire: " + meta.isOnFire());
|
||||||
player.sendMessage("glowing: " + meta.hasGlowingEffect());
|
player.sendMessage("glowing: " + meta.hasGlowingEffect());
|
||||||
player.sendMessage("viewers: " + entity.getViewers());
|
|
||||||
|
|
||||||
|
WrapperEntity e = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ARMOR_STAND);
|
||||||
|
int entityId = e.getEntityId(); // You can set the entityId provider to change this, WrapperEntity#ID_PROVIDER
|
||||||
|
if (e == null) {
|
||||||
|
throw new RuntimeException("Error creating entity meta"); // Only happens if the entity meta is null/invalid.
|
||||||
|
}
|
||||||
|
ArmorStandMeta m = (ArmorStandMeta) e.getMeta();
|
||||||
|
m.setInvisible(true);
|
||||||
|
e.spawn(new Location(1, 2, 3, 4, 5));
|
||||||
|
e.addViewer(player.getUniqueId());
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue