From 00278881eeecd23e478d25c990717899a2006f56 Mon Sep 17 00:00:00 2001 From: Arne Dalhuisen <59421074+Bloepiloepi@users.noreply.github.com> Date: Tue, 11 May 2021 20:11:56 +0200 Subject: [PATCH] Revert "Made EntityEquipEvent cancellable" This reverts commit d72fb72e --- .../minestom/server/entity/EquipmentSlot.java | 1 + .../minestom/server/entity/LivingEntity.java | 44 ++++++------------- .../type/decoration/EntityArmorStand.java | 44 ++++++------------- .../server/event/item/EntityEquipEvent.java | 15 +------ .../server/inventory/PlayerInventory.java | 6 --- 5 files changed, 28 insertions(+), 82 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/EquipmentSlot.java b/src/main/java/net/minestom/server/entity/EquipmentSlot.java index 7a3b70708..27a7cf02d 100644 --- a/src/main/java/net/minestom/server/entity/EquipmentSlot.java +++ b/src/main/java/net/minestom/server/entity/EquipmentSlot.java @@ -1,5 +1,6 @@ package net.minestom.server.entity; +import net.minestom.server.event.item.EntityEquipEvent; import net.minestom.server.item.attribute.AttributeSlot; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index 22ddef528..f03e0849b 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -127,11 +127,8 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setItemInMainHand(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND); - if (itemStack != null) { - this.mainHandItem = itemStack; - syncEquipment(EquipmentSlot.MAIN_HAND); - } + this.mainHandItem = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND); + syncEquipment(EquipmentSlot.MAIN_HAND); } @NotNull @@ -142,11 +139,8 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setItemInOffHand(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND); - if (itemStack != null) { - this.offHandItem = itemStack; - syncEquipment(EquipmentSlot.OFF_HAND); - } + this.offHandItem = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND); + syncEquipment(EquipmentSlot.OFF_HAND); } @NotNull @@ -157,11 +151,8 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setHelmet(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.HELMET); - if (itemStack != null) { - this.helmet = itemStack; - syncEquipment(EquipmentSlot.HELMET); - } + this.helmet = getEquipmentItem(itemStack, EquipmentSlot.HELMET); + syncEquipment(EquipmentSlot.HELMET); } @NotNull @@ -172,11 +163,8 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setChestplate(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE); - if (itemStack != null) { - this.chestplate = itemStack; - syncEquipment(EquipmentSlot.CHESTPLATE); - } + this.chestplate = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE); + syncEquipment(EquipmentSlot.CHESTPLATE); } @NotNull @@ -187,11 +175,8 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setLeggings(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS); - if (itemStack != null) { - this.leggings = itemStack; - syncEquipment(EquipmentSlot.LEGGINGS); - } + this.leggings = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS); + syncEquipment(EquipmentSlot.LEGGINGS); } @NotNull @@ -202,17 +187,14 @@ public class LivingEntity extends Entity implements EquipmentHandler { @Override public void setBoots(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.BOOTS); - if (itemStack != null) { - this.boots = itemStack; - syncEquipment(EquipmentSlot.BOOTS); - } + this.boots = getEquipmentItem(itemStack, EquipmentSlot.BOOTS); + syncEquipment(EquipmentSlot.BOOTS); } private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) { EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot); callEvent(EntityEquipEvent.class, entityEquipEvent); - return entityEquipEvent.isCancelled() ? null : entityEquipEvent.getEquippedItem(); + return entityEquipEvent.getEquippedItem(); } @Override diff --git a/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java b/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java index 4e3a1074f..121146e7b 100644 --- a/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java +++ b/src/main/java/net/minestom/server/entity/type/decoration/EntityArmorStand.java @@ -69,11 +69,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setItemInMainHand(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND); - if (itemStack != null) { - this.mainHandItem = itemStack; - syncEquipment(EquipmentSlot.MAIN_HAND); - } + this.mainHandItem = getEquipmentItem(itemStack, EquipmentSlot.MAIN_HAND); + syncEquipment(EquipmentSlot.MAIN_HAND); } @NotNull @@ -84,11 +81,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setItemInOffHand(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND); - if (itemStack != null) { - this.offHandItem = itemStack; - syncEquipment(EquipmentSlot.OFF_HAND); - } + this.offHandItem = getEquipmentItem(itemStack, EquipmentSlot.OFF_HAND); + syncEquipment(EquipmentSlot.OFF_HAND); } @NotNull @@ -99,11 +93,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setHelmet(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.HELMET); - if (itemStack != null) { - this.helmet = itemStack; - syncEquipment(EquipmentSlot.HELMET); - } + this.helmet = getEquipmentItem(itemStack, EquipmentSlot.HELMET); + syncEquipment(EquipmentSlot.HELMET); } @NotNull @@ -114,11 +105,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setChestplate(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE); - if (itemStack != null) { - this.chestplate = itemStack; - syncEquipment(EquipmentSlot.CHESTPLATE); - } + this.chestplate = getEquipmentItem(itemStack, EquipmentSlot.CHESTPLATE); + syncEquipment(EquipmentSlot.CHESTPLATE); } @NotNull @@ -129,11 +117,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setLeggings(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS); - if (itemStack != null) { - this.leggings = itemStack; - syncEquipment(EquipmentSlot.LEGGINGS); - } + this.leggings = getEquipmentItem(itemStack, EquipmentSlot.LEGGINGS); + syncEquipment(EquipmentSlot.LEGGINGS); } @NotNull @@ -144,11 +129,8 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { @Override public void setBoots(@NotNull ItemStack itemStack) { - itemStack = getEquipmentItem(itemStack, EquipmentSlot.BOOTS); - if (itemStack != null) { - this.boots = itemStack; - syncEquipment(EquipmentSlot.BOOTS); - } + this.boots = getEquipmentItem(itemStack, EquipmentSlot.BOOTS); + syncEquipment(EquipmentSlot.BOOTS); } public boolean isSmall() { @@ -256,6 +238,6 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler { private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull EquipmentSlot slot) { EntityEquipEvent entityEquipEvent = new EntityEquipEvent(this, itemStack, slot); callEvent(EntityEquipEvent.class, entityEquipEvent); - return entityEquipEvent.isCancelled() ? null : entityEquipEvent.getEquippedItem(); + return entityEquipEvent.getEquippedItem(); } } diff --git a/src/main/java/net/minestom/server/event/item/EntityEquipEvent.java b/src/main/java/net/minestom/server/event/item/EntityEquipEvent.java index 98f4ae3ca..501273eaf 100644 --- a/src/main/java/net/minestom/server/event/item/EntityEquipEvent.java +++ b/src/main/java/net/minestom/server/event/item/EntityEquipEvent.java @@ -2,19 +2,16 @@ package net.minestom.server.event.item; import net.minestom.server.entity.Entity; import net.minestom.server.entity.EquipmentSlot; -import net.minestom.server.event.CancellableEvent; import net.minestom.server.event.Event; import net.minestom.server.item.ItemStack; import org.jetbrains.annotations.NotNull; -public class EntityEquipEvent extends Event implements CancellableEvent { +public class EntityEquipEvent extends Event { private final Entity entity; private ItemStack equippedItem; private final EquipmentSlot slot; - private boolean cancelled; - public EntityEquipEvent(@NotNull Entity entity, @NotNull ItemStack equippedItem, @NotNull EquipmentSlot slot) { this.entity = entity; this.equippedItem = equippedItem; @@ -39,14 +36,4 @@ public class EntityEquipEvent extends Event implements CancellableEvent { public EquipmentSlot getSlot() { return slot; } - - @Override - public boolean isCancelled() { - return cancelled; - } - - @Override - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } } diff --git a/src/main/java/net/minestom/server/inventory/PlayerInventory.java b/src/main/java/net/minestom/server/inventory/PlayerInventory.java index d095bfab3..a4723b8fd 100644 --- a/src/main/java/net/minestom/server/inventory/PlayerInventory.java +++ b/src/main/java/net/minestom/server/inventory/PlayerInventory.java @@ -186,17 +186,11 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl equipmentSlot = EquipmentSlot.BOOTS; } - boolean cancel = false; if (equipmentSlot != null) { EntityEquipEvent entityEquipEvent = new EntityEquipEvent(player, itemStack, equipmentSlot); player.callEvent(EntityEquipEvent.class, entityEquipEvent); itemStack = entityEquipEvent.getEquippedItem(); - cancel = entityEquipEvent.isCancelled(); - } - - if (cancel) { - return; } this.itemStacks[slot] = itemStack;