Scoreboards updating laggs server down

Discussion in 'Plugin Development' started by Zandor300, Aug 20, 2014.

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

    Zandor300

    Hey, i have a really annoying problem...

    I've made a plugin that shows the balance of the player in a scoreboard... Everything works except when i "pop" (how i call it) another player. Then i get an error in the console and the server would lagg out... The server is running on my own pc with 32 gb of ram... In the run.bat it is set to 2 gb... But when i look at the taskmanager while the server laggs out, 31,9 out of 32 gb of ram is used...

    I can't seem to get this fixed...

    Error:
    Code:
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEvent(CraftEventFactory.java:98) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.callEntityDamageEvent(CraftEventFactory.java:407) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.event.CraftEventFactory.handleEntityDamageEvent(CraftEventFactory.java:434) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.EntityLiving.damageEntity(EntityLiving.java:658) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.EntityHuman.damageEntity(EntityHuman.java:746) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.EntityPlayer.damageEntity(EntityPlayer.java:452) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.EntityArrow.h(EntityArrow.java:231) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.World.entityJoinedWorld(World.java:1421) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.World.playerJoinedWorld(World.java:1402) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.World.tickEntities(World.java:1290) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.WorldServer.tickEntities(WorldServer.java:481) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:649) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
        at com.zandor300.hubessentials.utils.CustomScoreboard.updateScoreboard(CustomScoreboard.java:80) ~[?:?]
        at com.zandor300.hubessentials.listeners.players.PlayerAttack.onPlayerAttack(PlayerAttack.java:57) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        ... 19 more
    CustomScoreboard class: http://pastebin.com/60qQ4ZuV
    Crystal class: http://pastebin.com/6mVBpxvL
    onPlayerAttack:
    Code:java
    1. @EventHandler
    2. public void onPlayerAttack(EntityDamageByEntityEvent event) {
    3. if (!(event.getEntity() instanceof Player)) {
    4. event.setCancelled(true);
    5. return;
    6. }
    7. Player player = (Player) event.getEntity();
    8.  
    9. if (event.getDamager() instanceof Arrow) {
    10. final Arrow arrow = (Arrow) event.getDamager();
    11. if (!(arrow.getShooter() instanceof Player))
    12. return;
    13. Player damager = (Player) arrow.getShooter();
    14.  
    15. if (PvP.getPvP(player))
    16. return;
    17. if (PvP.getPvP(damager))
    18. return;
    19. if (!damager.canSee(player))
    20. return;
    21.  
    22. damager.hidePlayer(player);
    23. Popper.getPop(damager).addScore(1);
    24. for (CustomScoreboard scoreboard : CustomScoreboard
    25. .getAllScoreboards())
    26. scoreboard.updateScoreboard();
    27. player.playSound(player.getLocation(), Sound.ITEM_PICKUP, 1, 1);
    28.  
    29. arrow.remove();
    30.  
    31. Firework firework = (Firework) player.getWorld().spawn(
    32. player.getLocation(), Firework.class);
    33. FireworkMeta fireworkMeta = firework.getFireworkMeta();
    34. fireworkMeta.addEffect(FireworkEffect.builder().flicker(false)
    35. .trail(false).with(Type.BALL).withColor(Color.AQUA)
    36. .withFade(Color.BLUE).build());
    37. fireworkMeta.setPower(0);
    38. firework.setFireworkMeta(fireworkMeta);
    39.  
    40. damager.setLevel(Popper.getPop(damager).getScore());
    41.  
    42. } else if (PvP.getPvP(player) == false) {
    43. event.setCancelled(true);
    44. return;
    45. }
    46. }


    I hope someone can help me...

    -Zandor300
     
  2. Offline

    mine-care

    This is a null pointer exception meaning a variable is null,specifically in scoreboard class line 80

    Also why so many statics? And yes probably itis the get crystal returning null ;) use debug code and print out variables to see what is null and why

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  3. Offline

    Zandor300

    I know what is wrong but i dont know how to fix.
    But it does print the scoreboard with the balance...
     
  4. Offline

    mine-care

    Weird, have u tried the debug for alllll variables?

    PS OMG that's a kick backside pc! Are you even maxing it out ever?
    I have a amd fx8350 overclocked to 4.8 ghz 16 gb ram 2gb gpu (asus 7770 I belive) so untill now I'm 1/2 of your pc but I beat u on storage ;) 3x2tb hdd's and a 240gb ssd with the os also have u overclocked? In my case it "busts into Flames" when used too much! I need to get to water cooling,
    PPS I like ur profile photo
     
  5. Offline

    Zandor300

    Not all but most of it... Gonna debug them all in a hour... Ill get back to you with the results if i still cant fix it...

    When i play watchdogs my pc is very loud... But i dont use watercooling eather lolz

    I've made a command with this code:
    Code:java
    1. sender.sendMessage("getCrystal(): "
    2. + Crystal.getCrystal(args.getString(0)).toString());
    3. sender.sendMessage("getPlayer().getName(): "
    4. + Crystal.getCrystal(args.getString(0)).getPlayer().getName());
    5. sender.sendMessage("getBlance(): "
    6. + Crystal.getCrystal(args.getString(0)).getBalance());

    Output:
    Code:
    [19:07:51] [Server thread/INFO]: getCrystal(): com.zandor300.core.enums.Crystal@5cdfe82b
    [19:07:51] [Server thread/INFO]: getPlayer().getName(): Zandor300
    [19:07:51] [Server thread/INFO]: getBlance(): 30
    And that are all the variables in Crystal.class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    mine-care

    That's odd :-( I can't see what's wrong, when I get to my pc (~4 days) ill check it out codewise
     
  7. Offline

    Zandor300

    But there aren't any errors when a player joins becouse that's when i instanciate a new Crystal();
     
  8. Offline

    mine-care

    Ok, just to be sure I understand right, can you please give me a brief explanation of what this minigames it's about? What you wana do? What's crystals? You can also start a conversation with mew if you like it more ;)
     
  9. Offline

    Cycryl

    Zandor300
    make sure you only call the scoreboardmanager after the onEnable() in the main has been called... otherwise it can cause exceptions
     
  10. Offline

    Zandor300

    Then why is this guy creating the scoreboard inside the onEnable() method?
     
  11. Offline

    Cycryl

    Zandor300
    You can but if you do it at the beginning of the main class you can you will get an exception
     
  12. Offline

    Zandor300

    But i'm calling it when a player joins so that souldn't be the problem...

    Cycryl mine-care Still no suggestions? I'm pretty sure now, the problem is Crystal.class but i don't know why...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  13. Offline

    mythbusterma

    Zandor300

    Because, frankly, that guy is not only not qualified to program and certainly not qualified to teach others, but his is also a moron.

    That being said, there really isn't any reason why you can't create a scoreboard in onEnable(), other than you won't have any players to show it to.

    And seriously, we mean it, stop abusing statics.
     
  14. Offline

    Cycryl

    mythbusterma
    Since I am capable of using reflection and Packets in my plugins as well as the Bukkit API i wouldn't consider myself a bad coder.
    In case I wasn't clear again:
    YOU CANNOT INITIALIZE A SCOREBOARD BEFORE THE ONENABLE HAS BEEN CALLED.
    so you can initialize it in the onenable, bu NOT before that. Got it? nice.

    Zandor300
    now to you Zandor: Since the error occurred on line 80 of your Custom scoreboard you should check that line.
    It calls Crystal.getCrystal(player).getBalance();
    wich means that Crystal.getCrystal(player) must return null

    maybe try this:
    Code:java
    1.  
    2. public static Crystal getCrystal(String player) {
    3.  
    4. 30.
    5. for (Crystal crystal : allCrystals)
    6.  
    7. 31.
    8. if (crystal.getPlayer().getName()==player)
    9.  
    10. 32.
    11. return crystal;
    12.  
    13. 33.
    14. return null;
    15.  
    16. 34.
    17. }
    18.  
     
  15. Offline

    Zandor300

    I do it in my onEnable becouse when i just /reload it just shows it to the players allready in the server...

    What is a better way?

    I'm not even doing that...

    Doesn't change anything:
    Code:
    Caused by: java.lang.NullPointerException
        at com.zandor300.hubessentials.utils.CustomScoreboard.updateScoreboard(CustomScoreboard.java:80) ~[?:?]
        at com.zandor300.hubessentials.listeners.players.PlayerAttack.onPlayerAttack(PlayerAttack.java:57) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_11]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_11]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_11]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292)
        ... 20 more
    
     
    Cycryl likes this.
  16. Offline

    Cycryl

    Zandor300
    1. The Thing with the onenable was just there to tell mythbusterma what I meant. Your way of doing it is perfectly fine.
    2. Are you sure that the ArrayList<Crystel> contains the player?
    i am pretty sure ist not. Then the method Returns null and you get an exception.
    so make sure to put the player's Crystal in the ArrayList.
     
  17. Offline

    fireblast709

    Just because you know some tricks doesn't mean you can't be a bad programmer ;)
    Your argument is invalid as it can be. The ScoreboardManager is available after the first world has been loaded. If you aren't loading your plugin at STARTUP, it's perfectly fine to get it in the class body (though when you want to switch later, it's recommended to do it a tick after (or a 0 delay scheduled task) the onEnable was called). So either way, wrong :3
    Pass a main class reference through the constructor to both the scoreboard updater and Crystal, store their instance in the main class and add some getters. This way, from your updater class, you should be able to do something among the lines of
    Code:java
    1. Crystal = this.main.getCrystal().getCrystal(player)
    Also, if you reload, you should create new Crystal objects for every player that is online at the time of onEnable.
     
  18. Offline

    mythbusterma

    Cycryl

    I wasn't saying that about you, I was saying that about the video he linked (BCBlowz). Attacking other members of the forums like that is something I don't do.

    That being said, there's barely any reason to use reflection and introspection in Bukkit, instead you could try using an interface and different implementations in different Maven modules, as is the case with TagAPI and DhUtils.
     
  19. Offline

    Zandor300

    I don't know what you want to do with that... nvm But i think that will look odd...

    And i was already doing that at onEnable...
     
Thread Status:
Not open for further replies.

Share This Page