Added Animations

This commit is contained in:
MCMDEV
2020-07-14 15:13:26 +02:00
parent f5950090c7
commit 919cfa5e5e
17 changed files with 298 additions and 0 deletions
@@ -5,6 +5,7 @@
package net.jitse.npclib.api;
import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.api.state.NPCState;
import org.bukkit.Location;
@@ -103,6 +104,13 @@ public interface NPC {
*/
NPC toggleState(NPCState state);
/**
* Plays an animation as the the NPC.
*
* @param animation The animation to play.
*/
void playAnimation(NPCAnimation animation);
/**
* Get state of NPC.
*
@@ -0,0 +1,20 @@
package net.jitse.npclib.api.state;
public enum NPCAnimation {
SWING_MAINHAND(0),
TAKE_DAMAGE(1),
SWING_OFFHAND(3),
CRITICAL_DAMAGE(4),
MAGICAL_DAMAGE(5);
private int id;
NPCAnimation(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
@@ -11,6 +11,7 @@ import net.jitse.npclib.api.NPC;
import net.jitse.npclib.api.events.NPCHideEvent;
import net.jitse.npclib.api.events.NPCShowEvent;
import net.jitse.npclib.api.skin.Skin;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.api.state.NPCState;
import net.jitse.npclib.hologram.Hologram;
@@ -268,6 +269,16 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
return this;
}
@Override
public void playAnimation(NPCAnimation animation) {
for (UUID shownUuid : shown) {
Player player = Bukkit.getPlayer(shownUuid);
if (player != null && isShown(player)) {
sendAnimationPacket(player, animation);
}
}
}
@Override
public ItemStack getItem(NPCSlot slot) {
Objects.requireNonNull(slot, "Slot cannot be null");
@@ -4,6 +4,7 @@
package net.jitse.npclib.internal;
import net.jitse.npclib.api.state.NPCAnimation;
import net.jitse.npclib.api.state.NPCSlot;
import org.bukkit.entity.Player;
@@ -22,6 +23,8 @@ interface NPCPacketHandler {
void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto);
void sendAnimationPacket(Player player, NPCAnimation animation);
default void sendEquipmentPackets(Player player) {
for (NPCSlot slot : NPCSlot.values())
sendEquipmentPacket(player, slot, true);