Guest User

Untitled

a guest
Feb 17th, 2020
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class playerListener implements Listener {
  2. private static HighTierEnchants plugin = (HighTierEnchants)Bukkit.getPluginManager().getPlugin("HighTierEnchants");
  3. // Handles Custom Anvil Enchantment (Allows unsafe enchants)
  4. @EventHandler
  5. public void anvil(PrepareAnvilEvent e) {
  6. Inventory inv = e.getInventory();
  7.  
  8. if (inv.getType() == InventoryType.ANVIL) {
  9.  
  10. if (inv.getItem(0) != null && inv.getItem(1) != null) {
  11.  
  12. //Logger logger = plugin.getLogger();
  13.  
  14. // Check if enchanted book
  15. if(inv.getItem(0).getType().equals(Material.ENCHANTED_BOOK)) {
  16. if(inv.getItem(1).getType().equals(Material.ENCHANTED_BOOK)) {
  17. // 2 Enchanted Books
  18. ItemStack NewBook = new ItemStack(inv.getItem(0).getType(), 1);
  19. EnchantmentStorageMeta NewBookESM = (EnchantmentStorageMeta) NewBook.getItemMeta();
  20. EnchantmentStorageMeta esm0 = (EnchantmentStorageMeta) inv.getItem(0).getItemMeta();
  21. EnchantmentStorageMeta esm1 = (EnchantmentStorageMeta) inv.getItem(1).getItemMeta();
  22. if(esm0.hasStoredEnchants() || esm1.hasStoredEnchants()) {
  23. for ( Entry<Enchantment, Integer> i : esm0.getStoredEnchants().entrySet()) {
  24. for (Entry<Enchantment, Integer> j : esm1.getStoredEnchants().entrySet()) {
  25. // Same Enchant
  26. if (j.getKey() == i.getKey()) {
  27. if (i.getValue() == j.getValue()) {
  28. if ((i.getValue() + 1) <= 30) {
  29. NewBookESM.addStoredEnchant(i.getKey(), i.getValue() + 1, true);
  30. }else {
  31. NewBookESM.addStoredEnchant(i.getKey(), i.getValue(), true);
  32. }
  33.  
  34. }else if (i.getValue() > j.getValue()) {
  35. NewBookESM.addStoredEnchant(i.getKey(), i.getValue(), true);
  36. }else {
  37. NewBookESM.addStoredEnchant(i.getKey(), j.getValue(), true);
  38. }
  39.  
  40. }else if (esm0.hasStoredEnchant(j.getKey())){
  41. // Eventually Will Compare Don't Matter
  42. }else {
  43. NewBookESM.addStoredEnchant(j.getKey(), j.getValue(), true);
  44. }
  45.  
  46. }
  47. if (esm1.hasStoredEnchant(i.getKey())) {
  48. // Eventually Will Compare Don't Matter
  49. }else {
  50. NewBookESM.addStoredEnchant(i.getKey(), i.getValue(), true);
  51. }
  52. }
  53. NewBook.setItemMeta(NewBookESM);
  54. e.setResult(NewBook);
  55. }
  56. }
  57. }else {
  58. if (inv.getItem(1).getType().equals(Material.ENCHANTED_BOOK)) {
  59. ItemStack NewItem = new ItemStack(inv.getItem(0).getType(), 1);
  60. NewItem.setItemMeta(inv.getItem(0).getItemMeta());
  61. EnchantmentStorageMeta esm1 = (EnchantmentStorageMeta) inv.getItem(1).getItemMeta();
  62. if (esm1.hasStoredEnchants()) {
  63. for ( Entry<Enchantment, Integer> i : esm1.getStoredEnchants().entrySet()) {
  64. if (inv.getItem(0).containsEnchantment(i.getKey())) {
  65. if (inv.getItem(0).getEnchantmentLevel(i.getKey()) == i.getValue()) {
  66. if ((i.getValue() + 1) <= 30) {
  67. NewItem.addUnsafeEnchantment(i.getKey(), i.getValue() + 1);
  68. }else {
  69. NewItem.addUnsafeEnchantment(i.getKey(), i.getValue());
  70. }
  71.  
  72. }else if (inv.getItem(0).getEnchantmentLevel(i.getKey()) > i.getValue()) {
  73. NewItem.addUnsafeEnchantment(i.getKey(), NewItem.getEnchantmentLevel(i.getKey()));
  74. }else {
  75. NewItem.addUnsafeEnchantment(i.getKey(), i.getValue());
  76. }
  77. }else {
  78. NewItem.addUnsafeEnchantment(i.getKey(), i.getValue());
  79. }
  80. }
  81. for ( Entry<Enchantment, Integer> i : inv.getItem(0).getEnchantments().entrySet()) {
  82. if (esm1.hasStoredEnchant(i.getKey())) {
  83. // Will Compare Up Top
  84. }else {
  85. NewItem.addUnsafeEnchantment(i.getKey(), i.getValue());
  86. }
  87. }
  88. }
  89. e.setResult(NewItem);
  90. }
  91. }
  92. }
  93.  
  94. }
  95. }
  96. }
RAW Paste Data