[1.5.1] Custom Scoreboards

Discussion in 'Resources' started by Tzeentchful, Mar 16, 2013.

Thread Status:
Not open for further replies.
  1. Well but players don't keep MetaData when they go to another server ^^

    I'm currently trying to do exactly this.


    Edit:
    Well I am able to add/remove scoreboards now and if a player joins the server with the SC, goes to another server which has my plugin which removes the SC and then goes back to the server with the SC it works fine. But now the client crashes when the server tries to remove the scoreboard when the players don't have a scoreboard. A simple check would help a lot now. Maybe there are other solutions...
     
  2. Offline

    TheUpdater

    plz tell how to add this i cant get it to work it only tells me to do new classes
     
  3. Offline

    Tzeentchful

    "it only tells me to do new classes"???
    I have no idea what you are on about.
    And I told you before, if you can't understand how to implement this then you should't be messing with this sort of stuff.
     
    devilquak and CreeperShift like this.
  4. Offline

    TheUpdater

    i want it on my server omg!

    When i add those!
    and hold mouse over all i can do is make new classes!

    why cant you be nice and just post sorce!
     
  5. Offline

    Tzeentchful

    TheUpdater
    "and hold mouse over all i can do is make new classes!"
    Im assuming that your building against bukkit this requies acces to NMS code so you must build against craftbukkit.
    You would know this if you read the main post.

    "why cant you be nice and just post sorce!"
    Again your making no sense and all the code you need is in the main post.
     
  6. Offline

    TheUpdater

    how to build against Craftbukkit?
     
  7. Offline

    devilquak

    I suggest you learn some more Java, and understand what exactly most this thread is about.
     
  8. Offline

    TheUpdater

    wtf why cant you just tell?
     
  9. Offline

    devilquak

    Mainly because what you're saying is making no sense, and there's nothing to "tell". You seem to be misinterpreting everything in this thread, so you should become more familiar with Java before trying to delve into this stuff.
     
  10. Offline

    CreeperShift

    If we tell you "do x" you will just come back with:
    "now I got this, how do I y?"

    and we will tell you how to do y,

    and again you will now ask how to do z?

    In the end, we could just write the plugin for you.

    If you can't understand:

    Build against craftbukkit
    and then look at the source posted in the first post to figure it out

    please don't ask us to provide anything more ;)
     
    devilquak likes this.
  11. Offline

    TheUpdater

    all i need to know is how to build against craftbukkit
    then i will continue
     
  12. Offline

    CreeperShift

    How? How?
    WHAT??

    How do you build against Bukkit???
     
  13. Offline

    TheUpdater

    can you just say -.-
     
  14. Offline

    CreeperShift

    You say you know how to do the rest, yet you don't even know how to "build against something".

    I will ask you again, for a normal plugin you build against bukkit, right? Still following me here? Still know what I'm saying? Still understand it?

    Good!

    Now, let's say we want to build against CraftBukkit instead, WHAT DO WE DO ? :O

    1. Dark Ritual including sacrifices
    2. Summon dark spirit and force him to code the plugin for you
    3. Maybe use our brain and figure out how to do it ourselves with the information provided above?

    I'd go with 1 personally, but it's your choice.
     
  15. Offline

    stuntguy3000

    I would go with 1 also.
     
  16. Offline

    Tzeentchful

  17. Offline

    CreeperShift

  18. Offline

    devilquak

  19. Offline

    TheUpdater

    ok well i get that now export the project whit errors thing but the scoreBoard it wont show up?!
    Code:
    package addons;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.avaje.ebeaninternal.server.cluster.Packet;
     
    import me.champions.*;
     
    public class Scoreboard extends JavaPlugin implements Listener{
            public Scoreboard() { 
            }
            public Scoreboard(championsMain championsMain) {
                Bukkit.broadcastMessage("HELLYEAH");
            }
            public void test(final Player player) {
                getServer().getScheduler().runTask(this, new Runnable() {
     
                    @Override
                    public void run() {
                        String name = "Test";
                     
                        Scoreboard sb = new Scoreboard();
                        sb.registerObjective(name, new ScoreBoardBaseCriteria(name));
                     
                        Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.getObjective(name), 0);
                        Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1, sb.getObjective(name));
                     
                        sendPacket(player, packet);//Send Scoreboard create packet
                        sendPacket(player, display);//Send the display packet
                     
                        ScoreboardScore scoreItem1 = sb.getPlayerScoreForObjective("Answer to life", sb.getObjective(name));//Create a new item
                        ScoreboardScore scoreItem2 = sb.getPlayerScoreForObjective("4 * 4", sb.getObjective(name));//Create a new item
                        scoreItem1.setScore(42);//Set it's value to 42
                        scoreItem2.setScore(12);//Set it's value to 12
                     
                        Packet207SetScoreboardScore pScoreItem1 = new Packet207SetScoreboardScore(scoreItem1, 0);//Create score packet 1
                        Packet207SetScoreboardScore pScoreItem2 = new Packet207SetScoreboardScore(scoreItem2, 0);//Create score packet 2
                        sendPacket(player, pScoreItem1);//Send score update packet
                        sendPacket(player, pScoreItem2);//Send score update packet
                     
                    }
                     
                });
                     
            }
            public static void sendPacket(Player player, Packet packet) {
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); 
            }
        }
    reply
    to wrong guy lol sy read above

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  20. Offline

    devilquak

    TheUpdater

    I don't think you understand. You appear to have very little, if not any knowledge of Java whatsoever. This is relatively complicated stuff, even for most developers on Bukkit. Like multiple people have already stated, we beg you to go through a few Java tutorials before attempting to mess with scoreboards.
     
    techboy291 and CreeperShift like this.
  21. Offline

    chriztopia

    Ok I have created the scoreboard and it displays my info correctly... now I am trying to figure out how to update that information.

    Code:
    public static void sendPacket(Player player, Packet packet) {
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
     
     
    @EventHandler(priority = EventPriority.HIGH)
    public void onPlayerJoin(PlayerJoinEvent event){
       
     
       
        String username1 = event.getPlayer().getName();
     
        int pk = Integer.valueOf(plugin.getPlaytimepk(username1));
        int hk = Integer.valueOf(plugin.getPlaytimehk(username1));
        int fk = Integer.valueOf(plugin.getPlaytimefk(username1));
            Player player = event.getPlayer();
               
            String name = "TimeRank Kills";
            Scoreboard sb = new Scoreboard();//Create new scoreboard
            sb.registerObjective(name, new ScoreboardBaseCriteria(name));//Create new objective in the scoreboard
            Packet206SetScoreboardObjective packet = new Packet206SetScoreboardObjective(sb.getObjective(name), 0);//Create Scoreboard create packet
            Packet208SetScoreboardDisplayObjective display = new Packet208SetScoreboardDisplayObjective(1, sb.getObjective(name));//Create display packet set to sidebar mode
            sendPacket(player, packet);//Send Scoreboard create packet
            sendPacket(player, display);//Send the display packet
            ScoreboardScore hkills = sb.getPlayerScoreForObjective("Hostile Kills", sb.getObjective(name));//Create a new item
            ScoreboardScore pkills = sb.getPlayerScoreForObjective("Player Kills", sb.getObjective(name));//Create a new item
            ScoreboardScore fkills = sb.getPlayerScoreForObjective("Friendly Kills", sb.getObjective(name));//Create a new item
           
            hkills.setScore(hk);//Set it's value to 0
            fkills.setScore(fk);//Set it's value to 0
            pkills.setScore(pk);//Set it's value to 0
           
            Packet207SetScoreboardScore pKills = new Packet207SetScoreboardScore(pkills, 0);//Create score packet 1
            Packet207SetScoreboardScore hKills = new Packet207SetScoreboardScore(hkills, 0);//Create score packet 1
            Packet207SetScoreboardScore fKills = new Packet207SetScoreboardScore(fkills, 0);//Create score packet 1
           
            sendPacket(player, pKills);//Send score update packet
            sendPacket(player, fKills);//Send score update packet
            sendPacket(player, hKills);//Send score update packet
     
     
    }
     
  22. You can find out EVERYTHING here:



    And if you do not then just start with easier stuff. I don't get why we shall explain it when Tzeentchful already did it perfect.
     
  23. Offline

    TheUpdater


    ok 1 thing, is build aginst bukkit running plugin whit errors?
     
  24. Offline

    CreeperShift

    Build aginst spelchek wil produze errors sir!

    I don't know whats so fucking hard about the part that you need BASIC Java knowledge to even attempt this.

    If you can't understand that IF YOU DO IT RIGHT IT WONT PRODUCE ERRORS and simply build against Craftbukkit, not Bukkit like you normally do, just don't attempt this.


    Let me give you a few more hints (Note, by now even a monkey with disabilities would have figured it out):

    What is the first thing you do when you start a new project?
    You add Bukkit (The API) right? right? right? right? Do you? Do you?

    Story time:

    What does Bukkit (The API) not contain? Yes, the charming sir in the first row.
    "MineCraft server code."

    "But, but", says the disabled monkey in the second row, "We need MineCraft server code because Bukkit has not yet created an API for it!"

    "Absolutely, we need to use server code, so instead of using Bukkit, we will use both it and Craftbukkit, because what does Craftbukkit contain?"

    "MineCraft server code!", again from the charming sir in the first row, dang! Just look at that tie!

    "So now, we use both Bukkit and Craftbukkit in our project, what do you think WONT happen now?"

    "Compiling errors" whispers the monkey.
    And before you know it, you wake up, still completely stoned, because really monkeys can't talk. What's wrong with you!
     
  25. Any ideas?
     
  26. Offline

    TheUpdater

    lol its both bukkit and craftbukkit -.- why dident you post this befor
     
  27. Offline

    CreeperShift

    I may be a bit confused here, but is this basically your problem:

    Servers are connected, Player Steve has a Scoreboard on Server A, moves to Server B and it gets removed. No crash.
    Player Peter has no Scoreboard on Server A, moves to Server B. Server B tries to remove the Scoreboard, Peter crashes.

    Am I understanding this right?

    Would it be possible to simply ALWAYS add the scoreboard before they move to server B? So that way, they never crash when it gets removed? Even if the Scoreboard is just a dummy scoreboard that doesn't actually do anything? Just a thought.

    Or instead, remove the Scoreboard on Server A when they try to leave, instead of when they Arrive at Server B. I'm guessing you keep track of who has a Scoreboard on Server A anyways, right?

    Just some ideas I'm tossing around, might be worth trying out ;)


    We did, like 20 times. No, make that 40 times.
     

  28. Yep exactly this problem.
    The client crashs when:
    - Player has Scoreboard and server sends it again
    - Player has no Scoreboard and server tries to remove it

    And it's not possible to send packets to the player when he leaves the server because then he already lost the connection.



    "Would it be possible to simply ALWAYS add the scoreboard before they move to server B? So that way, they never crash when it gets removed? Even if the Scoreboard is just a dummy scoreboard that doesn't actually do anything? Just a thought."


    Let's say Steve connects to server C first which has no Scoreboard and then goes to B -> crash. There's always the problem that it is possible that a player closes his client and then joins a server WITHOUT Scoreboard and the possibility that the player already has a Scoreboard and switches the server then.


    "Or instead, remove the Scoreboard on Server A when they try to leave, instead of when they Arrive at Server B. I'm guessing you keep track of who has a Scoreboard on Server A anyways, right?

    Just some ideas I'm tossing around, might be worth trying out ;)"


    Sadly it's not possible to send packets to the player when he leaves a server.
    Currently I just see two ways:
    1. BungeeCord removes Scoreboards when it detects server switch
    2. A way to check if the player has a Scoreboard etc.
     
  29. Offline

    CreeperShift

    black_ixx

    Ah, so there are more than 2 servers! That makes things more complicated for sure :p

    I'm not sure how bungeecord works, could you elaborate on that a little bit? Is it like a command that you type to switch servers? Do you go through a portal?

    If so, could you not detect that and remove the scoreboard just before they leave?

    I'm guessing if there is no way to check if a player has a scoreboard, then you will probably have to either remove it on the Server that added it or get bungeecord to remove it (again, I'm not entirely sure what/how bungeecord works, I've heard about it but it's nothing I have ever used).

    A really idiot proof solution would be to use a mysql database where all the servers are connected and check if a player logged out with a scoreboard, then remove it only for that player. But yeah, lot's of work for such a little task >_<.

    EDIT: Wait, does bungeeCord not allow you to check from WHICH server the player came from?
     

  30. BungeeCord is a proxy and works like this:
    It's config contains a list of server ips and one main server.
    A player joins the "BungeeCord" server.
    Now BungeeCord creates a virtual player with the name of the player who joined the server.
    It joins the ip of the main server with this player. All the packet this player gets are sent to the real player.
    Now the player can interact and do stuff. All this data of the player is sent to BungeeCord which sends it to the server (in form of the virtual player).

    To switch a server players can enter portals (and yes I could remove the Scoreboard there) OR with a simple command. The problem is, that this command is not detected by the server because BungeeCord doesn't sends it to the server. It just disconnects the virtual player, joins the new server and transmits the packets there.

    Maybe it's possible to remove the switch-server command and add a new one which works through the server...
     
Thread Status:
Not open for further replies.

Share This Page