Guest User

Untitled

a guest
Dec 8th, 2019
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.youki300.eronyacore.listeners;
  2.  
  3. import fr.youki300.eronyacore.utils.ItemBuilder;
  4. import org.bukkit.Material;
  5. import org.bukkit.event.EventHandler;
  6. import org.bukkit.event.Listener;
  7. import org.bukkit.event.inventory.PrepareItemCraftEvent;
  8. import org.bukkit.inventory.CraftingInventory;
  9. import org.bukkit.inventory.ItemStack;
  10.  
  11. import java.util.HashMap;
  12.  
  13. public class ItemStackCrafting implements Listener {
  14.  
  15. ItemBuilder item1 = new ItemBuilder(Material.NAME_TAG).setName("§ePièce de craft classique");
  16.  
  17. @SuppressWarnings("serial")
  18. @EventHandler
  19. public void onPlayerCraftItem(PrepareItemCraftEvent e) {
  20.  
  21. if (e.getInventory().getMatrix().length < 9) {
  22. return;
  23. }
  24.  
  25. checkCraft(new ItemStack(Material.EMERALD_BLOCK),e.getInventory(), new HashMap<Integer, ItemStack>(){{
  26. put(4, item1.toItemStack());
  27. }});
  28. }
  29.  
  30. public void checkCraft(ItemStack result, CraftingInventory inv, HashMap<Integer, ItemStack> ingredients){
  31. ItemStack[] matrix = inv.getMatrix();
  32. for(int i = 0; i < 9; i++){
  33. if(ingredients.containsKey(i)){
  34. if(matrix[i] == null || !matrix[i].equals(ingredients.get(i))){
  35. return;
  36. }
  37. } else {
  38. if(matrix[i] != null){
  39. return;
  40. }
  41. }
  42. }
  43. inv.setResult(result);
  44. }
  45. }
RAW Paste Data