Help with numbers

Discussion in 'Plugin Development' started by yoitsjimby, Aug 20, 2014.

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

    yoitsjimby

    Well I created a scoreboard but the numbers I would like millions to show up like mil billions to
    show up as and thousands to show up as k
    so if my balance is like 100000 it shows up like 100k and if I have 1000000 it shows up as 1mil and etc heres what the scoreboard looks like





    [​IMG]
     
  2. Offline

    Yekllurt

    Check if the number is bigger then 100.000 then take the first 3 numbers and write at the end k then you get for example out of 162.300 162k
     
  3. Offline

    yoitsjimby

    Hey im not sure how I would state this thoug I know I would have to do like if number = im not really sure could you show me?
     
  4. Offline

    Yekllurt

    Here is how you coud to it
    Code:java
    1.  
    2. int money = 153650;
    3. String a = "0";
    4. if(money >= 100000){
    5. String b = String.valueOf(money);
    6. a = b.substring(0, 3) + "k";
    7. }
    8.  


    Here it woud return 153k ,
    the money integer you have to exchange throw you balance
     
  5. Offline

    Zettelkasten

    yoitsjimby Maybe like this?

    store output string
    if number bigger then 100.000 then
    output string = divide number by 1000 + "k"
    else
    output string = number as string
    put output string into scoreboard
     
  6. Offline

    yoitsjimby

    well heres my whole code

    package me.yoitsjimby;


    import java.util.logging.Logger;

    import net.craftservers.prisonrankup.Models.PRPlayer;

    import net.craftservers.prisonrankup.Models.Rank;

    import net.milkbowl.vault.economy.Economy;

    import net.milkbowl.vault.permission.Permission;

    import org.bukkit.Bukkit;

    import org.bukkit.ChatColor;

    import org.bukkit.Server;

    import org.bukkit.entity.Player;

    import org.bukkit.plugin.PluginManager;

    import org.bukkit.plugin.RegisteredServiceProvider;

    import org.bukkit.plugin.ServicesManager;

    import org.bukkit.plugin.java.JavaPlugin;

    import org.bukkit.scheduler.BukkitScheduler;

    import org.bukkit.scoreboard.DisplaySlot;

    import org.bukkit.scoreboard.Objective;

    import org.bukkit.scoreboard.Score;

    import org.bukkit.scoreboard.Scoreboard;

    import org.bukkit.scoreboard.ScoreboardManager;


    publicclass SB

    extends JavaPlugin


    {

    publicstatic Permission permission = null;


    publicvoid onEnable()


    {

    if (!setupEconomy())


    {

    getLogger().severe(String.format("VAULT NOT ENABLED", new Object[0]));

    getServer().getPluginManager().disablePlugin(this);

    return;


    }

    sB();

    }



    publicvoid sB()


    {

    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable()


    {

    publicvoid run()


    {

    for (Player p : Bukkit.getOnlinePlayers())


    {

    PRPlayer prplayer = new PRPlayer(p.getName());

    Rank nextRank = prplayer.getNextRank();

    Rank current = prplayer.getCurrentRank();

    Rank nowrank = current;

    Rank rank = nextRank;


    doublemoneyToNextRank = SB.econ.getBalance(p) - rank.getPrice();

    ScoreboardManager manager = SB.this.getServer().getScoreboardManager();

    Scoreboard sb = manager.getNewScoreboard();

    Objective o = sb.registerNewObjective("stats", "dummy");

    o.setDisplaySlot(DisplaySlot.SIDEBAR);

    o.setDisplayName(ChatColor.BLUE + "[" + ChatColor.RESET + ChatColor.BOLD.toString() + nowrank.getName().toString() + ChatColor.BLUE + "] " + ChatColor.BLUE.toString() + ChatColor.BOLD + p.getName());

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE.toString() + ChatColor.BOLD + "Online")).setScore(12);

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE.toString() + ChatColor.BOLD + Bukkit.getOnlinePlayers().length)).setScore(11);

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE.toString() + ChatColor.BOLD + "Rankup")).setScore(10);

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE.toString() + ChatColor.BOLD + moneyToNextRank)).setScore(9);

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE.toString() + ChatColor.BOLD + "Balance")).setScore(8);

    o.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE.toString() + ChatColor.BOLD + SB.econ.getBalance(p))).setScore(7);

    p.setScoreboard(sb);


    }

    }

    }, 0L, 200L);

    }

    publicstaticboolean setupEconomy()


    {

    if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {

    returnfalse;


    }

    RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);

    if (rsp == null) {

    returnfalse;


    }

    econ = (Economy)rsp.getProvider();

    returnecon != null;


    }



     

     



    publicstatic Economy econ = null;


    publicvoid updateScoreboard(Player p)


    {

    ScoreboardManager manager = getServer().getScoreboardManager();

    Scoreboard sb = manager.getNewScoreboard();

    Objective o = sb.registerNewObjective("stats", "dummy");

    o.setDisplaySlot(DisplaySlot.SIDEBAR);

    o.setDisplayName(ChatColor.BLUE.toString() + ChatColor.BOLD + p.getName());


    Score money = o.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + "Balance"));


    Score online = o.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + "Online"));

    money.setScore((int)econ.getBalance(p));

    online.setScore(Bukkit.getOnlinePlayers().length);

    p.setScoreboard(sb);


    }

    }
     
  7. Offline

    Yekllurt

    Plz post it in the code format, other wise it is unreadable
     
  8. Offline

    Zettelkasten

    yoitsjimby Yekllurt Yes, definitely! BTW Use Ctrl + SHIFT + V to paste code without the colors and add the
    Code:
    -tags to make it formatted as code.
     
    To your problem: Where you are right now doing this:
    [CODE=java]o.getScore(Bukkit.getOfflinePlayer(ChatColor.BLUE.toString() + ChatColor.BOLD + SB.econ.getBalance(p))).setScore(8);
    Change the "SB.econ.getBalance(p)" to the String with the new balance; in my example the "output string".
     
  9. Offline

    yoitsjimby

    how do I add it in this?
     
Thread Status:
Not open for further replies.

Share This Page