Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EntityEquipmentChangeEvent #11667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 95 additions & 41 deletions patches/api/0071-Add-PlayerArmorChangeEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Subject: [PATCH] Add PlayerArmorChangeEvent

diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerArmorChangeEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerArmorChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7cc612ec81b0c7da6ee6676167e047e69347966
index 0000000000000000000000000000000000000000..b11c8f5abc6110e20538e2ebadd162666e039cc8
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerArmorChangeEvent.java
@@ -0,0 +1,120 @@
@@ -0,0 +1,96 @@
+package com.destroystokyo.paper.event.player;
+
+import java.util.Set;
+import io.papermc.paper.event.entity.EntityEquipmentChangeEvent;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
Expand All @@ -30,56 +30,32 @@ index 0000000000000000000000000000000000000000..c7cc612ec81b0c7da6ee6676167e047e
+ * Not currently called for environmental factors though it <strong>MAY BE IN THE FUTURE</strong>
+ */
+@NullMarked
+public class PlayerArmorChangeEvent extends PlayerEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+public class PlayerArmorChangeEvent extends EntityEquipmentChangeEvent {
+
+ private final SlotType slotType;
+ private final ItemStack oldItem;
+ private final ItemStack newItem;
+
+ @ApiStatus.Internal
+ public PlayerArmorChangeEvent(final Player player, final SlotType slotType, final ItemStack oldItem, final ItemStack newItem) {
+ super(player);
+ this.slotType = slotType;
+ this.oldItem = oldItem;
+ this.newItem = newItem;
+ public PlayerArmorChangeEvent(final Player player, final EquipmentSlot equipmentSlot, final ItemStack oldItem, final ItemStack newItem) {
+ super(player, equipmentSlot, oldItem, newItem);
+ this.slotType = SlotType.valueOf(equipmentSlot.name());
+ }
+
+ /**
+ * Gets the type of slot being altered.
+ *
+ * @return type of slot being altered
+ */
+ public SlotType getSlotType() {
+ return this.slotType;
+ @Override
+ public Player getEntity() {
+ return (Player) entity;
+ }
+
+ /**
+ * Gets the existing item that's being replaced
+ *
+ * @return old item
+ */
+ public ItemStack getOldItem() {
+ return this.oldItem;
+ public Player getPlayer() {
+ return (Player) entity;
+ }
+
+ /**
+ * Gets the new item that's replacing the old
+ * Gets the type of slot being altered.
+ *
+ * @return new item
+ * @return type of slot being altered
+ */
+ public ItemStack getNewItem() {
+ return this.newItem;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ public SlotType getSlotType() {
+ return this.slotType;
+ }
+
+ public enum SlotType {
Expand Down Expand Up @@ -130,3 +106,81 @@ index 0000000000000000000000000000000000000000..c7cc612ec81b0c7da6ee6676167e047e
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityEquipmentChangeEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityEquipmentChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..f737c4bddd8f6bcfb5d4935fc68b55c36aabd9a8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityEquipmentChangeEvent.java
@@ -0,0 +1,72 @@
+package io.papermc.paper.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when an entities' equipment changes.
+ */
+@NullMarked
+public class EntityEquipmentChangeEvent extends EntityEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final EquipmentSlot equipmentSlot;
+ private final ItemStack oldItem;
+ private final ItemStack newItem;
+
+ @ApiStatus.Internal
+ public EntityEquipmentChangeEvent(final LivingEntity entity, final EquipmentSlot equipmentSlot, final ItemStack oldItem, final ItemStack newItem) {
+ super(entity);
+ this.equipmentSlot = equipmentSlot;
+ this.oldItem = oldItem;
+ this.newItem = newItem;
+ }
+
+ @Override
+ public LivingEntity getEntity() {
+ return (LivingEntity) entity;
+ }
+
+ /**
+ * Gets the equipment slot of the item that is being replaced.
+ *
+ * @return the old item
+ */
+ public EquipmentSlot getEquipmentSlot() {
+ return equipmentSlot;
+ }
+
+ /**
+ * Gets the existing item that is being replaced.
+ *
+ * @return the old item
+ */
+ public ItemStack getOldItem() {
+ return oldItem;
+ }
+
+ /**
+ * Gets the new item that is replacing the old item.
+ *
+ * @return the new item
+ */
+ public ItemStack getNewItem() {
+ return newItem;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+}
12 changes: 7 additions & 5 deletions patches/server/0156-Add-PlayerArmorChangeEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Add PlayerArmorChangeEvent


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 009539fa39c81c610ac34747cc09082a0756c79d..a03583daf6cac850c154e0e89dc3fa00a844903f 100644
index 009539fa39c81c610ac34747cc09082a0756c79d..bcbbb0eb7fea095269e93ad5ada5f9b27aa57dd4 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3280,10 +3280,17 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3280,10 +3280,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
throw new MatchException((String) null, (Throwable) null);
}

Expand All @@ -19,10 +19,12 @@ index 009539fa39c81c610ac34747cc09082a0756c79d..a03583daf6cac850c154e0e89dc3fa00
+ itemstack = this.getItemBySlot(enumitemslot); final ItemStack newEquipment = itemstack;// Paper - PlayerArmorChangeEvent - obfhelper
if (this.equipmentHasChanged(itemstack2, itemstack)) {
+ // Paper start - PlayerArmorChangeEvent
+ final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(oldEquipment);
+ final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(newEquipment);
+ if (this instanceof ServerPlayer && enumitemslot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
+ final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(oldEquipment);
+ final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(newEquipment);
+ new com.destroystokyo.paper.event.player.PlayerArmorChangeEvent((Player) this.getBukkitEntity(), com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType.valueOf(enumitemslot.name()), oldItem, newItem).callEvent();
+ new com.destroystokyo.paper.event.player.PlayerArmorChangeEvent((Player) this.getBukkitEntity(), org.bukkit.craftbukkit.CraftEquipmentSlot.getSlot(enumitemslot), oldItem, newItem).callEvent();
+ } else {
+ new io.papermc.paper.event.entity.EntityEquipmentChangeEvent(this.getBukkitLivingEntity(), org.bukkit.craftbukkit.CraftEquipmentSlot.getSlot(enumitemslot), oldItem, newItem).callEvent();
+ }
+ // Paper end - PlayerArmorChangeEvent
if (map == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Make shield blocking delay configurable


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 08322f6147b78d140a2e0d6c3189ee95270c3c71..9e21f77689eb246ad72cdbd7ee19211dcb2ed738 100644
index bcbbb0eb7fea095269e93ad5ada5f9b27aa57dd4..75a085455cdca59b50d544b4f089c9f0e0088d35 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -4102,12 +4102,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4104,12 +4104,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (this.isUsingItem() && !this.useItem.isEmpty()) {
Item item = this.useItem.getItem();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Add ray tracing methods to LivingEntity


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 61124dfec84792fa23ce1b0f03cbd97b1a6bde5b..30343efb680edf3dc355498b04c5db9ebecbf270 100644
index 93d55414861960782a3bd9cd436a7aa492d19dfe..02b467a4231b39bd497389c03f2bcae1037d2f07 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -4113,6 +4113,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4115,6 +4115,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

// Paper start - Make shield blocking delay configurable
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0251-Add-LivingEntity-getTargetEntity.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Add LivingEntity#getTargetEntity


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 781568c0aef7556fd4422574d31c0ad790f0afa7..8f6f73fd6f1fce3b78e472f454e0a34043a00125 100644
index bd1f8d001aa665951441520f268af895b73bf53b..6462634a9802766cc26c647764654482ad8f7cb3 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -4177,6 +4177,38 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4179,6 +4179,38 @@ public abstract class LivingEntity extends Entity implements Attackable {
return this.level().clip(raytrace);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ this is going to be the best soultion all around.
Improvements/suggestions welcome!

diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index cef054ba95ed7d2b0e2ee575edae3e94b77f58b6..8d958ac09bd9484d879eee6acb6aaea20f4f8339 100644
index c00c0473c83c724e894cbd08d75e476e8599d55c..05f3275e7be6a0dca5cef3124802287790701dcd 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2826,9 +2826,15 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
Expand All @@ -41,7 +41,7 @@ index cef054ba95ed7d2b0e2ee575edae3e94b77f58b6..8d958ac09bd9484d879eee6acb6aaea2
Iterator iterator = entityliving.getActiveEffects().iterator();

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 659ed49cebb8ed2a6e1c88fb1e4d95f0520820d4..2e1628a9b5507ff6b1f00ac83247fc033b2db1c4 100644
index e67d8da5be50e07cb0473b7bfe6d381da044155a..a430a3e2c3b4ae53cad1fbaf4dd71b9e2f24ccf7 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2822,17 +2822,28 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down Expand Up @@ -106,10 +106,10 @@ index 659ed49cebb8ed2a6e1c88fb1e4d95f0520820d4..2e1628a9b5507ff6b1f00ac83247fc03
if (this.valid) {
Bukkit.getPluginManager().callEvent(event);
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 8f6f73fd6f1fce3b78e472f454e0a34043a00125..7e684a7df64b64e25ba602c39488712eefdfbcfa 100644
index 6462634a9802766cc26c647764654482ad8f7cb3..45e6d6ccafffafcf8eff5dc3c0254fc427e94860 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3757,9 +3757,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3759,9 +3759,15 @@ public abstract class LivingEntity extends Entity implements Attackable {

@Override
public void stopRiding() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Prevent consuming the wrong itemstack


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 7e684a7df64b64e25ba602c39488712eefdfbcfa..ba78e8b73793292830f3260f9a12c50c698bb881 100644
index 45e6d6ccafffafcf8eff5dc3c0254fc427e94860..e2aebc600a915c308febcc2c05e3fcd5d73ce4af 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3994,9 +3994,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3996,9 +3996,14 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

public void startUsingItem(InteractionHand hand) {
Expand All @@ -24,15 +24,15 @@ index 7e684a7df64b64e25ba602c39488712eefdfbcfa..ba78e8b73793292830f3260f9a12c50c
this.useItem = itemstack;
this.useItemRemaining = itemstack.getUseDuration(this);
if (!this.level().isClientSide) {
@@ -4067,6 +4072,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4069,6 +4074,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
this.releaseUsingItem();
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
+ this.startUsingItem(this.getUsedItemHand(), true); // Paper - Prevent consuming the wrong itemstack
// CraftBukkit start - fire PlayerItemConsumeEvent
ItemStack itemstack;
PlayerItemConsumeEvent event = null; // Paper
@@ -4104,8 +4110,8 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -4106,8 +4112,8 @@ public abstract class LivingEntity extends Entity implements Attackable {
}

this.stopUsingItem();
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0313-Entity-Jump-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Subject: [PATCH] Entity Jump API
public net.minecraft.world.entity.LivingEntity jumping

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index ba78e8b73793292830f3260f9a12c50c698bb881..a874913997c80c8f47f395e2ef4bb959aaa3e76d 100644
index e2aebc600a915c308febcc2c05e3fcd5d73ce4af..9cc56273be257451e73a79de7d9f5c47973155be 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3538,8 +3538,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3540,8 +3540,10 @@ public abstract class LivingEntity extends Entity implements Attackable {
} else if (this.isInLava() && (!this.onGround() || d3 > d4)) {
this.jumpInLiquid(FluidTags.LAVA);
} else if ((this.onGround() || flag && d3 <= d4) && this.noJumpDelay == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ The entity's current team collision rule causes them to NEVER collide.
Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>

diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index a874913997c80c8f47f395e2ef4bb959aaa3e76d..b01e472a8a5f05e586bfa35e33abfd3875518ab3 100644
index 9cc56273be257451e73a79de7d9f5c47973155be..6b3217179a1705163af27d75ab735aa910f8182a 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3682,10 +3682,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3684,10 +3684,24 @@ public abstract class LivingEntity extends Entity implements Attackable {
if (!(world instanceof ServerLevel worldserver)) {
this.level().getEntities(EntityTypeTest.forClass(net.minecraft.world.entity.player.Player.class), this.getBoundingBox(), EntitySelector.pushableBy(this)).forEach(this::doPush);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Don't check chunk for portal on world gen entity add


diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 911dcfb9b34d94e38db71c17022b8a8c1e707eb7..e3322e8897f361b3fbf8d7188207271906a84c46 100644
index 7ab69f6d3e5da621ac830561f3aa5ff4abf4d6ac..1417d7795c0edf79b3dc5ad1837db6b560b56537 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3797,7 +3797,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3799,7 +3799,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
Entity entity = this.getVehicle();

super.stopRiding(suppressCancellation); // Paper - Force entity dismount during teleportation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ index b8d57e25851dd7da905100dfd4022e4b99fd7f02..721321a19ce056f82de2bef44a8791dc
} else if (entity1 instanceof Player && entity instanceof Player && !io.papermc.paper.configuration.GlobalConfiguration.get().collisions.enablePlayerCollisions) { // Paper - Configurable player collision
return false;
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index e3322e8897f361b3fbf8d7188207271906a84c46..b725bd297ed40aa8ccf3ad77f8652b39980efcf2 100644
index 1417d7795c0edf79b3dc5ad1837db6b560b56537..43f6fec9462fd66877dea551883f9b31779f76fa 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3711,7 +3711,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3713,7 +3713,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
return;
}
// Paper end - don't run getEntities if we're not going to use its result
Expand All @@ -56,7 +56,7 @@ index e3322e8897f361b3fbf8d7188207271906a84c46..b725bd297ed40aa8ccf3ad77f8652b39

if (!list.isEmpty()) {
// Paper - don't run getEntities if we're not going to use its result; moved up
@@ -3916,9 +3916,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
@@ -3918,9 +3918,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
return !this.isRemoved() && this.collides; // CraftBukkit
}

Expand Down
Loading
Loading