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:45:59 -0500
|
|
|
|
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
|
2024-02-01 10:15:57 +01:00
|
|
|
index 0000000000000000000000000000000000000000..ab08219497f7e362f113321c4bcfd180b335bf20
|
2021-06-11 14:02:28 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerArmorChangeEvent.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -0,0 +1,127 @@
|
2021-06-11 14:02:28 +02:00
|
|
|
+package com.destroystokyo.paper.event.player;
|
|
|
|
+
|
|
|
|
+import org.bukkit.Material;
|
|
|
|
+import org.bukkit.entity.Player;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+import org.bukkit.event.player.PlayerEvent;
|
|
|
|
+import org.bukkit.inventory.ItemStack;
|
|
|
|
+
|
|
|
|
+import java.util.Set;
|
2023-09-14 12:44:12 +02:00
|
|
|
+import org.jetbrains.annotations.ApiStatus;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
+
|
|
|
|
+import static org.bukkit.Material.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Called when the player themselves change their armor items
|
|
|
|
+ * <p>
|
|
|
|
+ * Not currently called for environmental factors though it <strong>MAY BE IN THE FUTURE</strong>
|
|
|
|
+ */
|
|
|
|
+public class PlayerArmorChangeEvent extends PlayerEvent {
|
2024-02-01 10:15:57 +01:00
|
|
|
+
|
|
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ @NotNull private final SlotType slotType;
|
2023-09-14 12:44:12 +02:00
|
|
|
+ @NotNull private final ItemStack oldItem;
|
|
|
|
+ @NotNull private final ItemStack newItem;
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2023-09-14 12:44:12 +02:00
|
|
|
+ @ApiStatus.Internal
|
|
|
|
+ public PlayerArmorChangeEvent(@NotNull Player player, @NotNull SlotType slotType, @NotNull ItemStack oldItem, @NotNull ItemStack newItem) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ super(player);
|
|
|
|
+ this.slotType = slotType;
|
|
|
|
+ this.oldItem = oldItem;
|
|
|
|
+ this.newItem = newItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the type of slot being altered.
|
|
|
|
+ *
|
|
|
|
+ * @return type of slot being altered
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ public SlotType getSlotType() {
|
|
|
|
+ return this.slotType;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the existing item that's being replaced
|
|
|
|
+ *
|
|
|
|
+ * @return old item
|
|
|
|
+ */
|
2023-09-14 12:44:12 +02:00
|
|
|
+ @NotNull
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ItemStack getOldItem() {
|
|
|
|
+ return this.oldItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the new item that's replacing the old
|
|
|
|
+ *
|
|
|
|
+ * @return new item
|
|
|
|
+ */
|
2023-09-14 12:44:12 +02:00
|
|
|
+ @NotNull
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ItemStack getNewItem() {
|
|
|
|
+ return this.newItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ @Override
|
|
|
|
+ public HandlerList getHandlers() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static HandlerList getHandlerList() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public enum SlotType {
|
2023-07-13 22:09:26 +02:00
|
|
|
+ HEAD(NETHERITE_HELMET, DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, CHAINMAIL_HELMET, LEATHER_HELMET, CARVED_PUMPKIN, PLAYER_HEAD, SKELETON_SKULL, ZOMBIE_HEAD, CREEPER_HEAD, WITHER_SKELETON_SKULL, TURTLE_HELMET, DRAGON_HEAD, PIGLIN_HEAD),
|
2021-06-11 14:02:28 +02:00
|
|
|
+ CHEST(NETHERITE_CHESTPLATE, DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, CHAINMAIL_CHESTPLATE, LEATHER_CHESTPLATE, ELYTRA),
|
|
|
|
+ LEGS(NETHERITE_LEGGINGS, DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, CHAINMAIL_LEGGINGS, LEATHER_LEGGINGS),
|
|
|
|
+ FEET(NETHERITE_BOOTS, DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, CHAINMAIL_BOOTS, LEATHER_BOOTS);
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ private final Set<Material> types;
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ SlotType(Material... types) {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ this.types = Set.of(types);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets an immutable set of all allowed material types that can be placed in an
|
|
|
|
+ * armor slot.
|
|
|
|
+ *
|
|
|
|
+ * @return immutable set of material types
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ public Set<Material> getTypes() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.types;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the type of slot via the specified material
|
|
|
|
+ *
|
|
|
|
+ * @param material material to get slot by
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * @return slot type the material will go in, or {@code null} if it won't
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
|
|
|
+ @Nullable
|
|
|
|
+ public static SlotType getByMaterial(@NotNull Material material) {
|
|
|
|
+ for (SlotType slotType : values()) {
|
|
|
|
+ if (slotType.getTypes().contains(material)) {
|
|
|
|
+ return slotType;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2023-09-14 12:44:12 +02:00
|
|
|
+ * Gets whether this material can be equipped to a slot
|
2021-06-11 14:02:28 +02:00
|
|
|
+ *
|
|
|
|
+ * @param material material to check
|
2023-09-14 12:44:12 +02:00
|
|
|
+ * @return whether this material can be equipped
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
|
|
|
+ public static boolean isEquipable(@NotNull Material material) {
|
|
|
|
+ return getByMaterial(material) != null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|