Need help with Bukkit.getScheduler()

Discussion in 'Plugin Development' started by portalthree, Nov 21, 2020.

  1. Offline

    portalthree

    Hi! So i'm tryna make a quick plugin but i'm kinda bad at coding and i have this error

    Code:
    Could not pass event BlockPlaceEvent to UltimatesImproved v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callBlockPlaceEvent(CraftEventFactory.java:127) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.ItemStack.placeItem(ItemStack.java:158) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:503) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_271]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_271]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_271]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.validate(CraftScheduler.java:397) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:123) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.runTaskLater(CraftScheduler.java:106) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            at com.portalthree.ultimatesimproved.Events.EventListener.onBlockPlaced(EventListener.java:26) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271]
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_271]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_271]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_271]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
            ... 18 more
    Here's my EventListener

    Code:
    package com.portalthree.ultimatesimproved.Events;
    
    import com.portalthree.ultimatesimproved.UltimatesImproved;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.Plugin;
    
    import java.util.Set;
    
    public class EventListener implements Listener {
    
        @EventHandler
        public void onBlockPlaced(BlockPlaceEvent event){
            Material blockType = event.getBlock().getType();
            Player player = event.getPlayer();
    
            if(blockType == Material.ENDER_PORTAL_FRAME){
                event.setCancelled(true);
                player.getWorld().spawnEntity(player.getTargetBlock((Set<Material>) null, 200).getLocation(), EntityType.ENDER_CRYSTAL);
                Bukkit.getScheduler().runTaskLater((UltimatesImproved.getPlugin()), new Runnable() {
    
                    @Override
                    public void run() {
                        player.getWorld().strikeLightning(player.getTargetBlock((Set<Material>) null, 200).getLocation());
    
                    }
    
                }, 40L);
                }
            }
        }
    And my main class

    Code:
    package com.portalthree.ultimatesimproved;
    
    import com.portalthree.ultimatesimproved.Events.EventListener;
    import com.portalthree.ultimatesimproved.Items.ItemHandler;
    import com.portalthree.ultimatesimproved.commands.MageUlti;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class UltimatesImproved extends JavaPlugin {
        public static Plugin plugin;
    
        @Override
        public void onEnable() {
            getCommand("mage").setExecutor(new MageUlti());
            ItemHandler.init();
            getServer().getPluginManager().registerEvents(new EventListener(), this);
        }
    
        public static Plugin getPlugin() {
            return plugin;
        }
    
        @Override
        public void onDisable() { }
    
    }
    
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    portalthree

    How am i supposed to do that?
     
  4. Offline

    timtower Moderator Moderator

    @portalthree plugin = this
    in the first line of the onEnable
     
  5. Offline

    portalthree

Share This Page