BlockIterator problems

Discussion in 'Plugin Development' started by Mr. Sandwich, May 17, 2016.

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

    Mr. Sandwich

    Code:
        public final Block getTarget(Player player, Integer range) {
            BlockIterator bi= new BlockIterator(player, range);
            Block lastBlock = bi.next();
            while (bi.hasNext()) {
                lastBlock = bi.next();
                if (lastBlock.getType() == Material.AIR)
                    continue;
                break;
            }
            return lastBlock;
        }
    
    I use this ^^^ to tp players to this block and it works but sometimes the console says a weird error log adn I dont know what it means, can someone tell me whats the problem?
    Code:
    [14:25:20 ERROR]: Could not pass event PlayerMoveEvent to Speedsters v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:607) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.PacketPlayInFlying.a(SourceFile:126) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:57) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_77]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_77]
            at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot.jar:git-Spigot-4af49dc-23da8b0]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
    Caused by: java.lang.IllegalStateException: Start block missed in BlockIterator
            at org.bukkit.util.BlockIterator.<init>(BlockIterator.java:170) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            at org.bukkit.util.BlockIterator.<init>(BlockIterator.java:233) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            at org.bukkit.util.BlockIterator.<init>(BlockIterator.java:268) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            at me.xXMrSandwichXx.Speedsters.Main.getTarget(Main.java:1479) ~[?:?]
            at me.xXMrSandwichXx.Speedsters.Main.onPlayerMove(Main.java:505) ~[?:?]
            at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-4af49dc-23da8b0]
            ... 15 more
    
     
  2. Offline

    I Al Istannen

  3. Offline

    Mr. Sandwich

  4. Offline

    I Al Istannen

    @Mr. Sandwich
    Just click on the link. Javadocs are a great help.
     
  5. Offline

    Mr. Sandwich

    Thanks but I prefer my method
     
  6. Offline

    I Al Istannen

    @Mr. Sandwich
    You are free to do. I don't know what the error is caused by, so good luck finding it out!

    Have a nice day :)
     
  7. Offline

    Zombie_Striker

    First, classes should not have more than a couple hundred lines. You should consider breaking up your one class into multiple other ones (E.g. A util class, event class, main class, ect.)

    Going back to your main problem, is this the line 1479? If not, post line 1479.
    As this error states, the block you are starting at does not exist. Although I do not know how to solve this issue, I would highly recommend using the Player#getTargetBlock(null, range); method instead. I recommend it because it is compact and should always work.
     
  8. Offline

    Mr. Sandwich

    when I use e.getPlayer().getTargetBlock(null, 3) it puts a red line under it and says: The method getTargetBlock(HashSet<Byte>, int) is ambiguous for the type Player


    EDIT: Also I dont know how to divide my class to a few classes
     
  9. Offline

    I Al Istannen

    @Mr. Sandwich
    Look at this:
    Also see here.
     
  10. Offline

    Mr. Sandwich

    I dont understand this I cant get it to work
     
  11. Offline

    I Al Istannen

    @Mr. Sandwich
    Well it isn't that complicated. Have you read the post I linked?
    getTargetBlock((Set<Material>) null, distance)
    is the correct way.
     
  12. Offline

    WolfMage1

    it honestly depends, I knew someone with 14k lines in a main class, that was the entire server though. and I know someone with even more. So, saying a class shouldn't have more than a couple of hundred lines is just bs imo.
     
    Last edited: May 20, 2016
  13. Offline

    I Al Istannen

    @WolfMage1
    He is right though. In oop languages you have the problem of the "God object". An object with way too much responsibilities. You normally want to extract functionality in different objects, which are then specialized and just communicate with each other through some kind of API. Makes it much more flexible, readable and maintainable. ("teile und herrrsche" ==> Divide-and-conquer? pattern)

    You can still have classes with lots of code, but it could often be split into different objects and create a better structure and more maintainable code. Not every time, but often.

    That being said, there are usecases for a God object (e.g. Microcontrollers, better performance), and you can also split the code too much with this technique, resulting in a bad structure too.
    Nonetheless this technique is often preferred.
     
    Last edited: May 20, 2016
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page