Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. @EventHandler
  2. public void onArmourEquip(ArmorEquipEvent event) {
  3. Player player = event.getPlayer();
  4. ItemStack newItem = event.getNewArmorPiece();
  5. ItemStack oldItem = event.getOldArmorPiece();
  6. if (ce.hasEnchantments(oldItem)) {
  7. for (CEnchantments cEnchantments : ce.getEnchantmentPotions().keySet()) {
  8. if (ce.hasEnchantment(oldItem, cEnchantments)) {
  9. if (cEnchantments.isEnabled()) {
  10. HashMap<PotionEffectType, Integer> effects = ce.getUpdatedEffects(player, new ItemStack(Material.AIR), oldItem, cEnchantments);
  11. for (PotionEffectType type : effects.keySet()) {
  12. if (effects.get(type) < 0) {
  13. player.removePotionEffect(type);
  14. } else {
  15. player.removePotionEffect(type);
  16. player.addPotionEffect(new PotionEffect(type, Integer.MAX_VALUE, effects.get(type)));
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }
  23. if (ce.hasEnchantments(newItem)) {
  24. for (CEnchantments cEnchantments : ce.getEnchantmentPotions().keySet()) {
  25. if (ce.hasEnchantment(newItem, cEnchantments)) {
  26. if (cEnchantments.isEnabled()) {
  27. EnchantmentUseEvent enchantmentUseEvent = new EnchantmentUseEvent(player, cEnchantments, newItem);
  28. Bukkit.getPluginManager().callEvent(enchantmentUseEvent);
  29. if (!enchantmentUseEvent.isCancelled()) {
  30. HashMap<PotionEffectType, Integer> effects = ce.getUpdatedEffects(player, newItem, oldItem, cEnchantments);
  31. for (PotionEffectType type : effects.keySet()) {
  32. if (effects.get(type) < 0) {
  33. player.removePotionEffect(type);
  34. } else {
  35. player.removePotionEffect(type);
  36. player.addPotionEffect(new PotionEffect(type, Integer.MAX_VALUE, effects.get(type)));
  37. }
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement