Solved Advanced Scoreboard

Discussion in 'Plugin Development' started by malikdbuseck, Jul 22, 2015.

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

    malikdbuseck

    So im trying to write a bit of code using scorebaords that updates whenever a player get killed or kills. Im not using the setscore method. I want it so it is right underneath like shown in the screenshot. But I want it so it updates instantly after an deathevent. Additionally I would like to make it so they do not have to log out to see the changes.

    [​IMG]
    Code: Scoreboard
    Code:
        public static Score CDEATH;
        public static Score CKILLS;
        public static Score CASSIST;
        public static Objective objective;
    
        public Scoreboard scoreboard(Player player) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            final Scoreboard board = manager.getNewScoreboard();
            objective = board.registerNewObjective("test", "dummy");
    
            UUID uuid = player.getUniqueId();
    
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    
            Score GAME = objective.getScore("§f§l        KITPVP");
            GAME.setScore(20);
    
            // ============================
    
            Score ART2 = objective.getScore("§7  ♦──────────♦");
            ART2.setScore(19);
    
            Score BLANK = objective.getScore("");
            BLANK.setScore(18);
    
            Score KIT = objective.getScore("§a§lKIT:");
            KIT.setScore(17);
    
            Score CURRENTKIT = objective.getScore("§fArcher");
            CURRENTKIT.setScore(16);
    
            // ============================
    
            Score ART = objective.getScore("§7─────♦");
            ART.setScore(15);
    
            Score RANK = objective.getScore("§a§lRANK:");
            RANK.setScore(14);
            Score CRANK = objective.getScore("§fMember");
            CRANK.setScore(13);
    
            // ============================
    
            Score ART3 = objective.getScore("§7─────♦ ");
            ART3.setScore(12);
    
            try {
                Statement statement = Main.c.createStatement();
                ResultSet res;
    
                res = statement
                        .executeQuery("SELECT * FROM playerdata WHERE uuid = '"
                                + uuid + "';");
                res.next();
    
                Score KILLS = objective.getScore("§a§lK:");
                KILLS.setScore(11);
                CKILLS = objective.getScore("§f" + res.getString("KILLS") + "");
                CKILLS.setScore(10);
    
                Score DEATH = objective.getScore("§a§lD:");
                DEATH.setScore(9);
    
                CDEATH = objective.getScore("§f" + res.getString("DEATHS") + " ");
                CDEATH.setScore(8);
    
                Score ASSIST = objective.getScore("§a§lA:");
                ASSIST.setScore(7);
    
                CASSIST = objective
                        .getScore("§f" + res.getString("ASSISTS") + "  ");
                CASSIST.setScore(6);
            } catch (Exception e) {
                e.printStackTrace();
            }

    Scoreboard Update:
    Code:
    public class ScoreUpdate implements Listener{
        public static Main plugin;
    
        public ScoreUpdate(Main plugin) {
            ScoreUpdate.plugin = plugin;
        }
     
        @EventHandler
        public void update(EntityDeathEvent event){
            //DEATH=================
            if(event.getEntity() instanceof Player){
                LivingEntity player = event.getEntity();
                UUID uuid = player.getUniqueId();
             
                try {
                    Statement statement = Main.c.createStatement();
                    ResultSet res;
                    res = statement
                            .executeQuery("SELECT * FROM playerdata WHERE uuid = '" + uuid + "';");
                    res.next();
                 
                    statement.executeUpdate("UPDATE playerdata SET DEATHS='" + (res.getInt("DEATHS")+1) + "' WHERE uuid='" + uuid + "'  ");
                 
                } catch (Exception e) {
                    e.printStackTrace();
                }
             
             
            }
        }
     
     
    }
     
  2. Offline

    Zombie_Striker

    @malikdbuseck
    to get a specific score you can do the following:
    A) loop through all the objects in the scoreboard and see if the name matches the score you want to change
    B)loop through all the objects and look at their score, each score represents the line it's one, so you look for the object with the right score.
     
  3. Offline

    malikdbuseck

    Still slightly confused. Whats happening right now in my code is it will update but the previous score still stay there and then they just interchange every second.Also how do i get it to update right away
     
  4. Offline

    Zombie_Striker

    @malikdbuseck
    I acutally looked at your code now and see many problems with it, but here are some that pertain to your problem:
    1. Why are you using MySQL? Using it for this plugin, like most other plugins that use MySQl, is just useless and takes up more memory.
    2. You are creating a new scoreboard for every time it updates. If the 'scoreboard' method gets called 100 times, a 100 scoreboards will flash on and off in the corner of your screen. Instead save the one instance of the scoreboard somewhere outside any method.
    3. When using MySQL statements, I would not recommend adding strings to a string ("String1"+"String2"), instead, create one string with question marks and set each question mark to their corresponding value.
     
Thread Status:
Not open for further replies.

Share This Page