BlockBreakEvent Error

Discussion in 'Spigot Plugin Help' started by Eptix, May 22, 2016.

  1. Code (Text):
    [15:47:27 ERROR]: Could not pass event BlockBreakEvent to Free_For_All v1.3.7
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PlayerInteractManager.breakBlock(PlayerInteractManager.java:285) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PlayerInteractManager.a(PlayerInteractManager.java:121) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:585) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:40) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PacketPlayInBlockDig.a(SourceFile:10) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-e8c6403]
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_91]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:676) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [craftbukkit.jar:git-Bukkit-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [craftbukkit.jar:git-Bukkit-e8c6403]
            at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.validate(CraftScheduler.java:395) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:123) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:119) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.scheduleSyncDelayedTask(CraftScheduler.java:102) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            at de.eptix.freeforall.MapReset.onBreak(MapReset.java:29) ~[?:?]
            at sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-e8c6403]
            ... 17 more
     
    My Code:

    Code (Text):
    package de.eptix.freeforall;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;

    public class MapReset implements Listener {
       
        private main plugin;
        private HashMap<Integer, String> broken = new HashMap<>();
        private int currentBlock = 0;
        private int current = 0;
       
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
           
            Player p = e.getPlayer();
            Block b = e.getBlock();
           
            broken.put(current, b.getLocation().getBlockX() + ";" + b.getLocation().getBlockY() + ";" + b.getLocation().getBlockZ() + ";" + b.getTypeId() + ";" + b.getData());
            current++;
           
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
               
                @Override
                public void run() {
                    String[] array = broken.get(currentBlock).split(";");
                    int x = Integer.valueOf(array[0]);
                    int y = Integer.valueOf(array[1]);
                    int z = Integer.valueOf(array[2]);
                    int id = Integer.valueOf(array[3]);
                    byte data = Byte.valueOf(array[4]);
                   
                    Location loc = new Location(Bukkit.getWorld("world"), x, y, z);
                    loc.getBlock().setTypeId(id);
                    loc.getBlock().setData(data);
                    currentBlock++;
                }
            }, 20);
        }

    }
     
     
  2. Main / setting manager class? But it looks like "plugin" is improperly defined
     
  3. Code (Text):
    package de.eptix.freeforall;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;

    public class main extends JavaPlugin {
       
        @Override
        public void onEnable() {
            System.out.println("[FFA] Free For All v1.0 | aktiviert.");
           
            Bukkit.getPluginManager().registerEvents(new onJoin (), this);
            Bukkit.getPluginManager().registerEvents(new onQuit (), this);
            Bukkit.getPluginManager().registerEvents(new onKill (), this);
            Bukkit.getPluginManager().registerEvents(new MapReset (), this);
            Bukkit.getPluginManager().registerEvents(new Commands (), this);
            getCommand("gameinfo").setExecutor(new Commands());
            getCommand("clean").setExecutor(new Commands());
        }

        @Override
        public void onDisable() {
            System.out.println("[FFA] Free For All v1.0 | deaktiviert.");
        }

    }
     
     
  4. You don't have a constructor.
    At the top of your listener class, you will need to put:
    Code (Java):
    public MapReset(main pl) {
       plugin = pl;
    }
    and when you call the listener, you will need to use the following:
    Code (Java):
    Bukkit.getPluginManager().registerEvents(new MapReset (this), this);
    Edit: Take a look at these to learn more about constructors:
    https://bukkit.org/threads/beginner-constructors-wip.100772/

    http://www.javatpoint.com/constructor
    http://www.homeandlearn.co.uk/java/class_constructor.html