Solved Main class pointer = null

Discussion in 'Plugin Development' started by ExDiggers, Jul 30, 2020.

  1. Offline

    ExDiggers

    I'm new to coding and am not that comfortable with NPEs and I wanted some help with my plugin, this is my code:
    Code:
    public class Scheduler {
    
        private OreGens oregens;
    
    
        public void SpawnBlock(Location loc, Material material, World world) {
            if(oregens == null) {
                Bukkit.broadcastMessage("NULLLLL");
            } else {
                Bukkit.broadcastMessage("NOT NULLLLLL");
            }
            Material block = loc.getBlock().getType();
            Location newLoc = loc.add(0, 1, 0);
            if(block.equals(Material.COAL_BLOCK)) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(oregens, new Runnable() {
                public void run() {
                    newLoc.getBlock().setType(Material.COAL_BLOCK);
                    }
                }, 50L);
            } else if (block.equals(Material.IRON_BLOCK)) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(oregens, new Runnable() {
                public void run() {
                    newLoc.getBlock().setType(Material.IRON_BLOCK);
                        }
                }, 50L);
            } else if (block.equals(Material.GOLD_BLOCK)) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(oregens, new Runnable() {
                public void run() {
                    newLoc.getBlock().setType(Material.GOLD_BLOCK);
                        }
                }, 50L);
            } else if (block.equals(Material.EMERALD_BLOCK)) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(oregens, new Runnable() {
                public void run() {
                    newLoc.getBlock().setType(Material.EMERALD_BLOCK);
                        }
                }, 50L);
            } else if (block.equals(Material.DIAMOND_BLOCK)) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(oregens, new Runnable() {
                public void run() {
                    newLoc.getBlock().setType(Material.DIAMOND_BLOCK);
                    Bukkit.broadcastMessage("diamond gen");
                        }
                    }, 50L);
            } else {
                Bukkit.broadcastMessage("not a gen apparently");
                return;
            }
        }
    }
    
    
    This is the error I get from console:
    
    
    [14:07:46] [Server thread/ERROR]: Could not pass event BlockPlaceEvent to OreGens v0.99
    org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callBlockPlaceEvent(CraftEventFactory.java:150) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.ItemStack.placeItem(ItemStack.java:207) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:505) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:953) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:37) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_251]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_251]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_251]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.validate(CraftScheduler.java:410) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:130) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:126) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:109) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.prismpvp.oregens.spawn.Scheduler.SpawnBlock(Scheduler.java:48) ~[?:?]
        at net.prismpvp.oregens.events.GenPlace.BlockPlace(GenPlace.java:65) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        ... 18 more
    
    
    
    Sorry for my incompetence.
     
  2. Offline

    CraftCreeper6

  3. Offline

    ExDiggers

    okay ty


    How do i go about fixing that?
     
    Last edited: Jul 30, 2020
  4. Offline

    CraftCreeper6

    @ExDiggers
    Give the class a constructor that takes in your main class (OreGens) and set it within the constructor.
     
  5. Offline

    ExDiggers

    Okay thanks!
     

Share This Page