Spigot/Bukkit Errors

Discussion in 'Plugin Development' started by Electric Cosmos, Nov 9, 2022.

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

    Electric Cosmos

    When trying to load my plugin I get these errors:
    Code:
    Error: Could not find or load main class com.electric_cosmos.plugin.SpigotPlugin
    Caused by: java.lang.NoClassDefFoundError: org/bukkit/event/Listener
    I followed this on setting up my plugin: https://www.spigotmc.org/wiki/creating-a-blank-spigot-plugin-in-eclipse/

    And I was thinking about using falling blocks in my plugin ( )

    Here is my main class code:

    Code:
    package com.electric_cosmos.plugin;
    
    import org.bukkit.plugin.*;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.*;
    import org.bukkit.event.entity.*;
    import org.bukkit.block.*;
    
    public class SpigotPlugin extends JavaPlugin implements Listener {
        public static void main(String[] args) {
            System.out.println((float) -5 + (float) (Math.random() * ((5 - -5) + 1)));
        }
       
        public void onEnable() {
            PluginManager pm =getServer().getPluginManager();
            pm.registerEvents(new SpigotPlugin(), new SpigotPlugin());
        }
               
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent event) {
            for (Block b : event.blockList()) {
                float x = (float) -5 + (float) (Math.random() * ((5 - -5) + 1));
            }
        }
    }
    
    My "plugin.yml":

    Code:
    name: Test-Spigot
    main: "com.electric_cosmos.plugin.SpigotPlugin"
    version: "1.0-SNAPSHOT"
    api: "1.3"
    api-version: 1.3
    
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Electric Cosmos

    Yeah, I think I forgot that step, it works after I exported it
     
  4. Offline

    Strahan

    I don't see how.

    Code:
    pm.registerEvents(new SpigotPlugin(), new SpigotPlugin());
    That should crash your plugin with a "plugin already initialized" error. You cannot instantiate new instances of the class that extends JavaPlugin. If you want to register listeners for the main class, you just do:

    Code:
    pm.registerEvents(this, this);
    ...just like they do in the tutorial you said you watched ;)
     
Thread Status:
Not open for further replies.

Share This Page