Skip to content

Instantly share code, notes, and snippets.

@lualzockt
Created August 29, 2013 14:19
Show Gist options
  • Save lualzockt/6378708 to your computer and use it in GitHub Desktop.
Save lualzockt/6378708 to your computer and use it in GitHub Desktop.
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));
}
}
}
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