Solved Custom Plugin Enabling but not working

Discussion in 'Spigot Plugin Help' started by ADuvall13, Oct 18, 2020 at 4:53 PM.

  1. Hi!

    First time posting to this forum.

    I copied (below) this generic plugin code as a starter. I've been able to have it enabled in my server but what I expect to happen is not happening. My concern is I'm not using "onEnable and onDisable" like most people are but the code I copied didn't use that. What is my issue? Please and thank you for the input.

    ISSUE:

    Main.java
    ------------------------------------------------------------------------------
    package io.github.ADuvall13;

    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin{

    @EventHandler
    public void CreatureSpawn(CreatureSpawnEvent event) {

    if(event.getEntityType() == EntityType.CREEPER)

    {
    Creeper creeper = (Creeper) event.getEntity();
    creeper.setPowered(true);
    }

    }

    }
    ------------------------------------------------------------------------------


    plugin.yml
    ------------------------------------------------------------------------------
    name: Main
    main: io.github.ADuvall13.Main
    version: 1.0.0
    api-version: 1.16
    commands:
    ------------------------------------------------------------------------------

    Warnings/Errors after compile
    View attachment 562521

    View attachment 562522

    /reload on server
    View attachment 562520
     
  2. SteelPhoenix

    Moderator

    You never register your listener (and your class does not implement Listener)
     
  3. You have to register this class since it is a listener

    Change:
    Code (Java):
    public class Main extends JavaPlugin{
    To:
    Code (Java):
    public class Main extends JavaPlugin implements Listener {
    And add this:
    Code (Text):
    public void onEnable() {
          Bukkit.getPluginManager().registerEvents(this, this);
    }
     
  4. Thank you! It is working now.