[Urgent] Kill Death Counter Without a scoreboard

Discussion in 'Plugin Development' started by Ibix13, May 15, 2013.

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

    Ibix13

    I have posted soooo many times trying to make a kill and death counter with killstreaks and kdr, but after a bit everyone just stops posting D: I need a simple way to get a kill and death counter, maybe kdr amd killstreaks. PLEASE help this is really urgent. Thanks
    Ibix
     
  2. Offline

    kreashenz

    You're clearly not that good at Java if you don't know how to do this.. Make your methods to add/take/set/get kills or deaths, then to do KDR, you need to divide ( / ) kills by deaths.. It's simple..
     
  3. Offline

    Ibix13

    I could do it with hashmaps but when I do those it resets when I reload the server...
     
  4. Offline

    fireblast709

    then save them in a flatfile or database
     
  5. Offline

    Ibix13

    can you tell me how tho...
     
  6. Offline

    fireblast709

    Assume a simple mapping from username to kdr
    Code:
    Map<String, Double> kdr = new HashMap<String, Double>();
    Saving:
    Code:
    public void save(File file)
    {
        if(!file.exists())
        {
            try
            {
                if(!file.getParentFile().mkdirs() || !file.createNewFile() ) 
                {
                    // Just throw the exception so we can handle the no-file-case in the catch
                    throw new IOException("Failed to create either the file or the parent folders");
                }
            }
            catch(IOException ex)
            {
                //yourLogger.log(Level.SEVERE, "Failed to find/create the file");
                // And we don't want it to continue
                return;
            }
        }
        
        YamlConfiguration yc = new YamlConfiguration();
        for(Map.Entry<String, Double> ratio : this.kdr.entrySet())
        {
            yc.set(ratio.getKey(), ratio.getValue());
        }
        
        try
        {
            yc.save(file);
        }
        catch(IOException ex)
        {
            //yourLogger.log(Level.SEVERE, "Failed to save the data");
        }
    }
    Loading:
    Code:
    public void load(File load)
    {
        if(!load.exists()) return;
        YamlConfiguration yc = YamlConfiguration.loadConfiguration(load);
        for(String key : yc.getKeys(false))
        {
            this.kdr.put(key, yc.getDouble(key, 1D));
        }
    }
    Study the code :p
     
  7. Offline

    microgeek

    It's not even Java, it's 6th grade logic.
     
  8. Offline

    Ibix13

    This forum is supposed to be fricking nice and you guys are being a bunch of douches.
     
  9. Offline

    TnT

    These folks are trying to help you out, no need to attack them. There is a basic understanding of Java that is required to make even the simplest of plugins, and they are suggesting that you may want to get back to basics and learn those before attempting to handle this plugin. We cannot possibly teach Java as well as teach how to use the Bukkit API, so there is some expectation that you will take on the learning Java bits first.

    That said, @fireblast709's post was very helpful. I suggest reading through that as an example of how you can accomplish what you are looking to accomplish.
     
    microgeek likes this.
Thread Status:
Not open for further replies.

Share This Page