My Scoreboard Tablist plugin doesn't work properly

Discussion in 'Plugin Development' started by TheSpigotGirl, May 23, 2021.

  1. Offline

    TheSpigotGirl

    Hi Guys,

    I'm currently programming a Minecraft Tablist Scoreboard Plugin and need a little help.

    Actually everything works as it should and there is no error message. But if another player enters the server, my player name will be reset to the default prefix and set over the other player's name, which of course shouldn't be.

    I've tried a lot of variations in programming, but I can't find a solution to the problem. I also have my own scoreboard (sidebar) plugin in the plugin, which can cause possible complications, but (actually) this shouldn't be the case.

    Here is the code:

    My Scoreboard Tablist problem (code) - Pastebin.com
     
  2. Offline

    Shqep

    Reformatted and on a website that has color formatting (next time please use NOT pastebin but hatebin, hatsebin or even github gists):
    Main class
    Tablist class

    Scoreboards are known to cause a lot of incompatibility issues. If possible, you are usually advised to keep one and only one scoreboard plugin on a server.
    Oh my, this is a very difficult topic to tackle on.

    @TheSpigotGirl
    I suspect that it gets overridden because you have 2 PlayerJoinEvent handlers in 2 different classes (Main and Tablist), trying to set new scoreboards. What I could recommend is by getting the player's active scoreboard if present, and using that scoreboard to mess with teams prefixes and stuff.

    If you decide to work with present scoreboards and not create new ones, make sure to check if the objective already exists with such name, whether the teams already exist before creating, as it will result in some sort of Exception.

    Another thing is that if each player has a different scoreboard, they won't see others' teams' prefixes. Everyone must have the same scoreboard. This is why multiple scoreboard plugins would cause incompatibility issues.

    Last thing is that you should try to join the 2 PlayerJoinEvent handlers together, so that it's much easier to see where the problem may be.

    There are a lot of weird things in your codes that I wanted to point out too (if you don't care, I mean, that's your choice I don't really care):
    Main (open)

    Line 22: System.out.println
    [​IMG]

    Line 26 - 28: Redundancy
    [​IMG]

    Line 71: Scoreboard Desync
    [​IMG]

    Hard-coding the color code symbol into your messages. I'd recommend using this over hard-coding the
    § sign or appending with ChatColor enums:
    [​IMG]

    I'm not going to touch on if-else-ifs and switch-cases since it's not very necessary, just makes it easier to maintain. If you want to clean up the if-else-ifs like others, look at switch-cases. I wouldn't say you try to optimize it right away, you can do it after you're done with the main features.
     
  3. Offline

    TheSpigotGirl

    Wow, thanks for all of your help!
    I am new to Java programming and will follow your tips.
    I will change it right now.

    Hii @Shqep
    ,
    I need your help again.
    I tried to fix this annoying problem (with your tips) myself, but unfortunately there is
    still an issue. This time, the console showed an error (something with "PlayerJoinEvent"),
    but It did not show the exact problem. (For example: The error line)
    I deleted the old Scoreboard and the second PlayerJoinEvent event (like you told me).
    I put the Tablist & Scoreboard (sidebar) in the main class below the
    PlayerJoinEvent which should not cause the problem, but I am not 100% sure.

    Here is the code:
    hatebin - mwumwbrknd

    The error message is below:


    [19:12:01 ERROR]: Could not pass event PlayerJoinEvent to FurnaceMC-SRP v1.5
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_271]
    Caused by: java.lang.IllegalArgumentException: An objective of name 'abcdef' already exists
    at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:31) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:1) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at de.all.main.Main.onJoin(Main.java:30) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_271]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    ... 14 more
    [19:12:01 INFO]: TheSpigotGirl[/127.0.0.1:61880] logged in with entity id 98 at ([world]-1316.5775607780804, 22.0, -361.42833221627654)
    [19:12:23 INFO]: User groups set!
    [19:12:26 INFO]: TheSpigot lost connection: Disconnected
    [19:12:26 INFO]: TheSpigot left the game
    [19:12:27 INFO]: UUID of player TheSpigot is d50b445e-a449-344e-9c56-2f94cedfaecc
    [19:12:27 ERROR]: Could not pass event PlayerJoinEvent to FurnaceMC-SRP v1.5
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_271]
    Caused by: java.lang.IllegalArgumentException: An objective of name 'abcdef' already exists
    at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:31) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:1) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at de.all.main.Main.onJoin(Main.java:30) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_271]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    ... 14 more
    [19:12:27 INFO]: TheSpigot[/127.0.0.1:61891] logged in with entity id 99 at ([world]-1319.4294284306493, 22.0, -340.07636075234325)
    [19:12:32 INFO]: TheSpigotGirl lost connection: Disconnected
    [19:12:32 INFO]: TheSpigotGirl left the game
    [19:12:33 INFO]: TheSpigot lost connection: Disconnected
    [19:12:33 INFO]: TheSpigot left the game
    [19:12:34 INFO]: UUID of player TheSpigot is d50b445e-a449-344e-9c56-2f94cedfaecc
    [19:12:34 ERROR]: Could not pass event PlayerJoinEvent to FurnaceMC-SRP v1.5
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-596221b-9a1fc1e]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_271]
    Caused by: java.lang.IllegalArgumentException: An objective of name 'abcdef' already exists
    at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:31) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:1) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at de.all.main.Main.onJoin(Main.java:30) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_271]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    ... 14 more

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2021
  4. Offline

    Shqep

    @TheSpigotGirl
    The best line to start looking for in your error message starts with "Caused by". From here you can see that it says:

    Code:
    Caused by: java.lang.IllegalArgumentException: An objective of name 'abcdef' already exists
    at org.apache.commons.lang.Validate.isTrue(Validate.java:136) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:31) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at org.bukkit.craftbukkit.v1_12_R1.scoreboard.CraftScoreboard.registerNewObjective(CraftScoreboard.java:1) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    at de.all.main.Main.onJoin(Main.java:30) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_271]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_271]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_271]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-596221b-9a1fc1e]
    The error is an instance of IllegalArgumentException, and the error message states that an objective with the name 'abcdef' already exists. This is why I told you to check whether the objective or the team exists, before creating it.
    When you navigate down the error stack, you look for the name of your class, here it is:
    at de.all.main.Main.onJoin(Main.java:30)
    So that means there's a statement (or an expression) at line 30 in file Main in package de.all.main, that is causing the error you see.
     
  5. Offline

    TheSpigotGirl

    @Shqep,
    Fortunately, I was able to fix a lot of problems (Thank you for helping me ),
    but the objective error right now might be a bit complicated.


    ["Caused by: java.lang.IllegalArgumentException: An objective of name 'Sidebar' already exists"]


    Usually, you can write anything you want in a string, because It will not affect your code at all.
    I have no other objective with the same name (Eclipse does not show me an issue).
    I checked my code more than 5 times and the error message has not changed yet.

    ["Objective obj = sb.registerNewObjective("Sidebar", "dummy");"]


    Do you have an idea why this is still wrong?

    Here is the code:
    hatebin - sfqmllndsv
     
  6. Offline

    Shqep

    I, uh, kinda need you to throw this mindset out of the window. Strings are objects too and they contribute to what your codes do. When you want to send a message, say "No permission." to a player, you can't just put "ashdaidaw" right?

    The IDE doesn't show you an issue because it doesn't know, simply. It doesn't know if this objective exists on Bukkit side yet. So it's your job to tell the code to check it.
    A simple null check would do just fine:
    Code:Java
    1. /// This returns the objective if it exists, null otherwise.
    2. final Objective o = sb.getObjective(name);
    3. if(o == null) {
    4. // Now you know it doesn't exist, create one!
    5. } else {
    6. // In this case, it does exist, so don't create another.
    7. }
     

Share This Page