"plugin" is being returned as null

Discussion in 'Plugin Development' started by MavenDisrrpt, Aug 28, 2021.

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


    I think the issue is that I am referencing plugin incorrectly. To explain what I mean by plugin, here is an example of what I am trying to reference externally. I have tried to debug this myself but I am stumped, it's probably something obvious but I just need another pair of eyes. Thank you heaps in advanced.

    getServer().getPluginManager().registerEvents(new EventThing(), >> this <<) // where "this" is the plugin.
    Here is a overview of the file structure related to this post.

    -> App.java (main)

    -> Listeners

    -> Tasks

    Quick context of the project: when mine ore, ore change to bedrock, then after 5 seconds it changes back to the original ore.

    Here is the Listener for when the block is broken.

    import me.mavendisrrpt.App; // main file
    import me.mavendisrrpt.Tasks.RegenerateBlockTask;
    import a.bunch.of.bukkit.stuff
    public final class BlockBreakListener implements Listener {
        App plugin;
        public void onBlockBreak(BlockBreakEvent event) {
            this.plugin = plugin;
            Player player = event.getPlayer();
            Block block = event.getBlock();
            Material blockType = block.getType();
            switch (blockType) {
                case IRON_ORE:
                    player.getInventory().addItem(new ItemStack(Material.IRON_ORE, 1));
                    System.out.println(plugin); // returning NULL
                    // BukkitTask task = new RegenerateBlockTask(plugin, block).runTaskLater(plugin, 100L);
    Here is the main file

    package me.mavendisrrpt;
    import org.bukkit.plugin.java.JavaPlugin;
    import me.mavendisrrpt.Commands.TestCommand;
    import me.mavendisrrpt.Listeners.BlockRegen;
    public class App extends JavaPlugin {
        public void onEnable() {
            getCommand("test").setExecutor(new TestCommand());
            getServer().getPluginManager().registerEvents(new BlockBreakListener(), this);
        public void onDisable() {
            // potatoes are tasty
  2. Offline

    timtower Administrator Administrator Moderator

    @MavenDisrrpt And where did you initialize plugin in the BlockBreakListener?
    Add a constructor for it.
Thread Status:
Not open for further replies.

Share This Page