add invisible property

This commit is contained in:
Pyrbu 2023-04-25 17:05:28 +01:00
parent d71ba9b664
commit 24c6e9695e
8 changed files with 14 additions and 8 deletions

@ -147,6 +147,7 @@ public class ZNPCsPlus extends JavaPlugin {
NPC npc = new NPC(world, type, new PacketLocation(x * 3, 200, z * 3, 0, 0));
if (type.getType() == EntityTypes.PLAYER) {
SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(NPCProperty.SKIN, new PrefetchedDescriptor(skin)));
npc.setProperty(NPCProperty.INVISIBLE, true);
}
npc.setProperty(NPCProperty.GLOW, NamedTextColor.RED);
npc.setProperty(NPCProperty.FIRE, true);

@ -24,7 +24,7 @@ import java.util.Map;
*/
public interface MetadataFactory {
EntityData skinLayers();
EntityData effects(boolean onFire, boolean glowing);
EntityData effects(boolean onFire, boolean glowing, boolean invisible);
MetadataFactory factory = get();

@ -10,8 +10,8 @@ public class V1_8Factory implements MetadataFactory {
}
@Override
public EntityData effects(boolean onFire, boolean glowing) {
return new EntityData(0, EntityDataTypes.BYTE, onFire ? 0x01 : 0);
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
return new EntityData(0, EntityDataTypes.BYTE, (onFire ? 0x01 : 0) | (invisible ? 0x20 : 0));
}
protected EntityData createSkinLayers(int index) {

@ -10,7 +10,7 @@ public class V1_9Factory extends V1_8Factory {
}
@Override
public EntityData effects(boolean onFire, boolean glowing) {
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (glowing ? 0x40 : 0)));
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (invisible ? 0x20 : 0) | (glowing ? 0x40 : 0)));
}
}

@ -38,4 +38,5 @@ public class NPCProperty<T> {
public static NPCProperty<SkinDescriptor> SKIN = new NPCProperty<>("skin");
public static NPCProperty<NamedTextColor> GLOW = new NPCProperty<>("glow");
public static NPCProperty<Boolean> FIRE = new NPCProperty<>("fire", false);
public static NPCProperty<Boolean> INVISIBLE = new NPCProperty<>("invisible", false);
}

@ -27,6 +27,7 @@ public class NPCType {
this.type = type;
ArrayList<NPCProperty<?>> list = new ArrayList<>(List.of(allowedProperties));
list.add(NPCProperty.FIRE);
list.add(NPCProperty.INVISIBLE);
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) list.add(NPCProperty.GLOW);
this.allowedProperties = Set.copyOf(list);
}

@ -108,7 +108,9 @@ public class V1_8Factory implements PacketFactory {
public void sendAllMetadata(Player player, PacketEntity entity) {
NPC owner = entity.getOwner();
if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers());
if (owner.getProperty(NPCProperty.FIRE)) sendMetadata(player, entity, MetadataFactory.get().effects(true, false));
boolean fire = owner.getProperty(NPCProperty.FIRE);
boolean invisible = owner.getProperty(NPCProperty.INVISIBLE);
if (fire || invisible) sendMetadata(player, entity, MetadataFactory.get().effects(fire, false, invisible));
}
@Override
@ -130,7 +132,7 @@ public class V1_8Factory implements PacketFactory {
}
CompletableFuture<UserProfile> future = new CompletableFuture<>();
descriptor.fetch(player).thenAccept(skin -> {
skin.apply(profile);
if (skin != null) skin.apply(profile);
future.complete(profile);
});
return future;

@ -14,7 +14,8 @@ public class V1_9Factory extends V1_8Factory {
if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers());
boolean glow = owner.hasProperty(NPCProperty.GLOW);
boolean fire = owner.getProperty(NPCProperty.FIRE);
if (glow || fire) sendMetadata(player, entity, MetadataFactory.get().effects(fire, glow));
boolean invisible = owner.getProperty(NPCProperty.INVISIBLE);
if (glow || fire) sendMetadata(player, entity, MetadataFactory.get().effects(fire, glow, invisible));
}
@Override