3030import com .github .retrooper .packetevents .wrapper .play .server .WrapperPlayServerTeams ;
3131import com .github .retrooper .packetevents .wrapper .play .server .WrapperPlayServerUseBed ;
3232import com .github .unldenis .corpse .CorpsePlugin ;
33- import com .github .unldenis .corpse .manager .CorpsePool ;
33+ import com .github .unldenis .corpse .model .CorpseArmor ;
34+ import com .github .unldenis .corpse .pool .CorpsePool ;
3435import com .github .unldenis .corpse .util .BedUtil ;
3536import com .github .unldenis .corpse .util .ProfileUtils ;
3637import io .github .retrooper .packetevents .util .SpigotConversionUtil ;
@@ -83,7 +84,7 @@ public static CorpseBuilder fromLocation(@NotNull Location location) {
8384 Corpse (
8485 @ NotNull Location location ,
8586 @ NotNull List <TextureProperty > textures ,
86- @ Nullable ItemStack [] armorContents ,
87+ @ Nullable CorpseArmor armor ,
8788 @ Nullable String name
8889 ) {
8990 pool = CorpsePool .getInstance ();
@@ -92,20 +93,16 @@ public static CorpseBuilder fromLocation(@NotNull Location location) {
9293 this .location = location ;
9394 this .profile = new UserProfile (UUID .randomUUID (), name != null ? name : ProfileUtils .randomName (), textures );
9495
96+ // create npc
9597 internalNPC = new CorpseNPC (profile , id ,
9698 pool .isShowTags () ? null : WrapperPlayServerTeams .NameTagVisibility .NEVER );
9799
100+ // set npc location
98101 internalNPC .setLocation (SpigotConversionUtil .fromBukkitLocation (location ));
99- if (pool .isRenderArmor () && armorContents != null ) {
100- if (armorContents [0 ] != null )
101- internalNPC .setBoots (SpigotConversionUtil .fromBukkitItemStack (armorContents [0 ]));
102- if (armorContents [1 ] != null )
103- internalNPC .setLeggings (SpigotConversionUtil .fromBukkitItemStack (armorContents [1 ]));
104- if (armorContents [2 ] != null )
105- internalNPC .setChestplate (SpigotConversionUtil .fromBukkitItemStack (armorContents [2 ]));
106- if (armorContents [3 ] != null )
107- internalNPC .setHelmet (SpigotConversionUtil .fromBukkitItemStack (armorContents [3 ]));
108102
103+ // set npc armor
104+ if (pool .isRenderArmor () && armor != null ) {
105+ this .setArmor (armor );
109106 hasArmor = true ;
110107 } else {
111108 hasArmor = false ;
@@ -148,7 +145,7 @@ public void show(@NotNull Player player) {
148145
149146 } else {
150147 List <EntityData <?>> entityData = new ArrayList <>();
151- entityData .add (new EntityData <>(6 , EntityDataTypes .ENTITY_POSE , EntityPose . SLEEPING ));
148+ entityData .add (new EntityData <>(6 , EntityDataTypes .ENTITY_POSE , pool . getEntityPose () ));
152149 WrapperPlayServerEntityMetadata packet = new WrapperPlayServerEntityMetadata (id , entityData );
153150 PacketEvents .getAPI ().getProtocolManager ().sendPacket (channel , packet );
154151 }
@@ -181,23 +178,53 @@ public void destroy() {
181178 CorpsePool .getInstance ().remove (this .id );
182179 }
183180
181+ /**
182+ * Gets the entity id of the corpse.
183+ * @return The entity id of the corpse.
184+ */
184185 public int getId () {
185186 return id ;
186187 }
187188
189+ /**
190+ * Gets the name of the corpse.
191+ * @return The name of the corpse.
192+ */
188193 @ NotNull
189194 public String getName () {
190195 return profile .getName ();
191196 }
192197
198+ /**
199+ * Gets the location of the corpse.
200+ * @return The location of the corpse.
201+ */
193202 @ NotNull
194203 public Location getLocation () {
195204 return location ;
196205 }
197206
207+ /**
208+ * Gets the players that are seeing the corpse.
209+ * @return The players that are seeing the corpse.
210+ */
198211 @ NotNull
199212 public Collection <Player > getSeeingPlayers () {
200213 return Collections .unmodifiableCollection (this .seeingPlayers );
201214 }
202215
216+ /**
217+ * Sets the armor of the corpse.
218+ * @param armor The armor to set.
219+ */
220+ private void setArmor (@ NotNull CorpseArmor armor ) {
221+ if (armor .getBoots () != null )
222+ internalNPC .setBoots (SpigotConversionUtil .fromBukkitItemStack (armor .getBoots ()));
223+ if (armor .getLeggings () != null )
224+ internalNPC .setLeggings (SpigotConversionUtil .fromBukkitItemStack (armor .getLeggings ()));
225+ if (armor .getChestplate () != null )
226+ internalNPC .setChestplate (SpigotConversionUtil .fromBukkitItemStack (armor .getChestplate ()));
227+ if (armor .getHelmet () != null )
228+ internalNPC .setHelmet (SpigotConversionUtil .fromBukkitItemStack (armor .getHelmet ()));
229+ }
203230}
0 commit comments