My bukkit plugin won't load

2.8k views Asked by At

I'm relatively new to making bukkit plugins, and i have a basic understanding of java. My plugin won't work. From what i see on other forums, this is a common error but none of the solutions have worked.

Here is my error:

[16:18:19 ERROR]: Could not load 'plugins/MtgCraft.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.sporech.MagictgCraft'

My plugin.yml:

name: MtgCraft
main: me.sporech.MagictgCraft
version: 1.8
author: Sporech
description: A basic plugin

My code is:

package me.sporech;

import java.util.Set;

import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class MagictgCraft extends JavaPlugin {
    public static MagictgCraft plugin;

    @Override
    public void onEnable(){
        getLogger().info("this is the plugin doing it");
    }
    @Override
    public void onDisable(){

    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) {
            Player player = (Player) sender;
            player.sendMessage("Hello, " + player.getName() + "!");
            return true;
        }
        return false;
    }
    @EventHandler
    public void onPlayerInteractBlock(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        if (player.getItemInHand().getType() == Material.STICK) {
            player.getWorld().strikeLightning(player.getTargetBlock((Set<Material>) null, 200).getLocation());
        }
    }
}
1

There are 1 answers

4
Variadicism On

The error is with your plugin.yml, not your code. Ensure that the plugin.yml is included in the default package and is inside your jar after exporting/zipping it.

It says that your description is invalid ("InvalidDescriptionException"); it may be too short, but that is just a guess. If lengthening your description does not work, try following the description with a ">" and a line break, then writing the description on the next line preceded by at least 8 spaces as shown in the example below from one of my plugins:

description: >
             This super simple plugin has so many features your head may just implode.

The above works in my plugins, though honestly it should not be necessary. Still, it's worth a try.

EDIT:

For future readers who don't want to sift through comments, the problem here was that the plugin.yml was not included in the "src" folder or in the default package of the exported jar. Always make sure your plugin.yml is in your exported jar in the default package!