OvercastNetwork / SportBukkit

CraftBukkit and Bukkit modifications that improve stability and add new features
99 stars 84 forks source link

Custom TabList #118

Closed makindotcc closed 9 years ago

makindotcc commented 9 years ago

I want to send to the player a customized tablist. Here is my code

    static void setTab(Player p, String prefix, String msg, String suffix) {
        tab.add(msg);
        ((CraftPlayer) p).getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(msg, true, 1100));
        Scoreboard sb = Bukkit.getScoreboardManager().getMainScoreboard();

        Team t = sb.getTeam(msg) == null ? sb.registerNewTeam(msg) : sb.getTeam(msg);
        if (!(prefix == null)) {
            t.setPrefix(prefix);
        }
        if (!(suffix == null)) {
            t.setSuffix(suffix);
        }
        t.addPlayer(Bukkit.getOfflinePlayer(msg));
        p.setScoreboard(sb);
    }

The method Bukkit.getOfflinePlayer(String) returns a String, but SportBukkit don't supports it. Also Bukkit.getPlayer(String) returns null when they is offline.

What can I do now? Please help!

jedediah commented 9 years ago

Not sure what you mean.. getOfflinePlayer returns an OfflinePlayer, and it should work fine in SportBukkit AFAIK

makindotcc commented 9 years ago

But it doesn't work. I have an error in the console:

Caused by: java.lang.IllegalArgumentException: WARNING: OfflinePlayer lookups are blocking and unsupported in SportBukkit. Please either use online players or the new string methods.
jedediah commented 9 years ago

Right, we disabled the username lookups. Just add players to the team by username. Don't use OfflinePlayer.

tonybruess commented 9 years ago

We disabled getOfflinePlayer because it is blocking and will break your plugins. Just use strings.

makindotcc commented 9 years ago

Now it works! Thanks for help! :)

OrigamiDream commented 9 years ago

@Thefilippop1PL How did you fix??? please tell me how to fixed it!

makindotcc commented 9 years ago

I replaced team.addPlayer(player); with team.add(string);