mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
105 lines
5.2 KiB
Diff
105 lines
5.2 KiB
Diff
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
|
|
index ec862d3a70b9d9f71873a71c1f1d143bc95799ae..1203387260e5e2727ffb682882da85b8c89c1f4c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -3060,6 +3060,13 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
|
|
|
|
if (this.equipmentHasChanged(itemstack, itemstack1)) {
|
|
+ // Paper start - PlayerArmorChangeEvent
|
|
+ if (this instanceof ServerPlayer && enumitemslot.getType() == EquipmentSlot.Type.ARMOR) {
|
|
+ final org.bukkit.inventory.ItemStack oldItem = CraftItemStack.asBukkitCopy(itemstack);
|
|
+ final org.bukkit.inventory.ItemStack newItem = CraftItemStack.asBukkitCopy(itemstack1);
|
|
+ new com.destroystokyo.paper.event.player.PlayerArmorChangeEvent((Player) this.getBukkitEntity(), com.destroystokyo.paper.event.player.PlayerArmorChangeEvent.SlotType.valueOf(enumitemslot.name()), oldItem, newItem).callEvent();
|
|
+ }
|
|
+ // Paper end - PlayerArmorChangeEvent
|
|
if (map == null) {
|
|
map = Maps.newEnumMap(EquipmentSlot.class);
|
|
}
|
|
diff --git a/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java b/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a706dcbabfe31bf54a552965fa5feb8be34213bf
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/inventory/item/ArmorSlotTypeMaterialTest.java
|
|
@@ -0,0 +1,74 @@
|
|
+package io.papermc.paper.inventory.item;
|
|
+
|
|
+import com.destroystokyo.paper.event.player.PlayerArmorChangeEvent;
|
|
+import java.util.ArrayList;
|
|
+import java.util.List;
|
|
+import java.util.stream.Stream;
|
|
+import net.minecraft.world.entity.EquipmentSlot;
|
|
+import net.minecraft.world.item.Equipable;
|
|
+import net.minecraft.world.item.Item;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import org.bukkit.Material;
|
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
|
+import org.bukkit.support.AbstractTestingBase;
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
+
|
|
+public class ArmorSlotTypeMaterialTest extends AbstractTestingBase {
|
|
+
|
|
+ public static Stream<Object[]> slotTypeParams() {
|
|
+ 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 });
|
|
+ }
|
|
+ }
|
|
+ return parameters.stream();
|
|
+ }
|
|
+
|
|
+ @ParameterizedTest(name = "{argumentsWithNames}")
|
|
+ @MethodSource("slotTypeParams")
|
|
+ public void testSlotType(PlayerArmorChangeEvent.SlotType slotType, Material item) {
|
|
+ final Item nmsItem = CraftMagicNumbers.getItem(item);
|
|
+ final Equipable equipable = Equipable.get(new ItemStack(nmsItem));
|
|
+ assertNotNull(equipable, item + " isn't equipable");
|
|
+ final EquipmentSlot slot = switch (slotType) {
|
|
+ case HEAD -> EquipmentSlot.HEAD;
|
|
+ case CHEST -> EquipmentSlot.CHEST;
|
|
+ case LEGS -> EquipmentSlot.LEGS;
|
|
+ case FEET -> EquipmentSlot.FEET;
|
|
+ };
|
|
+ assertEquals(equipable.getEquipmentSlot(), slot, item + " isn't set to the right slot");
|
|
+ }
|
|
+
|
|
+ public static Stream<Object[]> equipableParams() {
|
|
+ final List<Object[]> parameters = new ArrayList<>();
|
|
+ for (final Item item : net.minecraft.core.registries.BuiltInRegistries.ITEM) {
|
|
+ final Equipable equipable = Equipable.get(new ItemStack(item));
|
|
+ if (equipable != null) {
|
|
+ parameters.add(new Object[]{equipable, item});
|
|
+ }
|
|
+ }
|
|
+ return parameters.stream();
|
|
+ }
|
|
+
|
|
+ @ParameterizedTest(name = "{argumentsWithNames}")
|
|
+ @MethodSource("equipableParams")
|
|
+ public void testEquipable(Equipable equipable, Item item) {
|
|
+ final EquipmentSlot equipmentSlot = equipable.getEquipmentSlot();
|
|
+ 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) {
|
|
+ assertTrue(slotType.getTypes().contains(CraftMagicNumbers.getMaterial(item)), "SlotType " + slotType + " doesn't include " + item);
|
|
+ }
|
|
+ }
|
|
+}
|