add invisible property
This commit is contained in:
parent
8c0d6f07fa
commit
32b96384e1
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));
|
NPC npc = new NPC(world, type, new PacketLocation(x * 3, 200, z * 3, 0, 0));
|
||||||
if (type.getType() == EntityTypes.PLAYER) {
|
if (type.getType() == EntityTypes.PLAYER) {
|
||||||
SkinCache.fetchByName("Notch").thenAccept(skin -> npc.setProperty(NPCProperty.SKIN, new PrefetchedDescriptor(skin)));
|
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.GLOW, NamedTextColor.RED);
|
||||||
npc.setProperty(NPCProperty.FIRE, true);
|
npc.setProperty(NPCProperty.FIRE, true);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public interface MetadataFactory {
|
public interface MetadataFactory {
|
||||||
EntityData skinLayers();
|
EntityData skinLayers();
|
||||||
EntityData effects(boolean onFire, boolean glowing);
|
EntityData effects(boolean onFire, boolean glowing, boolean invisible);
|
||||||
|
|
||||||
MetadataFactory factory = get();
|
MetadataFactory factory = get();
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ public class V1_8Factory implements MetadataFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityData effects(boolean onFire, boolean glowing) {
|
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
|
||||||
return new EntityData(0, EntityDataTypes.BYTE, onFire ? 0x01 : 0);
|
return new EntityData(0, EntityDataTypes.BYTE, (onFire ? 0x01 : 0) | (invisible ? 0x20 : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EntityData createSkinLayers(int index) {
|
protected EntityData createSkinLayers(int index) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class V1_9Factory extends V1_8Factory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityData effects(boolean onFire, boolean glowing) {
|
public EntityData effects(boolean onFire, boolean glowing, boolean invisible) {
|
||||||
return new EntityData(0, EntityDataTypes.BYTE, (byte) ((onFire ? 0x01 : 0) | (glowing ? 0x40 : 0)));
|
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<SkinDescriptor> SKIN = new NPCProperty<>("skin");
|
||||||
public static NPCProperty<NamedTextColor> GLOW = new NPCProperty<>("glow");
|
public static NPCProperty<NamedTextColor> GLOW = new NPCProperty<>("glow");
|
||||||
public static NPCProperty<Boolean> FIRE = new NPCProperty<>("fire", false);
|
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;
|
this.type = type;
|
||||||
ArrayList<NPCProperty<?>> list = new ArrayList<>(List.of(allowedProperties));
|
ArrayList<NPCProperty<?>> list = new ArrayList<>(List.of(allowedProperties));
|
||||||
list.add(NPCProperty.FIRE);
|
list.add(NPCProperty.FIRE);
|
||||||
|
list.add(NPCProperty.INVISIBLE);
|
||||||
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) list.add(NPCProperty.GLOW);
|
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_9)) list.add(NPCProperty.GLOW);
|
||||||
this.allowedProperties = Set.copyOf(list);
|
this.allowedProperties = Set.copyOf(list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,9 @@ public class V1_8Factory implements PacketFactory {
|
||||||
public void sendAllMetadata(Player player, PacketEntity entity) {
|
public void sendAllMetadata(Player player, PacketEntity entity) {
|
||||||
NPC owner = entity.getOwner();
|
NPC owner = entity.getOwner();
|
||||||
if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers());
|
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
|
@Override
|
||||||
|
@ -130,7 +132,7 @@ public class V1_8Factory implements PacketFactory {
|
||||||
}
|
}
|
||||||
CompletableFuture<UserProfile> future = new CompletableFuture<>();
|
CompletableFuture<UserProfile> future = new CompletableFuture<>();
|
||||||
descriptor.fetch(player).thenAccept(skin -> {
|
descriptor.fetch(player).thenAccept(skin -> {
|
||||||
skin.apply(profile);
|
if (skin != null) skin.apply(profile);
|
||||||
future.complete(profile);
|
future.complete(profile);
|
||||||
});
|
});
|
||||||
return future;
|
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());
|
if (entity.getType() == EntityTypes.PLAYER && owner.getProperty(NPCProperty.SKIN_LAYERS)) sendMetadata(player, entity, MetadataFactory.get().skinLayers());
|
||||||
boolean glow = owner.hasProperty(NPCProperty.GLOW);
|
boolean glow = owner.hasProperty(NPCProperty.GLOW);
|
||||||
boolean fire = owner.getProperty(NPCProperty.FIRE);
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue