Added Animations
This commit is contained in:
parent
f5950090c7
commit
919cfa5e5e
|
@ -5,6 +5,7 @@
|
||||||
package net.jitse.npclib.api;
|
package net.jitse.npclib.api;
|
||||||
|
|
||||||
import net.jitse.npclib.api.skin.Skin;
|
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.NPCSlot;
|
||||||
import net.jitse.npclib.api.state.NPCState;
|
import net.jitse.npclib.api.state.NPCState;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
@ -103,6 +104,13 @@ public interface NPC {
|
||||||
*/
|
*/
|
||||||
NPC toggleState(NPCState state);
|
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.
|
* 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.NPCHideEvent;
|
||||||
import net.jitse.npclib.api.events.NPCShowEvent;
|
import net.jitse.npclib.api.events.NPCShowEvent;
|
||||||
import net.jitse.npclib.api.skin.Skin;
|
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.NPCSlot;
|
||||||
import net.jitse.npclib.api.state.NPCState;
|
import net.jitse.npclib.api.state.NPCState;
|
||||||
import net.jitse.npclib.hologram.Hologram;
|
import net.jitse.npclib.hologram.Hologram;
|
||||||
|
@ -268,6 +269,16 @@ public abstract class NPCBase implements NPC, NPCPacketHandler {
|
||||||
return this;
|
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
|
@Override
|
||||||
public ItemStack getItem(NPCSlot slot) {
|
public ItemStack getItem(NPCSlot slot) {
|
||||||
Objects.requireNonNull(slot, "Slot cannot be null");
|
Objects.requireNonNull(slot, "Slot cannot be null");
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package net.jitse.npclib.internal;
|
package net.jitse.npclib.internal;
|
||||||
|
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
import net.jitse.npclib.api.state.NPCSlot;
|
import net.jitse.npclib.api.state.NPCSlot;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@ interface NPCPacketHandler {
|
||||||
|
|
||||||
void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto);
|
void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto);
|
||||||
|
|
||||||
|
void sendAnimationPacket(Player player, NPCAnimation animation);
|
||||||
|
|
||||||
default void sendEquipmentPackets(Player player) {
|
default void sendEquipmentPackets(Player player) {
|
||||||
for (NPCSlot slot : NPCSlot.values())
|
for (NPCSlot slot : NPCSlot.values())
|
||||||
sendEquipmentPacket(player, slot, true);
|
sendEquipmentPacket(player, slot, true);
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_10_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_10_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_11_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_11_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_12_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_12_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_13_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_13_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_13_R2.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_13_R2.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_14_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_14_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_15_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_15_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import net.jitse.npclib.NPCLib;
|
import net.jitse.npclib.NPCLib;
|
||||||
import net.jitse.npclib.api.skin.Skin;
|
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.NPCSlot;
|
||||||
import net.jitse.npclib.hologram.Hologram;
|
import net.jitse.npclib.hologram.Hologram;
|
||||||
import net.jitse.npclib.internal.MinecraftVersion;
|
import net.jitse.npclib.internal.MinecraftVersion;
|
||||||
|
@ -30,6 +31,7 @@ public class NPC_v1_16_R1 extends NPCBase {
|
||||||
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
|
||||||
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
|
||||||
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
|
||||||
|
private PacketPlayOutAnimation packetPlayOutAnimation;
|
||||||
|
|
||||||
public NPC_v1_16_R1(NPCLib instance, List<String> lines) {
|
public NPC_v1_16_R1(NPCLib instance, List<String> lines) {
|
||||||
super(instance, lines);
|
super(instance, lines);
|
||||||
|
@ -109,6 +111,14 @@ public class NPC_v1_16_R1 extends NPCBase {
|
||||||
playerConnection.sendPacket(packet);
|
playerConnection.sendPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendAnimationPacket(Player player, NPCAnimation animation) {
|
||||||
|
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
|
||||||
|
|
||||||
|
PacketPlayOutAnimation packet = new PacketPlayOutAnimationWrapper().create(animation, entityId);
|
||||||
|
playerConnection.sendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSkin(Skin skin) {
|
public void updateSkin(Skin skin) {
|
||||||
GameProfile newProfile = new GameProfile(uuid, name);
|
GameProfile newProfile = new GameProfile(uuid, name);
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_16_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_16_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package net.jitse.npclib.nms.v1_8_R2.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_8_R2.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
int id = npcAnimation.getId();
|
||||||
|
if(id == 3) throw new IllegalArgumentException("Offhand Swing Animations are only available on 1.9 and up.");
|
||||||
|
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, id);
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package net.jitse.npclib.nms.v1_8_R3.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_8_R3.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
int id = npcAnimation.getId();
|
||||||
|
if(id == 3) throw new IllegalArgumentException("Offhand Swing Animations are only available on 1.9 and up.");
|
||||||
|
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, id);
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_9_R1.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_9_R1.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.jitse.npclib.nms.v1_9_R2.packets;
|
||||||
|
|
||||||
|
import com.comphenix.tinyprotocol.Reflection;
|
||||||
|
import net.jitse.npclib.api.state.NPCAnimation;
|
||||||
|
import net.minecraft.server.v1_9_R2.PacketPlayOutAnimation;
|
||||||
|
|
||||||
|
public class PacketPlayOutAnimationWrapper {
|
||||||
|
|
||||||
|
public PacketPlayOutAnimation create(NPCAnimation npcAnimation, int entityId) {
|
||||||
|
PacketPlayOutAnimation packetPlayOutAnimation = new PacketPlayOutAnimation();
|
||||||
|
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "a", int.class)
|
||||||
|
.set(packetPlayOutAnimation, entityId);
|
||||||
|
Reflection.getField(packetPlayOutAnimation.getClass(), "b", int.class)
|
||||||
|
.set(packetPlayOutAnimation, npcAnimation.getId());
|
||||||
|
|
||||||
|
return packetPlayOutAnimation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue