More code for #20

Started work on 1.8 R2 to 1.9 R2 with some slight errors, will be fixed later. 1.8 R1 should be working though.
This commit is contained in:
Jitse Boonstra
2019-10-20 11:36:37 +02:00
parent 96028d2ca1
commit cd1115d2a3
14 changed files with 289 additions and 35 deletions
@@ -6,7 +6,8 @@ public enum NPCSlot {
CHESTPLATE(3),
LEGGINGS(2),
BOOTS(1),
IN_HAND(0);
MAINHAND(0),
OFFHAND(5);
int slot;
@@ -83,6 +83,7 @@ public class Hologram {
}
public void generatePackets(MinecraftVersion version) {
// TODO: Check when this method was changed (1.9 R2 is giving an exception...
Reflection.MethodInvoker gravityMethod = (version.isAboveOrEqual(MinecraftVersion.V1_9_R2) ?
Reflection.getMethod(ENTITY_CLAZZ, "setNoGravity", boolean.class) :
Reflection.getMethod(ENTITY_ARMOR_STAND_CLAZZ, "setGravity", boolean.class));
@@ -20,10 +20,10 @@ interface PacketHandler {
void sendMetadataPacket(Player player);
void sendEquipmentPacket(Player player, NPCSlot slot);
void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto);
default void sendEquipmentPackets(Player player) {
for (NPCSlot slot : NPCSlot.values())
sendEquipmentPacket(player, slot);
sendEquipmentPacket(player, slot, true);
}
}
@@ -41,7 +41,8 @@ public abstract class SimpleNPC implements NPC, PacketHandler {
protected Location location;
protected Skin skin;
protected ItemStack helmet, chestplate, leggings, boots, inHand;
// offHand support in 1.9 R1 and later.
protected ItemStack helmet, chestplate, leggings, boots, inHand, offHand;
public SimpleNPC(NPCLib instance, List<String> lines) {
this.instance = instance;
@@ -280,7 +281,7 @@ public abstract class SimpleNPC implements NPC, PacketHandler {
case BOOTS:
this.boots = item;
break;
case IN_HAND:
case MAINHAND:
this.inHand = item;
break;
default:
@@ -290,7 +291,7 @@ public abstract class SimpleNPC implements NPC, PacketHandler {
for (UUID shownUuid : shown) {
Player player = Bukkit.getPlayer(shownUuid);
if (player != null && isShown(player)) {
sendEquipmentPacket(player, slot);
sendEquipmentPacket(player, slot, false);
}
}
return this;