2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: pkt77 <parkerkt77@gmail.com>
|
|
|
|
Date: Fri, 10 Nov 2017 23:46:34 -0500
|
|
|
|
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
|
2024-10-27 18:11:15 +01:00
|
|
|
index bcc0137fec45406e70231b4e2a5bd69dc08ffb5a..84e11e2c62e643f959f1a570a27f6ad07df165d4 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-10-27 18:11:15 +01:00
|
|
|
@@ -3283,6 +3283,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2024-10-22 23:30:51 +02:00
|
|
|
itemstack = this.getItemBySlot(enumitemslot);
|
|
|
|
if (this.equipmentHasChanged(itemstack2, itemstack)) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start - PlayerArmorChangeEvent
|
2024-06-14 13:07:50 +02:00
|
|
|
+ if (this instanceof ServerPlayer && enumitemslot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
|
2024-04-24 03:25:14 +02:00
|
|
|
+ final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(itemstack1);
|
|
|
|
+ final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(itemstack2);
|
2024-02-01 10:15:57 +01:00
|
|
|
+ new com.destroystokyo.paper.event.player.PlayerArmorChangeEvent((Player) this.getBukkitEntity(), com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType.valueOf(enumitemslot.name()), oldItem, newItem).callEvent();
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2024-01-22 18:04:55 +01:00
|
|
|
+ // Paper end - PlayerArmorChangeEvent
|
2021-06-11 14:02:28 +02:00
|
|
|
if (map == null) {
|
|
|
|
map = Maps.newEnumMap(EquipmentSlot.class);
|
|
|
|
}
|
2023-09-25 01:05:05 +02:00
|
|
|
diff --git a/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java b/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java
|
2023-07-13 22:09:26 +02:00
|
|
|
new file mode 100644
|
2024-10-25 19:15:40 +02:00
|
|
|
index 0000000000000000000000000000000000000000..1431b3faf081dc3ee5b33639bdc90c5057ae7027
|
2023-07-13 22:09:26 +02:00
|
|
|
--- /dev/null
|
2023-09-25 01:05:05 +02:00
|
|
|
+++ b/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -0,0 +1,75 @@
|
2023-07-13 22:09:26 +02:00
|
|
|
+package io.papermc.paper.inventory.item;
|
|
|
|
+
|
|
|
|
+import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
2023-09-24 09:16:58 +02:00
|
|
|
+import java.util.stream.Stream;
|
2024-10-25 19:15:40 +02:00
|
|
|
+import net.minecraft.core.component.DataComponents;
|
2023-07-13 22:09:26 +02:00
|
|
|
+import net.minecraft.world.entity.EquipmentSlot;
|
|
|
|
+import net.minecraft.world.item.Item;
|
2024-10-25 19:15:40 +02:00
|
|
|
+import net.minecraft.world.item.equipment.Equippable;
|
2023-07-13 22:09:26 +02:00
|
|
|
+import org.bukkit.Material;
|
|
|
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
2024-10-21 00:06:54 +02:00
|
|
|
+import org.bukkit.support.environment.AllFeatures;
|
2023-09-24 09:16:58 +02:00
|
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
2023-07-13 22:09:26 +02:00
|
|
|
+
|
2023-09-24 09:16:58 +02:00
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2023-09-25 01:05:05 +02:00
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
2023-07-13 22:09:26 +02:00
|
|
|
+
|
2024-10-21 00:06:54 +02:00
|
|
|
+@AllFeatures
|
|
|
|
+public class ArmorSlotTypeMaterialTest {
|
2023-07-13 22:09:26 +02:00
|
|
|
+
|
2023-09-25 01:05:05 +02:00
|
|
|
+ public static Stream<Object[]> slotTypeParams() {
|
2023-07-13 22:09:26 +02:00
|
|
|
+ final List<Object[]> parameters = new ArrayList<>();
|
|
|
|
+ for (final PlayerArmorChangeEvent.SlotType slotType : PlayerArmorChangeEvent.SlotType.values()) {
|
|
|
|
+ for (final Material item : slotType.getTypes()) {
|
|
|
|
+ parameters.add(new Object[]{ slotType, item });
|
|
|
|
+ }
|
|
|
|
+ }
|
2023-09-24 09:16:58 +02:00
|
|
|
+ return parameters.stream();
|
2023-07-13 22:09:26 +02:00
|
|
|
+ }
|
|
|
|
+
|
2023-09-25 01:05:05 +02:00
|
|
|
+ @ParameterizedTest(name = "{argumentsWithNames}")
|
|
|
|
+ @MethodSource("slotTypeParams")
|
|
|
|
+ public void testSlotType(PlayerArmorChangeEvent.SlotType slotType, Material item) {
|
2023-09-24 09:16:58 +02:00
|
|
|
+ final Item nmsItem = CraftMagicNumbers.getItem(item);
|
2024-10-25 19:15:40 +02:00
|
|
|
+ final Equippable equippable = nmsItem.components().get(DataComponents.EQUIPPABLE);
|
|
|
|
+ assertNotNull(equippable, item + " isn't equipable");
|
2023-09-24 09:16:58 +02:00
|
|
|
+ final EquipmentSlot slot = switch (slotType) {
|
2023-07-13 22:09:26 +02:00
|
|
|
+ case HEAD -> EquipmentSlot.HEAD;
|
|
|
|
+ case CHEST -> EquipmentSlot.CHEST;
|
|
|
|
+ case LEGS -> EquipmentSlot.LEGS;
|
|
|
|
+ case FEET -> EquipmentSlot.FEET;
|
|
|
|
+ };
|
2024-10-25 19:15:40 +02:00
|
|
|
+ assertEquals(equippable.slot(), slot, item + " isn't set to the right slot");
|
2023-07-13 22:09:26 +02:00
|
|
|
+ }
|
|
|
|
+
|
2023-09-25 01:05:05 +02:00
|
|
|
+ public static Stream<Object[]> equipableParams() {
|
2023-07-13 22:09:26 +02:00
|
|
|
+ final List<Object[]> parameters = new ArrayList<>();
|
2023-09-25 01:05:05 +02:00
|
|
|
+ for (final Item item : net.minecraft.core.registries.BuiltInRegistries.ITEM) {
|
2024-10-25 19:15:40 +02:00
|
|
|
+ final Equippable equippable = item.components().get(DataComponents.EQUIPPABLE);
|
|
|
|
+ if (equippable != null) {
|
|
|
|
+ parameters.add(new Object[]{equippable, item});
|
2023-07-13 22:09:26 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
2023-09-24 09:16:58 +02:00
|
|
|
+ return parameters.stream();
|
2023-07-13 22:09:26 +02:00
|
|
|
+ }
|
|
|
|
+
|
2023-09-25 01:05:05 +02:00
|
|
|
+ @ParameterizedTest(name = "{argumentsWithNames}")
|
|
|
|
+ @MethodSource("equipableParams")
|
2024-10-25 19:15:40 +02:00
|
|
|
+ public void testEquipable(Equippable equipable, Item item) {
|
|
|
|
+ final EquipmentSlot equipmentSlot = equipable.slot();
|
2023-07-13 22:09:26 +02:00
|
|
|
+ PlayerArmorChangeEvent.SlotType slotType = switch (equipmentSlot) {
|
|
|
|
+ case HEAD -> PlayerArmorChangeEvent.SlotType.HEAD;
|
|
|
|
+ case CHEST -> PlayerArmorChangeEvent.SlotType.CHEST;
|
|
|
|
+ case LEGS -> PlayerArmorChangeEvent.SlotType.LEGS;
|
|
|
|
+ case FEET -> PlayerArmorChangeEvent.SlotType.FEET;
|
|
|
|
+ default -> null;
|
|
|
|
+ };
|
|
|
|
+ if (slotType != null) {
|
2023-09-24 09:16:58 +02:00
|
|
|
+ assertTrue(slotType.getTypes().contains(CraftMagicNumbers.getMaterial(item)), "SlotType " + slotType + " doesn't include " + item);
|
2023-07-13 22:09:26 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|