|
11 | 11 | import org.bukkit.event.EventHandler;
|
12 | 12 | import org.bukkit.event.EventPriority;
|
13 | 13 | import org.bukkit.event.Listener;
|
14 |
| -import org.bukkit.event.inventory.InventoryClickEvent; |
| 14 | +import org.bukkit.event.block.Action; |
15 | 15 | import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
16 | 16 | import org.bukkit.event.player.PlayerInteractEntityEvent;
|
17 | 17 | import org.bukkit.event.player.PlayerInteractEvent;
|
@@ -50,65 +50,64 @@ public void onArmorStandRightClickEvent(PlayerInteractAtEntityEvent event) {
|
50 | 50 | Player player = event.getPlayer();
|
51 | 51 | if (!player.hasPermission(ConfigDataType.ARMOR_STAND_SWAP_PERMISSION.getString())) return;
|
52 | 52 | int value = getArmorSwapEnabled(player);
|
| 53 | + player.sendMessage(player.isSneaking() + " Sneaking"); |
53 | 54 | if (!player.isSneaking()) return;
|
54 | 55 | if (value != 1) return;
|
55 | 56 |
|
56 | 57 | Entity entity = event.getRightClicked();
|
57 | 58 |
|
| 59 | + if (entity instanceof ArmorStand stand) { |
| 60 | + event.setCancelled(true); |
| 61 | + if (stand.getEquipment() == null) return; |
| 62 | + if (!stand.isVisible()) return; |
58 | 63 |
|
59 |
| - if (!entity.getType().equals(EntityType.ARMOR_STAND)) return; |
60 |
| - |
61 |
| - event.setCancelled(true); |
62 |
| - ArmorStand stand = (ArmorStand) entity; |
63 |
| - if (stand.getEquipment() == null) return; |
64 |
| - if (!stand.isVisible()) return; |
65 |
| - |
66 |
| - ItemStack[] standArmorList = stand.getEquipment().getArmorContents(); |
67 |
| - ItemStack[] playerArmorList = player.getInventory().getArmorContents(); |
68 |
| - for (ItemStack itemStack : playerArmorList) { |
69 |
| - String itemName; |
70 |
| - if (canMove(itemStack, player)) { |
71 |
| - if (itemStack == null || itemStack.getType().equals(Material.AIR)) { |
72 |
| - itemName = null; |
73 |
| - } else { |
74 |
| - itemName = itemStack.getType().toString().toUpperCase(Locale.ROOT); |
75 |
| - } |
76 |
| - if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_BOOTS.getName())) { |
77 |
| - stand.getEquipment().setBoots(itemStack); |
78 |
| - } |
79 |
| - if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_LEGGINGS.getName())) { |
80 |
| - stand.getEquipment().setLeggings(itemStack); |
81 |
| - } |
82 |
| - if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_CHEST_PLATE.getName())) { |
83 |
| - stand.getEquipment().setChestplate(itemStack); |
84 |
| - } |
85 |
| - if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_HELMET.getName())) { |
86 |
| - stand.getEquipment().setHelmet(itemStack); |
| 64 | + ItemStack[] standArmorList = stand.getEquipment().getArmorContents(); |
| 65 | + ItemStack[] playerArmorList = player.getInventory().getArmorContents(); |
| 66 | + for (ItemStack itemStack : playerArmorList) { |
| 67 | + String itemName; |
| 68 | + if (canMove(itemStack, player)) { |
| 69 | + if (itemStack == null || itemStack.getType().equals(Material.AIR)) { |
| 70 | + itemName = null; |
| 71 | + } else { |
| 72 | + itemName = itemStack.getType().toString().toUpperCase(Locale.ROOT); |
| 73 | + } |
| 74 | + if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_BOOTS.getName())) { |
| 75 | + stand.getEquipment().setBoots(itemStack); |
| 76 | + } |
| 77 | + if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_LEGGINGS.getName())) { |
| 78 | + stand.getEquipment().setLeggings(itemStack); |
| 79 | + } |
| 80 | + if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_CHEST_PLATE.getName())) { |
| 81 | + stand.getEquipment().setChestplate(itemStack); |
| 82 | + } |
| 83 | + if (itemName == null || itemName.contains(EquipmentDataType.PLAYER_HELMET.getName())) { |
| 84 | + stand.getEquipment().setHelmet(itemStack); |
| 85 | + } |
87 | 86 | }
|
88 | 87 | }
|
89 |
| - } |
90 |
| - for (ItemStack itemStack : standArmorList) { |
91 |
| - String itemName; |
92 |
| - if (canMove(itemStack, player)) { |
93 |
| - if (itemStack == null || itemStack.getType().equals(Material.AIR)) { |
94 |
| - itemName = null; |
95 |
| - } else itemName = itemStack.getType().toString().toUpperCase(Locale.ROOT); |
96 |
| - if (itemName == null || itemName.contains(EquipmentDataType.STAND_BOOTS.getName())) { |
97 |
| - player.getInventory().setBoots(itemStack); |
98 |
| - } |
99 |
| - if (itemName == null || itemName.contains(EquipmentDataType.STAND_LEGGINGS.getName())) { |
100 |
| - player.getInventory().setLeggings(itemStack); |
101 |
| - } |
102 |
| - if (itemName == null || itemName.contains(EquipmentDataType.STAND_CHEST_PLATE.getName())) { |
103 |
| - player.getInventory().setChestplate(itemStack); |
104 |
| - } |
105 |
| - if (itemName == null || itemName.contains(EquipmentDataType.STAND_HELMET.getName())) { |
106 |
| - player.getInventory().setHelmet(itemStack); |
| 88 | + for (ItemStack itemStack : standArmorList) { |
| 89 | + String itemName; |
| 90 | + if (canMove(itemStack, player)) { |
| 91 | + if (itemStack == null || itemStack.getType().equals(Material.AIR)) { |
| 92 | + itemName = null; |
| 93 | + } else itemName = itemStack.getType().toString().toUpperCase(Locale.ROOT); |
| 94 | + if (itemName == null || itemName.contains(EquipmentDataType.STAND_BOOTS.getName())) { |
| 95 | + player.getInventory().setBoots(itemStack); |
| 96 | + } |
| 97 | + if (itemName == null || itemName.contains(EquipmentDataType.STAND_LEGGINGS.getName())) { |
| 98 | + player.getInventory().setLeggings(itemStack); |
| 99 | + } |
| 100 | + if (itemName == null || itemName.contains(EquipmentDataType.STAND_CHEST_PLATE.getName())) { |
| 101 | + player.getInventory().setChestplate(itemStack); |
| 102 | + } |
| 103 | + if (itemName == null || itemName.contains(EquipmentDataType.STAND_HELMET.getName())) { |
| 104 | + player.getInventory().setHelmet(itemStack); |
| 105 | + } |
107 | 106 | }
|
108 | 107 | }
|
| 108 | + standWithHand(player, stand); |
| 109 | + player.playSound(player.getLocation(), Sound.valueOf(sound), 1.0F, 1.0F); |
109 | 110 | }
|
110 |
| - standWithHand(player, stand); |
111 |
| - player.playSound(player.getLocation(), Sound.valueOf(sound), 1.0F, 1.0F); |
112 | 111 | }
|
113 | 112 | }
|
114 | 113 | @SuppressWarnings("ConstantConditions")
|
@@ -184,49 +183,60 @@ public void giveItem(ItemStack playerItem, ItemStack itemOnFrame, ItemFrame clic
|
184 | 183 | //
|
185 | 184 | // RIGHT CLICK ON ARMOR EVENT START HERE
|
186 | 185 | //
|
| 186 | + Boolean success = true; |
187 | 187 | @EventHandler
|
188 | 188 | public void onArmorRightClickEvent(PlayerInteractEvent event) {
|
| 189 | + if (!event.getAction().equals(Action.RIGHT_CLICK_AIR) || !event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return; |
189 | 190 | if (mainHandSwap) {
|
| 191 | + success = false; |
190 | 192 | Player player = event.getPlayer();
|
191 | 193 | if (player.getInventory().getItemInMainHand().getType().isAir()) return;
|
192 | 194 | int value = getArmorSwapEnabled(player);
|
193 | 195 | if (value == 1) {
|
194 | 196 | Block block = event.getClickedBlock();
|
195 | 197 | if (block != null) {
|
196 |
| - if (!block.getType().isInteractable()) return; |
| 198 | + player.sendMessage(block.getType().toString()); |
| 199 | + if (block.getType().isInteractable()) return; |
| 200 | + } |
| 201 | + ItemStack item = player.getInventory().getItemInMainHand(); |
| 202 | + String itemName = item.getType().toString().toUpperCase(Locale.ROOT); |
| 203 | + if (itemName.contains(EquipmentDataType.PLAYER_HELMET.getName())) { |
| 204 | + if (player.getInventory().getHelmet() == null) return; |
| 205 | + ItemStack returnItem = player.getInventory().getHelmet(); |
| 206 | + if (!canMove(returnItem, player)) return; |
| 207 | + player.getInventory().setItemInMainHand(returnItem); |
| 208 | + player.getInventory().setHelmet(item); |
| 209 | + success = true; |
| 210 | + } |
| 211 | + else if (itemName.contains(EquipmentDataType.PLAYER_CHEST_PLATE.getName()) || itemName.contains(EquipmentDataType.PLAYER_ELYTRA.getName())) { |
| 212 | + if (player.getInventory().getChestplate() == null) return; |
| 213 | + ItemStack returnItem = player.getInventory().getChestplate(); |
| 214 | + if (!canMove(returnItem, player)) return; |
| 215 | + player.getInventory().setItemInMainHand(returnItem); |
| 216 | + player.getInventory().setChestplate(item); |
| 217 | + success = true; |
| 218 | + } |
| 219 | + else if (itemName.contains(EquipmentDataType.PLAYER_BOOTS.getName())) { |
| 220 | + if (player.getInventory().getBoots() == null) return; |
| 221 | + ItemStack returnItem = player.getInventory().getBoots(); |
| 222 | + if (!canMove(returnItem, player)) return; |
| 223 | + player.getInventory().setItemInMainHand(returnItem); |
| 224 | + player.getInventory().setBoots(item); |
| 225 | + success = true; |
| 226 | + } |
| 227 | + else if (itemName.contains(EquipmentDataType.PLAYER_LEGGINGS.getName())) { |
| 228 | + if (player.getInventory().getLeggings() == null) return; |
| 229 | + ItemStack returnItem = player.getInventory().getBoots(); |
| 230 | + if (!canMove(returnItem, player)) return; |
| 231 | + player.getInventory().setItemInMainHand(returnItem); |
| 232 | + player.getInventory().setLeggings(item); |
| 233 | + success = true; |
| 234 | + } |
| 235 | + if (success) { |
| 236 | + player.playSound(player.getLocation(), Sound.valueOf(sound), 1.0F, 1.0F); |
197 | 237 | }
|
198 |
| - ItemStack Item = player.getInventory().getItemInMainHand(); |
199 |
| - playerItem(player, Item, sound); |
200 | 238 | }
|
201 | 239 | }
|
202 |
| - } |
203 |
| - public void playerItem(Player player, ItemStack item, String sound){ |
204 |
| - String itemName = item.getType().toString().toUpperCase(Locale.ROOT); |
205 |
| - if (itemName.contains(EquipmentDataType.PLAYER_HELMET.getName())) { |
206 |
| - ItemStack returnItem = player.getInventory().getHelmet(); |
207 |
| - if (!canMove(returnItem, player)) return; |
208 |
| - player.getInventory().setItemInMainHand(returnItem); |
209 |
| - player.getInventory().setHelmet(item); |
210 |
| - } |
211 |
| - else if (itemName.contains(EquipmentDataType.PLAYER_CHEST_PLATE.getName()) || itemName.contains(EquipmentDataType.PLAYER_ELYTRA.getName())) { |
212 |
| - ItemStack returnItem = player.getInventory().getChestplate(); |
213 |
| - if (!canMove(returnItem, player)) return; |
214 |
| - player.getInventory().setItemInMainHand(returnItem); |
215 |
| - player.getInventory().setChestplate(item); |
216 |
| - } |
217 |
| - else if (itemName.contains(EquipmentDataType.PLAYER_BOOTS.getName())) { |
218 |
| - ItemStack returnItem = player.getInventory().getBoots(); |
219 |
| - if (!canMove(returnItem, player)) return; |
220 |
| - player.getInventory().setItemInMainHand(returnItem); |
221 |
| - player.getInventory().setBoots(item); |
222 |
| - } |
223 |
| - else if (itemName.contains(EquipmentDataType.PLAYER_LEGGINGS.getName())) { |
224 |
| - ItemStack returnItem = player.getInventory().getLeggings(); |
225 |
| - if (!canMove(returnItem, player)) return; |
226 |
| - player.getInventory().setItemInMainHand(returnItem); |
227 |
| - player.getInventory().setLeggings(item); |
228 |
| - } |
229 |
| - player.playSound(player.getLocation(), Sound.valueOf(sound), 1.0F, 1.0F); |
230 | 240 | }
|
231 | 241 | //
|
232 | 242 | // RIGHT CLICK ON ARMOR EVENT ENDS HERE
|
|
0 commit comments