Solved getInt of configFile Coins

Discussion in 'Plugin Development' started by GRayzerG, Jul 4, 2015.

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

    GRayzerG

    Hi i need help with get coins and show coins in scoreboard.

    This is a simple Api of coins


    Code:
    import com.gmail.minecraft4779.main.main;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    
    public class EconomyAPI implements Listener{
      
        public static void giveRupia(Player player, int i) {
            main.config.set(player.getUniqueId() + ".Rupias",
            main.config.getInt(player.getUniqueId() + ".Rupias", 0) + i);
            main.saveFile();
            player.sendMessage("§6§l♦§r§7=======================§6§l♦");
            player.sendMessage("      §2Haz Ganado §a§l" + i + " §6Rupias");
            player.sendMessage("§6§l♦§r§7=======================§6§l♦");
        }
        public static void takeRupia(Player player, int i) {
            main.config.set(player.getUniqueId() + ".Rupias",
                    main.config.getInt(player.getUniqueId() + ".Rupias", 0) - i);
            main.saveFile();
            player.sendMessage("§7Recibiste §a§l" + i + "§7Rupias");
        }
      
        public static boolean hasnough(Player player, int i) {
            if(main.config.getInt(player.getUniqueId() + ".Rupias") >= i)
                return true;
            return false;
        }
    }
    
    objectives of scoreboard.class
    Code:
    Score coins = objective.getScore("§7Rupias:");
    coins.setScore(12);
    
    Score coins1 = objective.getScore(main.config.getInt(player.getUniqueId() + ".Rupias")); // i have error here
    coins1.setScore(11);
    where i want show the coins

    and main.class

    Code:
    package com.gmail.minecraft4779.main;
    
    import com.gmail.minecraft4779.BookMenu.BookMenu;
    import com.gmail.minecraft4779.Chat.Chat;
    import com.gmail.minecraft4779.Economy.EconomyAPI;
    import com.gmail.minecraft4779.InfoSign.InfoSign;
    import com.gmail.minecraft4779.Lobby.BoardInfo;
    import com.gmail.minecraft4779.Lobby.LobbyJoin;
    import com.gmail.minecraft4779.Pet.DamageListener;
    import com.gmail.minecraft4779.Pet.MoveListener;
    import com.gmail.minecraft4779.Pet.PetCustomGUI;
    import com.gmail.minecraft4779.Pet.PetGUI;
    import com.gmail.minecraft4779.Pet.QuitListener;
    import com.gmail.minecraft4779.Vanish.Vanish;
    
    
    import java.util.HashMap;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Entity;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class main extends JavaPlugin {
        public static FileConfiguration config;
        public static final Logger log = Logger.getLogger("Minecraft");
        public static HashMap<String,Entity> Pets = new HashMap<String, Entity>();
        public static Plugin plugin;
        @Override
        public void onEnable() {
            log.log(Level.INFO, "[AztecaCraft] Plugin is Enable");
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "AnimateScoreboard is now enabled - Version Using: " + getDescription().getVersion());
            main.plugin = this;
            PluginManager manager = Bukkit.getPluginManager();
            manager.registerEvents(new LobbyJoin(), this);
            manager.registerEvents(new InfoSign(), this);
            manager.registerEvents(new Vanish(), this);
            manager.registerEvents(new BookMenu(), this);
            manager.registerEvents(new Chat(), this);
            manager.registerEvents(new EconomyAPI(), this);
            manager.registerEvents(new BoardInfo(), this);
            /*=====================[PET SYSTEM]=====================*/
            //manager.registerEvents(new JoinListener(), this);
            manager.registerEvents(new QuitListener(), this);
            manager.registerEvents(new MoveListener(), this);
            manager.registerEvents(new DamageListener(), this);
            manager.registerEvents(new PetGUI(), this);
            manager.registerEvents(new PetCustomGUI(), this);
            /*======================================================*/
            config = getConfig();
           
            /*======================================================*/
        }
        public static void saveFile(){
            plugin.saveConfig();
        }
        @Override
        public void onDisable() {
            log.log(Level.INFO, "[AztecaCraft] Plugin is Disable");
           
            for(String name : Pets.keySet()){
                Pets.get(name).remove();
            }
        }
       
        /*public void saveHashMap(HashMap<Object, Object> hm) {
            for (Object key : hm.keySet()) {
            config.set("HashMap."+key, hm.get(key));
            }
            saveConfig();
            }
    
            public HashMap<Object, Object> loadHashMap() {
            HashMap<Object, Object> hm = new HashMap<Object, Object>();
            for (String key : config.getConfigurationSection("HashMap").getKeys(false)) {
            hm.put(key, config.get("HashMap."+key));
            }
            return hm;
            }*/
    }
    
     
    Last edited: Jul 4, 2015
  2. Offline

    pie_flavor

    @GRayzerG Right, but what's the problem?
     
  3. Offline

    ChintziSecilMC

    @GRayzerG well to get the int of a string in config you do getConfig.getInt("Put string here"); if thats what you mean?
     
  4. @GRayzerG The scoreboard takes a string not an int. It's a simple fix just make it
    Code:
    "" + main.config.getInt(player.getUniqueId()+".Rupias")
    Or String.valueOf(Int code);

    By the way, always check if it contains them being getting it, otherwise you will get errors when someone who isn't in the config yet tries to get the scoreboard or do anything which gets the int.
     
  5. Offline

    GRayzerG

    Thnaks :D these errors are beginners, continue to learn :)
     
Thread Status:
Not open for further replies.

Share This Page