Solved I cant load my plugin = org.bukkit.plugin.InvalidPluginException

Discussion in 'Plugin Development' started by Birdytrap, Jan 26, 2013.

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

    Birdytrap

    Every time I want to start up my plugin, I get this error. I searched on the web, but I cant get what I did wrong! Also, there are no errors in Eclipse.

    This is the error I get in the console:
    Console error (open)
    [SEVERE] Could not load 'plugins\Pipeweed_V0.1.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.InstantiationException
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.loadPlugins(CraftServer.java:239)
    at org.bukkit.craftbukkit.v1_4_6.CraftServer.<init>(CraftServer.java:217)
    at net.minecraft.server.v1_4_6.PlayerList.<init>(PlayerList.java:52)
    at net.minecraft.server.v1_4_6.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_4_6.DedicatedServer.init(DedicatedServer.java:104)
    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:399)
    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178)
    ... 9 more


    In the plugin, I have 2 classes, 1 listener and 1 plugin class.

    This is my Plugin code:
    Plugin (open)

    Code:
    package com.gmail.Birdytrap.Pipeweed;
     
     
    import java.util.List;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.gmail.Birdytrap.Pipeweed.PipeweedListener;
     
    public abstract class PipeweedPlugin extends JavaPlugin implements Runnable {
        public static String PipeLore = ChatColor.GOLD + "A pipe used to smoke pipewee.";
        PipeweedListener listener;
     
        ShapedRecipe recipePipe, recipePipeweed;
     
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(listener = new PipeweedListener(this), this);
         
     
            Bukkit.addRecipe(recipePipe = new ShapedRecipe(new ItemStack(Material.STICK, 1)).shape("  ","  #","@@@").setIngredient('@', Material.STICK).setIngredient('#', Material.WOOD));
            Bukkit.addRecipe(recipePipeweed = new ShapedRecipe(new ItemStack(Material.WHEAT, 1)).shape("@#@","#@#","@#@").setIngredient('@', Material.WHEAT).setIngredient('#', Material.SEEDS));
            Bukkit.getScheduler().runTaskTimer(this, this, 20, 20);
            getLogger().info(ChatColor.GOLD + "Pipweeed version 0.1 has been enabled");
    }
        @Override
        public void onDisable() {
            Bukkit.getScheduler().cancelTasks(this);
            getLogger().info(ChatColor.GOLD + "Pipeweed version 0.1 has been disabled");
        }
        public boolean playerHasPipeInHand(Player player) {
            return isPipe(player.getItemInHand());
        }
         
        public boolean isPipe(ItemStack stack) {
            if (stack != null) {
                List<String> lore = stack.getItemMeta().getLore();
                if (lore != null) {
                    if (lore.size() == 1) {
                            return lore.get(0).equals(PipeLore);
    }
                }
            }
            return false;
        }
    }
    


    This is the code im my Listener:
    Listener (open)

    Code:
    package com.gmail.Birdytrap.Pipeweed;
     
    import java.util.Arrays;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.PrepareItemCraftEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.CraftingInventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.Recipe;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
     
    import com.gmail.Birdytrap.Pipeweed.PipeweedPlugin;
    public class PipeweedListener implements Listener {
        private PipeweedPlugin plugin;
     
        public PipeweedListener(PipeweedPlugin plugin) {
            this.plugin = plugin;
        }
     
        @EventHandler
        public void onCraft(PrepareItemCraftEvent event) {
            CraftingInventory inv = event.getInventory();
            Recipe recipe = event.getRecipe();
         
            if (recipe instanceof ShapedRecipe) {
                ShapedRecipe sRecipe = (ShapedRecipe)recipe;
                if (recipeMatches(sRecipe, plugin.recipePipe)) {
                    ItemStack result = new ItemStack(Material.STICK);
                    ItemMeta meta = result.getItemMeta();
                    meta.setDisplayName(ChatColor.DARK_GREEN + "Pipe");
                    //Lore in the plugin file. This is for the public boolean.
                    meta.setLore(Arrays.asList(PipeweedPlugin.PipeLore));
                    //Enchantments. Durability for the glowing effect to show that this is the pipe.
                    meta.addEnchant(Enchantment.DURABILITY, 1, false);
                    result.setItemMeta(meta);
                 
                    inv.setResult(result);
                }
            }
            if (recipe instanceof ShapedRecipe) {
                ShapedRecipe sRecipe = (ShapedRecipe)recipe;
                if (recipeMatches(sRecipe, plugin.recipePipeweed)) {
                    ItemStack result = new ItemStack(Material.WHEAT);
                    ItemMeta meta = result.getItemMeta();
                    meta.setDisplayName(ChatColor.GREEN + "Longbottom Leaf");
                    meta.setLore(Arrays.asList(ChatColor.GOLD + "A common type of pipeweed"));
                    meta.addEnchant(Enchantment.DURABILITY, 1, false);
                    result.setItemMeta(meta);
                 
                    inv.setResult(result);
                }
            }
    }
        private boolean recipeMatches(ShapedRecipe recipe1, ShapedRecipe recipe2) {
            if (!recipe1.getResult().equals(recipe2.getResult())) return false;
            if (recipe1.getShape().length != recipe2.getShape().length) return false;
            for (int i=0; i<recipe1.getShape().length; i++) {
                if (recipe1.getShape()[i].length() != recipe2.getShape()[i].length()) return false;
            }
            return true;
        }
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
                if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
                    if (plugin.playerHasPipeInHand(player)) {
                     
                        player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 200);
                     
                        return;
                    }
                }
            }
    }
     
     
    


    I hope someone can help me, since I have put alot of time in this!

    Thanks in advance!
     
  2. Offline

    william9518

    Why are u using an abstract class?!?!?! Also, show me ur plugin.yml
     
  3. Offline

    Birdytrap

    Because without the abstract, I get a error :/

    Code:
    The type PipeweedPlugin must implement the inherited abstract method Runnable.run()
    Also my .yml is:

    name: Pipeweed
    version: 0.1
    main: com.gmail.Birdytrap.Pipeweed.PipeweedPlugin
    author: Birdytrap
    description: Test
     
  4. Offline

    raGan.

    lol. Remove 'abstract' and add run() method. If you want to schedule task then you must give it something to run.
     
  5. Offline

    william9518

    Why are u implementing runnable?!?!
     
  6. Do not add abstract to your plugins class definition. Add implementations for the missing methods eclipse is complaining about instead. Empty methods will be sufficient if you don't need them. Using eclipses quick fix for it will generate the missing methods automatically.
     
  7. Offline

    Birdytrap

    Oh, ok! Well thank you both! I fixed this error! I can finaly continue with my plugin!

    Thanks again!

    PS: Both of you get a cake ---> [cake]
     
  8. Offline

    william9518

    Yes! Nomnom... That cake tastes baad...
     
Thread Status:
Not open for further replies.

Share This Page