Custom Currency HELP

Discussion in 'Spigot Plugin Development' started by Marcuri02, May 2, 2015.

  1. Hello, I need a plugin for my server that is Custom Currency. I use this code that I see in internet but I want to add a /Silver give NAME CURRENCY and I don't know how to do this. This is my code.
    Code (Text):

    import java.util.HashMap;
    import java.util.UUID;
    import java.util.Map.Entry;

    import org.bukkit.entity.Monster;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Villager;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Tutorial extends JavaPlugin implements Listener {

        private HashMap<UUID, Integer> money = new HashMap<>();

        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);

        public void onDisable() {
            for (Entry<UUID, Integer> entry : money.entrySet()) {
                getConfig().set(entry.getKey() + ".Silver", entry.getValue());


        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();

            if (!getConfig().contains(p.getUniqueId().toString())) {
                getConfig().set(p.getUniqueId() + ".Silver", 0);
                money.put(p.getUniqueId(), 0);
            } else {
                money.put(p.getUniqueId(), getConfig().getInt(p.getUniqueId() + ".Silver"));

        public void onEntityDeath(EntityDeathEvent e) {
            if (e.getEntity() instanceof Monster) {
                if (e.getEntity().getKiller() instanceof Player) {
                    Player p = e.getEntity().getKiller();
                    giveSilver(p, 200);
            } else if (e.getEntity() instanceof Villager) {
                if (e.getEntity() instanceof Player) {
                    Player p = e.getEntity().getKiller();
                    takeSilver(p, 200);

        private void giveSilver(Player p, int i) {
            UUID uuid = p.getUniqueId();
            money.put(uuid, money.get(uuid) + i);
            p.sendMessage("§2§l$" + i + " silver received!");

        private void takeSilver(Player p, int i) {
            UUID uuid = p.getUniqueId();
            money.put(uuid, money.get(uuid) - i);
            p.sendMessage("§c§l$" + i + " silver taken!");
  2. I see and I don't know how to do it. Any help please?
  3. Inkzzz

    Resource Staff

    No-one's going to spoon feed. If you want a good explanation, I'd advise watching a YouTube video.
    • Like Like x 1
  4. Any one can give me the code of the command please?
  5. I see you already have that, just make a command where you call takeSilver on the player, and giveSilver to the victim.
  6. Yes but I don't know how to create this command. Please help me.
    • Winner Winner x 1
  7. Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("basic")) { // If the player typed /basic then do the following...
                Player p = null;
                int i = 0;
                giveSilver(p, i);
    Is this good?
    • Agree Agree x 1
  8. Player is null and i is 0 so you are giving 0 silver to a null player.
  9. And how I modificate this?
  10. #11 raratchet, May 2, 2015
    Last edited: May 2, 2015
  11. @Marcuri02
    -Get player from command arguments
    -GiveSilver to player
  12. Exactly but let him figure out by him self ;D
  13. Yeah, he's asking for a spoonfeed but then he wouldn't learn anything! :p
  14. Can you guys stop being so rude? Just redirect him to a link or something, no need to say: "He wants this, that, no."
    • Like Like x 1
    • Agree Agree x 1
    1. Create a command;
    2. Check if args length is 2
    3. Check if args1 is a player (also do a nullcheck)
    4. Check if args2 is actually an integer
    5. Use your give silver method.
    You are here now.
  15. Hes using sgtcaze's code hes not really coding any of this lol
  16. I guess you, like many others made the mistake of jumping straight into plugin development before being at least reasonably proficient with Java. Start from square 1 mate.