mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Revert "Made EntityEquipEvent cancellable"
This reverts commit d72fb72e
This commit is contained in:
parent
d72fb72e74
commit
00278881ee
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import net.minestom.server.event.item.EntityEquipEvent;
|
||||||
import net.minestom.server.item.attribute.AttributeSlot;
|
import net.minestom.server.item.attribute.AttributeSlot;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -127,11 +127,8 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND);
|
this.mainHandItem = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.MAIN_HAND);
|
||||||
this.mainHandItem = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.MAIN_HAND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -142,11 +139,8 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND);
|
this.offHandItem = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.OFF_HAND);
|
||||||
this.offHandItem = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.OFF_HAND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -157,11 +151,8 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHelmet(@NotNull ItemStack itemStack) {
|
public void setHelmet(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.HELMET);
|
this.helmet = getEquipmentItem(itemStack, EquipmentSlot.HELMET);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.HELMET);
|
||||||
this.helmet = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.HELMET);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -172,11 +163,8 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChestplate(@NotNull ItemStack itemStack) {
|
public void setChestplate(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE);
|
this.chestplate = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.CHESTPLATE);
|
||||||
this.chestplate = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.CHESTPLATE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -187,11 +175,8 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLeggings(@NotNull ItemStack itemStack) {
|
public void setLeggings(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS);
|
this.leggings = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.LEGGINGS);
|
||||||
this.leggings = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.LEGGINGS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -202,17 +187,14 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBoots(@NotNull ItemStack itemStack) {
|
public void setBoots(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.BOOTS);
|
this.boots = getEquipmentItem(itemStack, EquipmentSlot.BOOTS);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.BOOTS);
|
||||||
this.boots = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.BOOTS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) {
|
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) {
|
||||||
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot);
|
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot);
|
||||||
callEvent(EntityEquipEvent.class, entityEquipEvent);
|
callEvent(EntityEquipEvent.class, entityEquipEvent);
|
||||||
return entityEquipEvent.isCancelled() ? null : entityEquipEvent.getEquippedItem();
|
return entityEquipEvent.getEquippedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,11 +69,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND);
|
this.mainHandItem = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.MAIN_HAND);
|
||||||
this.mainHandItem = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.MAIN_HAND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -84,11 +81,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND);
|
this.offHandItem = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.OFF_HAND);
|
||||||
this.offHandItem = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.OFF_HAND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -99,11 +93,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHelmet(@NotNull ItemStack itemStack) {
|
public void setHelmet(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.HELMET);
|
this.helmet = getEquipmentItem(itemStack, EquipmentSlot.HELMET);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.HELMET);
|
||||||
this.helmet = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.HELMET);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -114,11 +105,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setChestplate(@NotNull ItemStack itemStack) {
|
public void setChestplate(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE);
|
this.chestplate = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.CHESTPLATE);
|
||||||
this.chestplate = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.CHESTPLATE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -129,11 +117,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLeggings(@NotNull ItemStack itemStack) {
|
public void setLeggings(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS);
|
this.leggings = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.LEGGINGS);
|
||||||
this.leggings = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.LEGGINGS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -144,11 +129,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBoots(@NotNull ItemStack itemStack) {
|
public void setBoots(@NotNull ItemStack itemStack) {
|
||||||
itemStack = getEquipmentItem(itemStack, EquipmentSlot.BOOTS);
|
this.boots = getEquipmentItem(itemStack, EquipmentSlot.BOOTS);
|
||||||
if (itemStack != null) {
|
syncEquipment(EquipmentSlot.BOOTS);
|
||||||
this.boots = itemStack;
|
|
||||||
syncEquipment(EquipmentSlot.BOOTS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSmall() {
|
public boolean isSmall() {
|
||||||
@ -256,6 +238,6 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) {
|
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) {
|
||||||
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot);
|
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot);
|
||||||
callEvent(EntityEquipEvent.class, entityEquipEvent);
|
callEvent(EntityEquipEvent.class, entityEquipEvent);
|
||||||
return entityEquipEvent.isCancelled() ? null : entityEquipEvent.getEquippedItem();
|
return entityEquipEvent.getEquippedItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,16 @@ package net.minestom.server.event.item;
|
|||||||
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.EquipmentSlot;
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.event.CancellableEvent;
|
|
||||||
import net.minestom.server.event.Event;
|
import net.minestom.server.event.Event;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class EntityEquipEvent extends Event implements CancellableEvent {
|
public class EntityEquipEvent extends Event {
|
||||||
|
|
||||||
private final Entity entity;
|
private final Entity entity;
|
||||||
private ItemStack equippedItem;
|
private ItemStack equippedItem;
|
||||||
private final EquipmentSlot slot;
|
private final EquipmentSlot slot;
|
||||||
|
|
||||||
private boolean cancelled;
|
|
||||||
|
|
||||||
public EntityEquipEvent(@NotNull Entity entity, @NotNull ItemStack equippedItem, @NotNull EquipmentSlot slot) {
|
public EntityEquipEvent(@NotNull Entity entity, @NotNull ItemStack equippedItem, @NotNull EquipmentSlot slot) {
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.equippedItem = equippedItem;
|
this.equippedItem = equippedItem;
|
||||||
@ -39,14 +36,4 @@ public class EntityEquipEvent extends Event implements CancellableEvent {
|
|||||||
public EquipmentSlot getSlot() {
|
public EquipmentSlot getSlot() {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -186,17 +186,11 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
|
|||||||
equipmentSlot = EquipmentSlot.BOOTS;
|
equipmentSlot = EquipmentSlot.BOOTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean cancel = false;
|
|
||||||
if (equipmentSlot != null) {
|
if (equipmentSlot != null) {
|
||||||
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(player, itemStack, equipmentSlot);
|
EntityEquipEvent entityEquipEvent = new EntityEquipEvent(player, itemStack, equipmentSlot);
|
||||||
|
|
||||||
player.callEvent(EntityEquipEvent.class, entityEquipEvent);
|
player.callEvent(EntityEquipEvent.class, entityEquipEvent);
|
||||||
itemStack = entityEquipEvent.getEquippedItem();
|
itemStack = entityEquipEvent.getEquippedItem();
|
||||||
cancel = entityEquipEvent.isCancelled();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cancel) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.itemStacks[slot] = itemStack;
|
this.itemStacks[slot] = itemStack;
|
||||||
|
Loading…
Reference in New Issue
Block a user