How to Add money dots?

Discussion in 'Plugin Development' started by DuB_B_O_S, Aug 22, 2014.

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

    DuB_B_O_S

    Im trying to make a money dots so when u do ./bal u will get "your balance is: 1,000,000,00.00" not "your balance is: 1000000000"

    thx for helping and reading
     
  2. Offline

    mine-care

    DuB_B_O_S likes this.
  3. Offline

    Monkey_Swag

    int double
     
    DuB_B_O_S likes this.
  4. Offline

    DevSock

    DuB_B_O_S It's really easy, you can use decimal format! Here is the code, please be sure to understand it before you use it.

    Code:java
    1. //First you need to get the player's balance and set it to a variable.
    2. double balance = 1234567.89;
    3. //Then you need to create a decimal format.
    4. DecimalFormat df = new DecimalFormat("###,###,###,###,###.##");
    5. //Then you need to format the balance using your decimal format, this returns a string.
    6. String formattedBalance = df.format(balance);
    7. //Then you message the player their balance using the variable you saved the formatted balance to!
    8. player.sendMessage("Your balance is " + formattedBalance + "!");
     
    DuB_B_O_S likes this.
  5. Offline

    DuB_B_O_S

    Thank you!

    im rly bad at coding xD i just started bukkit coding so im newb xD

    DevSock

    im getting Syntax erros ...
    Code:java
    1. package me.saticnetwork.staticbal;
    2.  
    3. import java.text.DecimalFormat;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class StaticBal extends JavaPlugin implements Listener{
    13.  
    14. double balance = 1234567.89;
    15. DecimalFormat df = new DecimalFormat("###,###,###,###,###.##");
    16. String formattedBalance = df.format(balance);
    17. Player.sendMessage("Your balance is " + formattedBalance + "!");
    18. }


    on" player.sendMessage "

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    Xyplo

  7. Offline

    DuB_B_O_S

    player.sendMessage("Your balance is " + formattedBalance + "!");
    the "sendMessage" is the error
     
  8. Offline

    JBoss925

    Why isn't the code in a method?
     
  9. Offline

    DuB_B_O_S

  10. Offline

    Xyplo

    1) Like JBoss925 said, Why is it not in a method?
    2) THERE IS NO 'Player' !!!!
     
  11. Offline

    DuB_B_O_S

    Xyplo
    im newb at coding so i have no idea what is player as a player so what should i do ? :/
     
  12. Offline

    ulsa

    well at least try to do broadcast message for testing instead of a player :)
    well what "player" is .. it is an entity :p also it is an object which holds a lots of information such as players name , its inventory , which world he is , is he op , his location ....

    so if you want to send a message to a player you can do
    A) loop through every player and send message
    B) get his name and use Bukkit.getPlayer(name) method and send him a message

    but for broadcasting you can change the player bit to
    Code:java
    1. Bukkit.broadcastMessage("Your balance is " + formattedBalance + "!")
    2.  
    3. //will broadcast a message to everyone


    also dont forget to add a space to exclamation mark :)
     
  13. Offline

    DuB_B_O_S

    I did the coding like this No erros But my server dosent allow to load the plugin :/

    Code:java
    1. package me.saticnetwork.staticbal;
    2.  
    3. import java.text.DecimalFormat;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class StaticBal extends JavaPlugin implements Listener{
    13. public void onEnable() {
    14. Bukkit.getServer().getLogger().info("StaticBal Plugin Enabled!");
    15. }
    16.  
    17. public void onDisable() {
    18. Bukkit.getServer().getLogger().info("StaticBal Plugin Disabled!");
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    22. if (!(sender instanceof Player)) {
    23. sender.sendMessage("console is not allowed to use balance command!");
    24. return true;
    25. }
    26. double balance = 1234567.89;
    27. DecimalFormat df = new DecimalFormat("###,###,###,###,###.##");
    28. String formattedBalance = df.format(balance);
    29. Player player = (Player) sender;
    30. if (cmd.getName().equalsIgnoreCase("bal")) {
    31. player.sendMessage("Your balance is " + formattedBalance + "!");
    32. }
    33. return true;
    34. }
    35. }
     
  14. Offline

    shohouku


    You'll need to register your events from your onEnable function, if you have another class that already registers the event, check your other classes or else just use this.

    Put this in your OnEnable:

    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
     
  15. Offline

    DuB_B_O_S

    ok thx im gona try it now

    shohouku

    i don't have other class only the class what i post is at there
    and its still dosent allow me to run the plugin at server

    Any1 ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  16. Offline

    stoneminer02

    1. Don't bump more than once each 24 hours.
    2. Learn java.
    3. Try again.
     
    DuB_B_O_S likes this.
  17. Offline

    Dragonphase

    DuB_B_O_S

    You need to learn Java and the Bukkit API before attempting to make a Bukkit Plugin.
     
    DuB_B_O_S likes this.
  18. Offline

    MineStein

    It makes our lives and yours so much easier if you take your time and learn Java. I jumped in without knowing Java. It only gets harder if you keep going in that direction. I can recommend you some tutorials.

    For Java
    Text: http://www.tutorialspoint.com/java/index.htm
    Video: https://www.youtube.com/playlist?list=PLE7E8B7F4856C9B19
    Official Tutorial: http://docs.oracle.com/javase/tutorial/java/concepts/index.html

    For Bukkit
    Text: Take a look at the forums, it is basically a HUGE knowledge base
    Video:
    - https://www.youtube.com/user/TheTurqmelon
    - https://www.youtube.com/user/SgtCaze
    - https://www.youtube.com/user/PogoStick29Dev
    Documentation: http://www.jd.bukkit.org

    I hope this helps! :D
     
    DuB_B_O_S likes this.
  19. Offline

    Jozeth

    What I use:
    Code:java
    1. public static String format(BigDecimal money) {
    2. DecimalFormat formatter = new DecimalFormat("#.##");
    3. formatter.setGroupingUsed(true);
    4. formatter.setGroupingSize(3);
    5.  
    6. return formatter.format(money);
    7. }
    You can change the 'BigDecimal' to 'double' if needed.

    Returns: 5850.41 to 5,850.41
     
    DuB_B_O_S likes this.
  20. Offline

    MordorKing78

    Binnen in men hard binnen in mijn ziel van binnen
     
  21. Offline

    DuB_B_O_S

    Ok i will check it out when i come home and thx

    Thanks i will try it out when i come hom ;)

    Im sorry if i am newb and im trying to learn java/bukkit coding.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  22. Offline

    DevSock

    ulsa
    I know this is a petty thing to comment about, but you SHOULDN'T add a space if you want to be grammatically correct.

    On Topic: You need to learn Java. We can't help you if you don't know Java, it's what makes all of this possible! Don't even think about doing anything with Bukkit until you know at least the basics of Java like the back of your hand.
     
  23. Offline

    mine-care

    DevSock thanks for giving him an example! I had barely enough time to point out the clas and doc on my post above <3
     
Thread Status:
Not open for further replies.

Share This Page