Solved custsom economy

Discussion in 'Spigot Plugin Development' started by FalconSeeker, Mar 25, 2018.

Thread Status:
Not open for further replies.
  1. Code (Text):

    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;

    import falconseeker.main.Main;

    public class Econ implements CommandExecutor, Listener {
        private Main main = (Main)Main.getPlugin(Main.class);

        public void setGold(Player p, int amount){
            UUID uuid = p.getUniqueId();
            main.getConfig().set(uuid + ".gold", getGold(p) + amount);
        }
        public int getGold(Player p){
           
            UUID uuid = p.getUniqueId();
        return main.getConfig().getInt(uuid + ".gold");
        }
           public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                Player p = (Player) sender;
                if (commandLabel.equalsIgnoreCase("gold")) {
                    if (args.length == 0) {
                    p.sendMessage(ChatColor.RED + "Not enough args");
                    } else {

                    Player target = Bukkit.getPlayerExact(args[0]);
                    if (target == null) {

                    p.sendMessage(ChatColor.RED + "Your target " + args[0] + " is not online!");
                    } else {
                       
                        if (args.length == 1){
                            int amount = Integer.valueOf(args[1]);
                    p.sendMessage(ChatColor.GREEN + "Given " + amount + " to " + args[0]);
                   setGold(target, amount);
                   }
             
                }
    }
           }
                return true;
           }
    }
    doesnt do anything. howeever, when i type /gold i get the message.
     
  2. Could you elaborate? What doesnt happen that you think should happen?
     
  3. The money is not added to the players balance. No messages or anything
     
  4. JanTuck

    Supporter

    You have to use saveConfig after.
     
  5. and use cmd.getName
     
  6. As said, you need to save the config after you've set the gold there.
     
  7. yes, but its not sending the message
    Code (Text):
                    p.sendMessage(ChatColor.GREEN + "Given " + amount + " to " + args[0]);
     
     
  8. Maybe instead of getExactPlayer, try getOfflinePlayer
     
  9. Solved thread. I messed up some args.
     
Thread Status:
Not open for further replies.