Bukkit ShapelessRecipe Problem

Discussion in 'Plugin Development' started by Dasvin, Oct 8, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    Dasvin

    i have made a mistake in public void onEnable, i cant craft the item, but i cant find my mistake, probably around Shapeless Recipe

    also made an screenshot so you can see it in eclipse
    Code:
    package sueperkraefte;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    public class sueperkraefte extends JavaPlugin{
        @EventHandler
        public void onEvent (PlayerInteractEvent e,Player spieler, Location Location) {
          
          
            Location position = spieler.getLocation();
            Location position1 = spieler.getLocation();
            Location position2 = spieler.getLocation();
            Location position3 = spieler.getLocation();
          
            World welt = spieler.getWorld();
          
            double yStart = position.getY() + 6;
            double xStart = position1.getX() + 6;
            double yStart1 = position2.getY() - 6;
            double xStart1 = position3.getX() - 6;
          
            position.setX(yStart);
            position1.setX(xStart);
            position2.setX(xStart1);
            position2.setX(yStart1);
      
            ItemStack gegenstand = spieler.getInventory().getItemInMainHand();
            ItemMeta metaData = gegenstand.getItemMeta();
          
            if (e.getAction() == Action.LEFT_CLICK_AIR){
                if (metaData.getDisplayName().equals("MachtKristall")){
                    //if (e.getItem().getEnchantments() == Enchantment.LUCK(10){
                  
                    welt.strikeLightning(position);
                    welt.strikeLightning(position1);
                    welt.strikeLightning(position2);
                    welt.strikeLightning(position3);
                }
                }
            }
      
      
        public void onEnable(Player spieler, Listener listener) {
            ItemStack machtkristall = new ItemStack(Material.DIAMOND);
            ItemMeta metaData = machtkristall.getItemMeta();
            metaData.setDisplayName("Machtkristall");
            machtkristall.setItemMeta(metaData);
            machtkristall.addUnsafeEnchantment(Enchantment.LUCK, 10);
            Location position = spieler.getLocation();
            World welt = spieler.getWorld();
            
            ShapelessRecipe machtkristallRezept = new ShapelessRecipe(machtkristall);
          
            machtkristallRezept.addIngredient(Material.DIAMOND);
            machtkristallRezept.addIngredient(Material.NETHER_STAR);
          
            this.getServer().addRecipe(machtkristallRezept);
            
            PluginManager pluginManager = this.getServer().getPluginManager();
            pluginManager.registerEvents(listener, this);
            
        }
        public void onDisable() {
          
        }
      
    }
     

    Attached Files:

    Last edited by a moderator: Oct 9, 2021
  2. Online

    timtower Administrator Administrator Moderator

    @Dasvin onEnable does not use arguments.
     
  3. Offline

    Kars

    ^ what he said. This is why you should use @Override annotation on onEnable.
     
  4. Offline

    Dai_Kunai

    Ah so other than making it clear that it's overriding, @Override will also show you if you put the wrong arguments? I'm ngl I usually skip it but
     
  5. Online

    timtower Administrator Administrator Moderator

    @Dai_Kunai It needs to well, override, if it can't because of arguments then it will yell at your face for doing it wrong.
     
  6. Offline

    Enemesies

    Good to know
     
  7. Offline

    Dasvin

    Sorry guys it took me a while to respond, thank you for helping me, i have fixed the arguments know, but it stil doesnt work
    Code:
    public class sueperkraefte extends JavaPlugin{
       
        @Override
    
        public void onEnable() {
    
          
             ItemStack machtkristall = new ItemStack(Material.DIAMOND);
             ItemMeta metaData = machtkristall.getItemMeta();
             metaData.setDisplayName("Machtkristall");
             machtkristall.setItemMeta(metaData);
             machtkristall.addUnsafeEnchantment(Enchantment.LUCK, 10);
            
            ShapelessRecipe machtkristallRezept = new ShapelessRecipe(machtkristall); // HERE IS A PROBLEM BECAUSE IT IS DEPRECATED 
           
             machtkristallRezept.addIngredient(Material.DIAMOND);
             machtkristallRezept.addIngredient(Material.NETHER_STAR);
           
             this.getServer().addRecipe(machtkristallRezept);
             PluginManager pluginManager = this.getServer().getPluginManager();
            
             MachtkristallListener listener = new MachtkristallListener; // HERE IS PROBLEM BECAUSE IT WONT ACCEPT MACHTKRISTALL LISTENER AS A TYPE
            
             pluginManager.registerEvents(listener, this);
        }
       
       
       
       
        public void onDisable() {
           
        }
           
            @EventHandler
            public void onEvent (PlayerInteractEvent e,Player spieler, Location Location) {
               
               
                Location position = spieler.getLocation();
                Location position1 = spieler.getLocation();
                Location position2 = spieler.getLocation();
                Location position3 = spieler.getLocation();
               
                World welt = spieler.getWorld();
               
                double yStart = position.getY() + 6;
                double xStart = position1.getX() + 6;
                double yStart1 = position2.getY() - 6;
                double xStart1 = position3.getX() - 6;
               
                position.setX(yStart);
                position1.setX(xStart);
                position2.setX(xStart1);
                position2.setX(yStart1);
           
                ItemStack gegenstand = spieler.getInventory().getItemInMainHand();
                ItemMeta metaData = gegenstand.getItemMeta();
               
                if (e.getAction() == Action.LEFT_CLICK_AIR){
                    if (metaData.getDisplayName().equals("MachtKristall")){
                         //if (e.getItem().getEnchantments() == Enchantment.LUCK(10){
                       
                        welt.strikeLightning(position);
                        welt.strikeLightning(position1);
                        welt.strikeLightning(position2);
                        welt.strikeLightning(position3);
                    }
                    }
               
        }
       
    }
    
        
     
  8. Offline

    Kars

    @Dasvin your eventlistener class must implement Listener.
     
  9. Online

    timtower Administrator Administrator Moderator

    @Dasvin To add on Kars.
    Events only have a single variable, the event itself, not what you have there.
    And where is MachtkristallListener defined anyways?
     
    Kars likes this.
Thread Status:
Not open for further replies.

Share This Page