Stats Config help

Discussion in 'Plugin Development' started by VinexAx789, Nov 21, 2015.

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

    VinexAx789

    Hello, I'm making stats for my plugin and I got the file to work but it doesn't print anything into it.

    Stats Class Code:
    View Class (open)

    Code:
    public int getKills(String player) {
            int kills = plugin.stats.get("Players." + player + ".Kills") != null ? plugin.stats
                    .getInt("Players." + player + ".Kills") : 0;
            return kills;
        }
    
        public void addKill(String player) {
            plugin.stats.set("Players." + player + ".Kills", getKills(player) + 1);
            try {
                plugin.stats.save(plugin.statsFile);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    
        public int getDeaths(String player) {
            int deaths = plugin.stats.get("Players." + player + ".Deaths") != null ? plugin.stats
                    .getInt("Players." + player + ".Deaths") : 0;
            return deaths;
        }
    
        public void addDeath(String player) {
            plugin.stats
                    .set("Players." + player + ".Deaths", getDeaths(player) + 1);
            try {
                plugin.stats.save(plugin.statsFile);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    
        public int getKDR(String player) {
            int kills = plugin.stats.get("Players." + player + ".Kills") != null ? plugin.stats
                    .getInt("Players." + player + ".Kills") : 0;
            int deaths = plugin.stats.get("Players." + player + ".Deaths") != null ? plugin.stats
                    .getInt("Players." + player + ".Deaths") : 0;
    
            return kills / deaths;
        }
    
        public void setKDR(String player) {
            int kills = plugin.stats.get("Players." + player + ".Kills") != null ? plugin.stats
                    .getInt("Players." + player + ".Kills") : 0;
            int deaths = plugin.stats.get("Players." + player + ".Deaths") != null ? plugin.stats
                    .getInt("Players." + player + ".Deaths") : 0;
    
            plugin.stats.set("Players." + player + ".KDR", kills / deaths);
        }
    }
    


    Death Event:
    View Death Event (open)

    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void playerdeath(PlayerDeathEvent event) {
            if (event.getEntity().getKiller() != null) {
                Player victim = event.getEntity();
                Player killer = victim.getKiller();
                             statsObject.addKill(killer.getName());
                               statsObject.addDeath(victim.getName());
    }
    }


    onEnable():
    View onEnable (open)

    Code:
    public void onEnable() {
          
            FileConfiguration config = getConfig();
            config.options().copyDefaults(true);
          
            config.addDefault("Economy.host", "www.db4free.net");
            config.addDefault("Economy.name", "byosta");
            config.addDefault("Economy.user", "byosta");
            config.addDefault("Economy.password", "byostabyosta");
    
            statsFile = new File(getDataFolder(), "stats.yml");
            stats = YamlConfiguration.loadConfiguration(statsFile);
          
            statsFile = new File(getDataFolder(), "stats.yml");
            if (!statsFile.exists()) {
                try {
                    statsFile.createNewFile();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            stats.options().copyDefaults(true);
        }
     
  2. Offline

    Zombie_Striker

    @VinexAx789
    Did you debug? If so, what line does it get up to?
     
  3. Offline

    Xerox262

    Code:
    public int getKDR(String player) {
    should return a double to have decimal places. (Not an int) not exactly helpful to the main topic but still. Also dividing by 0 is an ArithmeticException.
     
    Zombie_Striker and VinexAx789 like this.
  4. Offline

    VinexAx789

    @Zombie_Striker It doesn't print anything to the config I might just do it with MySQL but I don't know it yet.
     
  5. Offline

    Zombie_Striker

     
  6. Offline

    Xerox262

    http://www.w3schools.com/sql/ will teach you SQL. If you use that then it'd be easier to share it across servers.
     
  7. Offline

    VinexAx789

    I'm legally blind so I can't see that. But let me debug there.
     
Thread Status:
Not open for further replies.

Share This Page