Refreshing MySQL (Multiple scoreboard values)

Discussion in 'Plugin Development' started by Eos, Aug 3, 2015.

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

    Eos

    I'm using Husky's lib and i'm trying to figure out how to refresh the mysql in x amount of seconds. I know this is possible but I have no clue how to actually do it.
     
    Last edited: Aug 3, 2015
  2. Offline

    mythbusterma

    @Eos

    Define "reload," also there's no reason to use someone else's "API" (and I use that in the most incredibly lose sense of that phrase). Just write your own code, it's faster and won't be awful.
     
  3. Offline

    Konato_K

    @Eos Why do you even need to "reload"?

    Edit: No, you're the one who wrong who assumes "reload" is properly defined for MySQL.
     
  4. Offline

    Eos

    Is refresh a better word? What i'm trying to do is refresh the mysql db and get the mysql results live after the refresh. Right now the only way to do that is reload & leave the server.
     
  5. Offline

    Konato_K

    @Eos I'm still not entirely sure what you want to do, but let's see if I understand.

    You have some data that may be changed in the database and you want to get it straight from there so any changes made take effect, right?

    Just "select" the information from the database then, if that's not what you want then explain further.
     
  6. Offline

    Eos

    @Konato_K
    Let me be in more in depth, so a player's balance is on the scoreboard money: {amount}. The money is stored in a mysql database. Whenever I type /money give {player} amount it gives them the money and it saves into a mysql database. The new value shows up on the mysql database but not the scoreboard. It only shows up on the scoreboard if I reload the server & leave the game and when I rejoin my new balance is there. What i'm trying to do is update the balance in real time instead of restarting the server everytime.
     
  7. Offline

    Gater12

    @Eos
    Create method to update a player's scoreboard with the new balance?
     
  8. Offline

    SuperOriginal

    Before you went calling people retarded you should've realized your initial wording made absolutely no sense.
     
  9. Offline

    Konato_K

    @Eos Get the player scoreboard and modify whatever needs to be modified there, no need to "refresh" MySQL since it has nothing to do with it.
     
  10. Offline

    mythbusterma

    I'm sorry, what makes you think that that is an appropriate response? It's not my fault you cannot communicate/don't understand how MySQL works.

    How about you learn some humility before you come asking for help.

    Also, if I'm so retarded, how can I figure out that the solution is to periodically poll the database and update your Scoreboard accordingly?
     
  11. Offline

    Lammazz

    @Eos I'm a little late to post to this but what you should do is just put into each of your methods that change a player's balance to make it also update the scoreboard of that player with the new value(s). I recommend only reading from the database when a player joins and store any information you may need locally and update it there. Then when the player leaves and if you want on an interval (in case of crashes etc.) set the values again so as to trade a little bit of memory from your server in return for less power from the mysql server. Also you have to remember that MySQL is a server not a file that you can easily read, you must constantly request for everything and incorrectly doing so can cause a lot of lag.
    @mythbusterma 's way would also work but if you have a server with many people this would cause long intervals where the mysql server is idle and then a few seconds where it is overloaded with multiple requests.

    If you already found a solution hopefully this post gave you some insight into reducing how much resources are being used.
     
  12. Offline

    Eos

    [​IMG]

    Any clue whats causing it?

    UserScoreboard.java
    Code:
        @EventHandler
        public void onQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                @Override
                public void run() {
                    try {
                        for (Player players : Bukkit.getOnlinePlayers()) {
                            PlayerScoreboard(p);
                            players.setScoreboard(plugin.board);
                        }
                    } catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }, 0, 10L);
    
        }
    Code:
        Core plugin;
        Objective obj;
    
        public  Colorize color = new Colorize();
        public UserScoreboard(Core p){
            this.plugin = p;
            Bukkit.getPluginManager().registerEvents(this, plugin);
            obj = plugin.board.registerNewObjective(name, "dummy");
    
        }
    Code:
     
    this.plugin = p;Bukkit.getPluginManager().registerEvents(this, plugin);obj = plugin.board.registerNewObjective(name, "dummy");}
    
    public void PlayerScoreboard(Player p) throws Exception {
    
    
            Bits bit = new Bits(plugin, p.getUniqueId());
    
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    
            plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                @Override
                public void run() {
                    String display = Colorize.style("nope.exe").toRainbow();
                    obj.setDisplayName(display);
    
                }
            }, 0, 2L);
    
    
                Score server = obj.getScore(ChatColor.LIGHT_PURPLE + "Server:");
                Score server2 = obj.getScore(ChatColor.WHITE + "NOPE.EXE "); // LOBBY
    
                Score bits = obj.getScore(ChatColor.GOLD + "Bits:");
                Score bits2 = obj.getScore(ChatColor.WHITE + "" + bit.getBits()); // Bits
    
                Score rank = obj.getScore(ChatColor.AQUA + "Rank:");
                Score rank2 = obj.getScore(ChatColor.WHITE + "None");
    
                Score website = obj.getScore(ChatColor.RED + "Website:");
                Score website2 = obj.getScore(ChatColor.WHITE + "http://nope.exe.com/");
    
    
    
                server.setScore(8);
                server2.setScore(7);
                bits.setScore(6);
                bits2.setScore(5);
                rank.setScore(4);
                rank2.setScore(3);
                website.setScore(2);
                website2.setScore(1);
    
    
    
            p.setScoreboard(plugin.board);
    
        }
     
  13. Offline

    Gater12

    @Eos
    You're going to have to reset the score of the last balance to remove it from the scoreboard.
     
Thread Status:
Not open for further replies.

Share This Page