Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private ShapelessRecipe plantRecipe;
- @Override
- public void onEnable() {
- ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta ambrem = ambre.getItemMeta();
- ambrem.setDisplayName("§6§lAmbre");
- ambre.setItemMeta(ambrem);
- ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta topazem = topaze.getItemMeta();
- topazem.setDisplayName("§c§lTopaze");
- topazem.addEnchant(Enchantment.DURABILITY, 1, true);
- topaze.setItemMeta(topazem);
- ItemStack platine = new ItemStack(Material.NETHER_STAR);
- ItemMeta platinem = platine.getItemMeta();
- platinem.setDisplayName("§4§lPlatine");
- platine.setItemMeta(platinem);
- plantRecipe = new ShapelessRecipe(topaze);
- plantRecipe.addIngredient(9, Material.DOUBLE_PLANT);
- Bukkit.addRecipe(plantRecipe);
- Bukkit.getPluginManager().registerEvents(this, this);
- }
- @EventHandler
- public void onPrepareCraft(PrepareItemCraftEvent e) {
- if(!(e.getRecipe() instanceof ShapelessRecipe))
- return;
- ShapelessRecipe recipe = (ShapelessRecipe) e.getRecipe();
- ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta ambrem = ambre.getItemMeta();
- ambrem.setDisplayName("§6§lAmbre");
- ambre.setItemMeta(ambrem);
- ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta topazem = topaze.getItemMeta();
- topazem.setDisplayName("§c§lTopaze");
- topazem.addEnchant(Enchantment.DURABILITY, 1, true);
- topaze.setItemMeta(topazem);
- ItemStack platine = new ItemStack(Material.NETHER_STAR);
- ItemMeta platinem = platine.getItemMeta();
- platinem.setDisplayName("§4§lPlatine");
- platine.setItemMeta(platinem);
- if(recipeEquals(recipe, plantRecipe)) {
- ItemStack plant = null;
- for(int i = 0; i < e.getInventory().getMatrix().length; i++) {
- if(e.getInventory().getMatrix()[i] != null
- && e.getInventory().getMatrix()[i].hasItemMeta()) {
- plant = e.getInventory().getMatrix()[i];
- }
- }
- if(plant == null)
- return;
- if(!plant.getItemMeta().hasDisplayName())
- return;
- if(plant.getItemMeta().getDisplayName().equals("§6§lAmbre"))
- e.getInventory().setResult(topaze);
- else if(plant.getItemMeta().getDisplayName().equals("§c§lTopaze"))
- e.getInventory().setResult(platine);
- else
- e.getInventory().setResult(null);
- }
- }
- private boolean recipeEquals(Recipe recipe, Recipe other) {
- if(recipe.equals(other))
- return true;
- if(recipe instanceof ShapelessRecipe && other instanceof ShapelessRecipe) {
- ShapelessRecipe sr = (ShapelessRecipe) recipe;
- ShapelessRecipe sr2 = (ShapelessRecipe) other;
- return sr.getIngredientList().equals(sr2.getIngredientList())
- && sr.getResult().equals(sr2.getResult());
- }
- else if(recipe instanceof ShapedRecipe && other instanceof ShapedRecipe) {
- ShapedRecipe sr = (ShapedRecipe) recipe;
- ShapedRecipe sr2 = (ShapedRecipe) other;
- return sr.getIngredientMap().equals(sr2.getIngredientMap())
- && sr.getResult().equals(sr2.getResult())
- && Arrays.equals(sr.getShape(), sr2.getShape());
- }
- else if(recipe instanceof FurnaceRecipe && other instanceof FurnaceRecipe) {
- FurnaceRecipe fr = (FurnaceRecipe) recipe;
- FurnaceRecipe fr2 = (FurnaceRecipe) other;
- return fr.getExperience() == fr2.getExperience()
- && fr.getInput().equals(fr2.getInput())
- && fr.getResult().equals(fr2.getResult());
- }
- else if(recipe instanceof MerchantRecipe && other instanceof MerchantRecipe) {
- MerchantRecipe mr = (MerchantRecipe) recipe;
- MerchantRecipe mr2 = (MerchantRecipe) other;
- return mr.getIngredients().equals(mr2.getIngredients())
- && mr.getMaxUses() == mr2.getMaxUses()
- && mr.getUses() == mr2.getUses()
- && mr.getResult().equals(mr2.getResult());
- }
- return recipe.getResult().equals(other.getResult());
- }
- @EventHandler
- public void onjoin(PlayerJoinEvent e){
- ItemStack ambre = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta ambrem = ambre.getItemMeta();
- ambrem.setDisplayName("§6§lAmbre");
- ambre.setItemMeta(ambrem);
- ItemStack topaze = new ItemStack(Material.DOUBLE_PLANT);
- ItemMeta topazem = topaze.getItemMeta();
- topazem.setDisplayName("§c§lTopaze");
- topazem.addEnchant(Enchantment.DURABILITY, 1, true);
- topaze.setItemMeta(topazem);
- ItemStack platine = new ItemStack(Material.NETHER_STAR);
- ItemMeta platinem = platine.getItemMeta();
- platinem.setDisplayName("§4§lPlatine");
- platine.setItemMeta(platinem);
- e.getPlayer().getInventory().addItem(ambre);
- e.getPlayer().getInventory().addItem(platine);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement