[ERROR]Could not pass event BlockBrakeEvent

Discussion in 'Plugin Development' started by Typ, Aug 5, 2016.

Thread Status:
Not open for further replies.
  1. Hello,
    I've got a Problem: I wrote a plugin, which Counts all broken blocks of a Player and saves them into a YAML file. Now, after it worked about 6 hours, there's suddenly a error.
    Console (open)

    Code:
    05.08 16:47:16 [Server] INFO Caused by: java.lang.NullPointerException
    05.08 16:47:16 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_40]
    05.08 16:47:16 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_40]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:10) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:40) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:834) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.a(PlayerInteractManager.java:194) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:293) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:16 [Server] INFO org.bukkit.event.EventException
    05.08 16:47:16 [Server] ERROR Could not pass event BlockBreakEvent to Survival v1.0.0
    05.08 16:47:15 [Server] INFO Caused by: java.lang.NullPointerException
    05.08 16:47:15 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_40]
    05.08 16:47:15 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_40]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:10) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:40) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:834) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.a(PlayerInteractManager.java:194) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:293) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:15 [Server] INFO org.bukkit.event.EventException
    05.08 16:47:15 [Server] ERROR Could not pass event BlockBreakEvent to Survival v1.0.0
    05.08 16:47:14 [Server] INFO Caused by: java.lang.NullPointerException
    05.08 16:47:14 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_40]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_40]
    05.08 16:47:14 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_40]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:10) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PacketPlayInBlockDig.a(SourceFile:40) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:834) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.a(PlayerInteractManager.java:194) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at net.minecraft.server.v1_10_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:293) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.10.2.jar:git-Spigot-a9631d2-2239ff0]
    05.08 16:47:14 [Server] INFO org.bukkit.event.EventException
    05.08 16:47:14 [Server] ERROR Could not pass event BlockBreakEvent to Survival v1.0.0


    I don't know how to solve this. When you Need the Code, just tell me ;)

    Typ
     
  2. Offline

    MarinD99

    Post your code, there's no point in seeing the error without the initial code.
     
  3. Offline

    Zombie_Striker

  4. Ok, then here's the Code:
    Code:
    package net.Typ.Survival.Listener;
    
    import net.Typ.Survival.Survival;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    
    import java.io.File;
    import java.io.IOException;
    
    /**
    * Created by typ on 18.07.2016.
    */
    public class BlockBreakListener implements Listener
    {
        Survival plugin;
        Player p;
    
        // constructor
        public BlockBreakListener(Survival plugin)
        {
            this.plugin = plugin;
        }
    
        // Events
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e)
        {
            // variables
            this.p = (Player) e.getPlayer();
            boolean blocktype = false;
    
            // when player is no player, stop Event
            if(!(p instanceof Player))
            {
            }
            else
            {
                int ID = e.getBlock().getTypeId();
                String category = checkID(ID);
    
                addData(category);
            }
        }
    
        // add a new broken block to player
        private boolean addData(String dataType)
        {
            // load player-data
            // if file doesn't exist, create it
            File ordner = new File("plugins/Survival/data");
            File playerdatafile = new File("plugins/Survival/data/data.yml");
    
            if (!ordner.exists())
            {
                return false;
            }
    
            if (!playerdatafile.exists())
            {
                return false;
            }
    
            YamlConfiguration cfg = YamlConfiguration.loadConfiguration(playerdatafile);
    
            // check, if dataType equals sth avaible
            switch(dataType)
            {
                case "Baumaterial":
                case "Dekoration":
                case "Redstone";
                    int number = 0;                     // number of broken blocks of selected cathegory
    
                    // get mass of selected block cathegory
                    number = cfg.getInt(p.getName() + ".AbgebauteBlöcke." + dataType);
                    number = number + 1;
    
                    // set number
                    cfg.set(p.getName() + ".AbgebauteBlöcke." + dataType, number);
                    break;
                default:
                    return false;
            }
    
            try
            {
                cfg.save(playerdatafile);
            } catch (IOException e)
            {
                e.printStackTrace();
                return false;
            }
    
            return true;
        }
    
        // check, of what type the broken block is
        private String checkID(int ID)
        {
            /////////////////
            // Baumaterial //
            /////////////////
            if(Survival.baumaterial.contains(ID))
            {
                return "Baumaterial";
            }
    
            ////////////////
            // Dekoration //
            ////////////////
            if(Survival.dekoration.contains(ID))
            {
                return "Dekoration";
            }
    
            //////////////
            // redstone //
            //////////////
            if(Survival.redstone.contains(ID))
            {
                return "Redstone";
            }
    
            return null;
        }
    }
    I think the Problem could be the "return null;" in line 126. But I don't know why this should be the error?

    Is it that one or am I wrong?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    EDIT by me: edit button doesn't work directly after posting a code
     
    Last edited: Aug 6, 2016
  5. Offline

    Zombie_Striker

    Storing one global variable for a player is a very, very bad idea. If you need to pass the player from method to method, either pass it through the parameters of the method or create a Map to store the players.

    1. Remove the comments. It should be pretty easy to tell which if statements controls what is returned. Right now, it just seems like useless space
    2. Do not abuse static. remove the static from those arraylists, and just pass the instance of the class through the constructor.
    3. The words that are returned should be lower case (convention)
    4. It is a very bad idea to return null. The only times you should ever work with nulls are if you need to clear data or if you are creating a new variable.

    IDS are no longer supported. Use Materials instead.

    You forgot to add the breaks. That means that it will loop through all these cases.
     
  6. Thank you for your answer! So you think, if I Change the Things you told me, it will work again?

    And to the last Thing with the Brakes: This is Intension, because, there I want to check, if "dataType" is one of These Things.

    I will try that Things out and hope it will work
     
  7. Offline

    Zombie_Striker

    Did you mean intentional? If so, then you are missing the point. Breaks make sure you don't have to loop through every single option. Think of it this way: How can a string be both "Dekoration" and "Redstone"? How can one word be equal to two? It can't, so there is no reason to check if it is anything else if one option has already been selected.
     
Thread Status:
Not open for further replies.

Share This Page