mirror of
https://github.com/Minestom/Minestom.git
synced 2024-07-01 08:54:57 +02:00
Fix ArmorEquipEvent for EntityCreature
This commit is contained in:
parent
59214b3b96
commit
f6803f9c24
|
@ -3,6 +3,7 @@ package net.minestom.server.entity;
|
|||
import net.minestom.server.collision.CollisionUtils;
|
||||
import net.minestom.server.entity.pathfinding.EntityPathFinder;
|
||||
import net.minestom.server.entity.property.Attribute;
|
||||
import net.minestom.server.event.ArmorEquipEvent;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.*;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
|
@ -170,7 +171,7 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
|
||||
@Override
|
||||
public void setHelmet(ItemStack itemStack) {
|
||||
this.helmet = itemStack;
|
||||
this.helmet = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
||||
syncEquipment(EntityEquipmentPacket.Slot.HELMET);
|
||||
}
|
||||
|
||||
|
@ -181,7 +182,7 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
|
||||
@Override
|
||||
public void setChestplate(ItemStack itemStack) {
|
||||
this.chestplate = itemStack;
|
||||
this.chestplate = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
||||
syncEquipment(EntityEquipmentPacket.Slot.CHESTPLATE);
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
|
||||
@Override
|
||||
public void setLeggings(ItemStack itemStack) {
|
||||
this.leggings = itemStack;
|
||||
this.leggings = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
||||
syncEquipment(EntityEquipmentPacket.Slot.LEGGINGS);
|
||||
}
|
||||
|
||||
|
@ -203,7 +204,7 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
|
||||
@Override
|
||||
public void setBoots(ItemStack itemStack) {
|
||||
this.boots = itemStack;
|
||||
this.boots = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
||||
syncEquipment(EntityEquipmentPacket.Slot.BOOTS);
|
||||
}
|
||||
|
||||
|
@ -260,4 +261,10 @@ public abstract class EntityCreature extends LivingEntity {
|
|||
if (blockPosition.getY() > getPosition().getY())
|
||||
jump(1);
|
||||
}
|
||||
|
||||
private ItemStack getEquipmentItem(ItemStack itemStack, ArmorEquipEvent.ArmorSlot armorSlot) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(itemStack, armorSlot);
|
||||
callEvent(ArmorEquipEvent.class, armorEquipEvent);
|
||||
return armorEquipEvent.getArmorItem();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package net.minestom.server.inventory;
|
||||
|
||||
import net.minestom.server.event.ArmorEquipEvent;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
||||
|
||||
import static net.minestom.server.utils.inventory.PlayerInventoryUtils.*;
|
||||
|
||||
public interface EquipmentHandler {
|
||||
|
||||
ItemStack getItemInMainHand();
|
||||
|
@ -51,18 +48,4 @@ public interface EquipmentHandler {
|
|||
}
|
||||
}
|
||||
|
||||
default ArmorEquipEvent getArmorEquipEventPacket(int slot, ItemStack itemStack) {
|
||||
if (slot == HELMET_SLOT) {
|
||||
return new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
||||
} else if (slot == CHESTPLATE_SLOT) {
|
||||
return new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
||||
} else if (slot == LEGGINGS_SLOT) {
|
||||
return new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
||||
} else if (slot == BOOTS_SLOT) {
|
||||
return new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -189,7 +189,18 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
|||
} else if (slot == OFFHAND_SLOT) {
|
||||
equipmentSlot = EntityEquipmentPacket.Slot.OFF_HAND;
|
||||
} else {
|
||||
ArmorEquipEvent armorEquipEvent = getArmorEquipEventPacket(slot, itemStack);
|
||||
ArmorEquipEvent armorEquipEvent = null;
|
||||
|
||||
if (slot == HELMET_SLOT) {
|
||||
armorEquipEvent = new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
||||
} else if (slot == CHESTPLATE_SLOT) {
|
||||
armorEquipEvent = new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
||||
} else if (slot == LEGGINGS_SLOT) {
|
||||
armorEquipEvent = new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
||||
} else if (slot == BOOTS_SLOT) {
|
||||
armorEquipEvent = new ArmorEquipEvent(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
||||
}
|
||||
|
||||
if (armorEquipEvent != null) {
|
||||
equipmentSlot = armorEquipEvent.getArmorSlot().toEquipmentPacketSlot();
|
||||
player.callEvent(ArmorEquipEvent.class, armorEquipEvent);
|
||||
|
|
Loading…
Reference in New Issue
Block a user