2020-01-22 03:02:07 +01:00
|
|
|
From 119d214a5cf12953f1d00e283e2c5768be6d9d03 Mon Sep 17 00:00:00 2001
|
2017-11-11 05:46:55 +01:00
|
|
|
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
|
2020-01-22 03:02:07 +01:00
|
|
|
index 00000000..2827a100
|
2017-11-11 05:46:55 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerArmorChangeEvent.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -0,0 +1,137 @@
|
2017-11-11 05:46:55 +01: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.Arrays;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.Set;
|
2019-03-20 01:28:15 +01:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
2017-11-11 05:46:55 +01:00
|
|
|
+
|
|
|
|
+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 {
|
|
|
|
+ private static final HandlerList HANDLERS = new HandlerList();
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull private final SlotType slotType;
|
|
|
|
+ @Nullable private final ItemStack oldItem;
|
|
|
|
+ @Nullable private final ItemStack newItem;
|
2017-11-11 05:46:55 +01:00
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public PlayerArmorChangeEvent(@NotNull Player player, @NotNull SlotType slotType, @Nullable ItemStack oldItem, @Nullable ItemStack newItem) {
|
2017-11-11 05:46:55 +01: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
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-11-11 05:46:55 +01:00
|
|
|
+ public SlotType getSlotType() {
|
|
|
|
+ return this.slotType;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the existing item that's being replaced
|
|
|
|
+ *
|
|
|
|
+ * @return old item
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
|
|
|
+ public ItemStack getOldItem() {
|
|
|
|
+ return this.oldItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the new item that's replacing the old
|
|
|
|
+ *
|
|
|
|
+ * @return new item
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
|
|
|
+ public ItemStack getNewItem() {
|
|
|
|
+ return this.newItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return "ArmorChangeEvent{" + "player=" + player + ", slotType=" + slotType + ", oldItem=" + oldItem + ", newItem=" + newItem + '}';
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-11-11 05:46:55 +01:00
|
|
|
+ @Override
|
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return HANDLERS;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-11-11 05:46:55 +01:00
|
|
|
+ public static HandlerList getHandlerList() {
|
|
|
|
+ return HANDLERS;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public enum SlotType {
|
2018-07-14 03:44:35 +02:00
|
|
|
+ HEAD(DIAMOND_HELMET, GOLDEN_HELMET, IRON_HELMET, CHAINMAIL_HELMET, LEATHER_HELMET, PUMPKIN, JACK_O_LANTERN),
|
|
|
|
+ CHEST(DIAMOND_CHESTPLATE, GOLDEN_CHESTPLATE, IRON_CHESTPLATE, CHAINMAIL_CHESTPLATE, LEATHER_CHESTPLATE, ELYTRA),
|
|
|
|
+ LEGS(DIAMOND_LEGGINGS, GOLDEN_LEGGINGS, IRON_LEGGINGS, CHAINMAIL_LEGGINGS, LEATHER_LEGGINGS),
|
|
|
|
+ FEET(DIAMOND_BOOTS, GOLDEN_BOOTS, IRON_BOOTS, CHAINMAIL_BOOTS, LEATHER_BOOTS);
|
2017-11-11 05:46:55 +01:00
|
|
|
+
|
|
|
|
+ private final Set<Material> mutableTypes = new HashSet<>();
|
|
|
|
+ private Set<Material> immutableTypes;
|
|
|
|
+
|
|
|
|
+ SlotType(Material... types) {
|
|
|
|
+ this.mutableTypes.addAll(Arrays.asList(types));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets an immutable set of all allowed material types that can be placed in an
|
|
|
|
+ * armor slot.
|
|
|
|
+ *
|
|
|
|
+ * @return immutable set of material types
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-11-11 05:46:55 +01:00
|
|
|
+ public Set<Material> getTypes() {
|
|
|
|
+ if (immutableTypes == null) {
|
|
|
|
+ immutableTypes = Collections.unmodifiableSet(mutableTypes);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return immutableTypes;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets the type of slot via the specified material
|
|
|
|
+ *
|
|
|
|
+ * @param material material to get slot by
|
|
|
|
+ * @return slot type the material will go in, or null if it won't
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public static SlotType getByMaterial(@NotNull Material material) {
|
2017-11-11 05:46:55 +01:00
|
|
|
+ for (SlotType slotType : values()) {
|
|
|
|
+ if (slotType.getTypes().contains(material)) {
|
|
|
|
+ return slotType;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets whether or not this material can be equipped to a slot
|
|
|
|
+ *
|
|
|
|
+ * @param material material to check
|
|
|
|
+ * @return whether or not this material can be equipped
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public static boolean isEquipable(@NotNull Material material) {
|
2017-11-11 05:46:55 +01:00
|
|
|
+ return getByMaterial(material) != null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
--
|
2020-01-22 03:02:07 +01:00
|
|
|
2.25.0.windows.1
|
2017-11-11 05:46:55 +01:00
|
|
|
|