Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. private ShapelessRecipe plantRecipe;
  2.  
  3. @Override
  4. public void onEnable() {
  5.  
  6. ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
  7. ItemMeta ambrem = ambre.getItemMeta();
  8. ambrem.setDisplayName("§6§lAmbre");
  9. ambre.setItemMeta(ambrem);
  10.  
  11. ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
  12. ItemMeta topazem = topaze.getItemMeta();
  13. topazem.setDisplayName("§c§lTopaze");
  14. topazem.addEnchant(Enchantment.DURABILITY, 1, true);
  15. topaze.setItemMeta(topazem);
  16.  
  17. ItemStack platine = new ItemStack(Material.NETHER_STAR);
  18. ItemMeta platinem = platine.getItemMeta();
  19. platinem.setDisplayName("§4§lPlatine");
  20. platine.setItemMeta(platinem);
  21.  
  22. plantRecipe = new ShapelessRecipe(topaze);
  23. plantRecipe.addIngredient(9, Material.DOUBLE_PLANT);
  24.  
  25. Bukkit.addRecipe(plantRecipe);
  26.  
  27. Bukkit.getPluginManager().registerEvents(this, this);
  28. }
  29.  
  30. @EventHandler
  31. public void onPrepareCraft(PrepareItemCraftEvent e) {
  32. if(!(e.getRecipe() instanceof ShapelessRecipe))
  33. return;
  34.  
  35. ShapelessRecipe recipe = (ShapelessRecipe) e.getRecipe();
  36.  
  37. ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
  38. ItemMeta ambrem = ambre.getItemMeta();
  39. ambrem.setDisplayName("§6§lAmbre");
  40. ambre.setItemMeta(ambrem);
  41.  
  42. ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
  43. ItemMeta topazem = topaze.getItemMeta();
  44. topazem.setDisplayName("§c§lTopaze");
  45. topazem.addEnchant(Enchantment.DURABILITY, 1, true);
  46. topaze.setItemMeta(topazem);
  47.  
  48. ItemStack platine = new ItemStack(Material.NETHER_STAR);
  49. ItemMeta platinem = platine.getItemMeta();
  50. platinem.setDisplayName("§4§lPlatine");
  51. platine.setItemMeta(platinem);
  52.  
  53. if(recipeEquals(recipe, plantRecipe)) {
  54. ItemStack plant = null;
  55.  
  56. for(int i = 0; i < e.getInventory().getMatrix().length; i++) {
  57. if(e.getInventory().getMatrix()[i] != null
  58. && e.getInventory().getMatrix()[i].hasItemMeta()) {
  59.  
  60. plant = e.getInventory().getMatrix()[i];
  61. }
  62. }
  63.  
  64. if(plant == null)
  65. return;
  66. if(!plant.getItemMeta().hasDisplayName())
  67. return;
  68.  
  69. if(plant.getItemMeta().getDisplayName().equals("§6§lAmbre"))
  70. e.getInventory().setResult(topaze);
  71. else if(plant.getItemMeta().getDisplayName().equals("§c§lTopaze"))
  72. e.getInventory().setResult(platine);
  73. else
  74. e.getInventory().setResult(null);
  75. }
  76. }
  77.  
  78. private boolean recipeEquals(Recipe recipe, Recipe other) {
  79. if(recipe.equals(other))
  80. return true;
  81.  
  82. if(recipe instanceof ShapelessRecipe && other instanceof ShapelessRecipe) {
  83. ShapelessRecipe sr = (ShapelessRecipe) recipe;
  84. ShapelessRecipe sr2 = (ShapelessRecipe) other;
  85.  
  86. return sr.getIngredientList().equals(sr2.getIngredientList())
  87. && sr.getResult().equals(sr2.getResult());
  88. }
  89. else if(recipe instanceof ShapedRecipe && other instanceof ShapedRecipe) {
  90. ShapedRecipe sr = (ShapedRecipe) recipe;
  91. ShapedRecipe sr2 = (ShapedRecipe) other;
  92.  
  93. return sr.getIngredientMap().equals(sr2.getIngredientMap())
  94. && sr.getResult().equals(sr2.getResult())
  95. && Arrays.equals(sr.getShape(), sr2.getShape());
  96. }
  97. else if(recipe instanceof FurnaceRecipe && other instanceof FurnaceRecipe) {
  98. FurnaceRecipe fr = (FurnaceRecipe) recipe;
  99. FurnaceRecipe fr2 = (FurnaceRecipe) other;
  100.  
  101. return fr.getExperience() == fr2.getExperience()
  102. && fr.getInput().equals(fr2.getInput())
  103. && fr.getResult().equals(fr2.getResult());
  104. }
  105. else if(recipe instanceof MerchantRecipe && other instanceof MerchantRecipe) {
  106. MerchantRecipe mr = (MerchantRecipe) recipe;
  107. MerchantRecipe mr2 = (MerchantRecipe) other;
  108.  
  109. return mr.getIngredients().equals(mr2.getIngredients())
  110. && mr.getMaxUses() == mr2.getMaxUses()
  111. && mr.getUses() == mr2.getUses()
  112. && mr.getResult().equals(mr2.getResult());
  113. }
  114.  
  115. return recipe.getResult().equals(other.getResult());
  116. }
  117.  
  118. @EventHandler
  119. public void onjoin(PlayerJoinEvent e){
  120.  
  121. ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
  122. ItemMeta ambrem = ambre.getItemMeta();
  123. ambrem.setDisplayName("§6§lAmbre");
  124. ambre.setItemMeta(ambrem);
  125.  
  126. ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
  127. ItemMeta topazem = topaze.getItemMeta();
  128. topazem.setDisplayName("§c§lTopaze");
  129. topazem.addEnchant(Enchantment.DURABILITY, 1, true);
  130. topaze.setItemMeta(topazem);
  131.  
  132. ItemStack platine = new ItemStack(Material.NETHER_STAR);
  133. ItemMeta platinem = platine.getItemMeta();
  134. platinem.setDisplayName("§4§lPlatine");
  135. platine.setItemMeta(platinem);
  136.  
  137. e.getPlayer().getInventory().addItem(ambre);
  138. e.getPlayer().getInventory().addItem(platine);
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement