Created
August 29, 2013 14:19
-
-
Save lualzockt/6378708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Stats { | |
private static MyPlugin plugin; | |
private static Map<String,Integer> kills = new HashMap<String,Integer>(); | |
public static void setPlugin(MyPlugin pl) { | |
plugin = pl: | |
} | |
public static void load() { | |
for(String key : plugin.getConfig().getKeys(false)) { | |
kills.put(key, plugin.getConfig().get(key)); | |
} | |
} | |
public static void addKill(Player player) { | |
if(kills.containsKey(player.getName())) { | |
kills.put(player.getName(); kills.get(player.getName()) +1); | |
}else { | |
kills.put(player.getName(),1); | |
} | |
} | |
public static void safe() { | |
for(String key : kills.keySet()) { | |
plugin.getConfig().set(key, kills.get(key)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyPlugin extends JavaPlugin implements Listener{ | |
@Override | |
public void onEnable() { | |
Stats.setPlugin(this); | |
Stats.load(); | |
} | |
@Override | |
public void onDisable() { | |
Stats.save(); | |
} | |
@EventHandler | |
public void onDeath(PlayerDeathEvent e) { | |
if(e.getEntity().getKiller() != null) { | |
Stats.addKIll(e.getEntity()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment