Use MySQL values on ScoreBoard

Discussion in 'Plugin Development' started by keeper317, Jan 1, 2015.

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

    keeper317

    I am trying to make a scoreboard with that shows a rank and coins with specific names. I want this:
    Name of Board
    &a(Player Name) 8
    7
    &aBank: 6
    &bCredits: (values from MySQL) 5
    &dTokens: (values from MySQL) 4
    3
    &aRank: (value from MySQL) 2

    My scoreboard code (open)

    Code:
    public static void statBoard(Player p)
        {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective obj = board.registerNewObjective("stats", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName(Main.boardname);
            Score un = obj.getScore(Bukkit.getOfflinePlayer("§a" + p.getName()));
            un.setScore(8);
            Score blank = obj.getScore(Bukkit.getOfflinePlayer(""));
            blank.setScore(7);
            Score Bank = obj.getScore(Bukkit.getOfflinePlayer("§aBank: "));
            Bank.setScore(6);
            Score credits = obj.getScore(Bukkit.getOfflinePlayer("§bCredits: " + [COLOR=#ff0000]MySQLManager.getCredits(p)[/COLOR]));
            credits.setScore(5);
            Score Tokens = obj.getScore(Bukkit.getOfflinePlayer("§dTokens: + [COLOR=#0000ff]MySQLManager.getTokens(p)[/COLOR]"));
            Tokens.setScore(4);
            Score blank1 = obj.getScore(Bukkit.getOfflinePlayer(""));
            blank1.setScore(3);
            Score Rank = obj.getScore(Bukkit.getOfflinePlayer("§aRank: " + [COLOR=#00ff00]MySQLManager.getRank(p)[/COLOR]));
            Rank.setScore(2);
            if(!Main.url.equalsIgnoreCase("ignore") && !Main.url.equalsIgnoreCase(""))
            {
                Score blank2 = obj.getScore(Bukkit.getOfflinePlayer(""));
                blank2.setScore(1);
                Score url = obj.getScore(Bukkit.getOfflinePlayer(Main.url));
                url.setScore(0);
            }
            p.setScoreboard(board);
        }

    MySQL Retrieval Code (open)

    Code:
    public String [COLOR=#00ff00]getRank[/COLOR](Player p) throws SQLException, ClassNotFoundException
        {
            String name = p.getUniqueId().toString();
            if(!this.db.checkConnection())
                this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM `niftyranks_users` WHERE `uuid`='" + name +"';");
            if(!rs.next())
                return null;
            return rs.getString("rank");
        }
        public String [COLOR=#ff0000]getCredits[/COLOR](Player p) throws SQLException, ClassNotFoundException
        {
            String name = p.getUniqueId().toString();
            if(!this.db.checkConnection())
                this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM `economy_balance` WHERE `uuid`='" + name +"'AND `currency_id`='" + 2 + "';");
            if(!rs.next())
                return null;
            return rs.getString("balance");
        }
        public String [COLOR=#0000ff]getTokens[/COLOR](Player p) throws SQLException, ClassNotFoundException
        {
            String userid = getUserID(p);
            if(!this.db.checkConnection())
                this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM `economy_balance` WHERE `username_id`='" + userid +"'AND `currency_id`='" + 1 + "';");
            if(!rs.next())
                return null;
            return rs.getString("balance");
        }
        public String getUserID(Player p) throws SQLException, ClassNotFoundException
        {
            String name = p.getUniqueId().toString();
            if(!this.db.checkConnection())
                this.db.openConnection();
            Statement statement = this.db.getConnection().createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM `economy_account` WHERE `uuid`='" + name +"';");
            if(!rs.next())
                return null;
            return rs.getString("id");
           
        }

    I need to get the values at the noted areas.
    Thanks for the help.
     
  2. Offline

    mythbusterma

    @keeper317

    Looks like lag. Why are you accessing a remote server and preforming a very expensive operation on the main thread of the server?
     
  3. Offline

    keeper317

    It is set up that way due to how I was taught. Also it is not lag as the problem is not in game. The problem is that the scoreboard looks for a static reference and the MySQL can not use a static variable.
     
  4. Offline

    mythbusterma

    @keeper317

    Well yes, there will be lag problems in the game if you continue to do it this way. Then stop making everything static? This has nothing to do with what MySQL can and cannot do.
     
  5. Offline

    keeper317

    its not by choice to make it static. and it makes no difference currently where i access sql from
     
  6. Offline

    mythbusterma

    @keeper317

    Why isn't it a choice? It seems like a choice to me.
     
    Eathuis and nverdier like this.
  7. Offline

    keeper317

    You are not being helpful anymore posts from you that only attack me and my intelligence will result in a report from me.
     
  8. Offline

    mythbusterma

    @keeper317

    At which point did I even IMPLY you were stupid? Also, most of the reason I haven't provided anything other than "stop abusing static/stop accessing SQL improperly" is that you haven't provided us with a clear description of the error, the entirety of the classes involved, and what the desired behaivour is.
     
  9. Offline

    Jadedcat

    He has not attacked you or insulted you.
     
Thread Status:
Not open for further replies.

Share This Page