Solved Death Counter

Discussion in 'Plugin Development' started by toma2711, Nov 3, 2014.

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

    toma2711

    I am trying to create part of my plugin that counts a players death and then stores it into a file. I have a PlayerDeath event set up and it is registered in my main class. Is there a way to make it so that if when the player dies, it gets the death count in the file, adds 1 and then stores it again? The plugin is on GitHub at http://github.com/Skylit-Networks/Skylit-Core
    This is the Deaths Class, I have added "PLACEHOLDER" where I am wanting to put the method.
    Code:java
    1. package me.skylitgaming.skylitcore;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandExecutor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.PlayerDeathEvent;
    11.  
    12. public class Deaths implements CommandExecutor, Listener{
    13. Main plugin;
    14. public Deaths(Main passedPlugin){
    15. this.plugin = passedPlugin;
    16. }
    17. @EventHandler
    18. public void onPlayerDeath(PlayerDeathEvent e){
    19. Player player = e.getEntity();
    20. plugin.getConfig().set("deaths."+player, "PLACEHOLDER");
    21. }
    22.  
    23. @Override
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25. if (!(sender instanceof Player)){
    26. sender.sendMessage(ChatColor.RED+"This is a player only command!");
    27. return true;
    28. }
    29. Player player = (Player) sender;
    30. if (cmd.getName().equalsIgnoreCase("deaths")){
    31. player.sendMessage(ChatColor.GREEN+"You have had: "+plugin.getConfig().getInt("deaths."+player)+" deaths!");
    32. return true;
    33. }
    34. return true;
    35. }
    36.  
    37.  
    38. }
    39.  


    And this is the Main Class
    Code:java
    1. package me.skylitgaming.skylitcore;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.configuration.file.FileConfiguration;
    5. import org.bukkit.plugin.java.JavaPlugin;
    6.  
    7. public class Main extends JavaPlugin{
    8.  
    9. public void onEnable(){
    10. this.getServer().getLogger().info("============================================");
    11. this.getServer().getLogger().info("*********** ENABLING SKYLIT CORE ***********");
    12. this.getServer().getLogger().info("============================================");
    13. this.getCommand("heal").setExecutor(new HealAndFeed(this));
    14. this.getCommand("feed").setExecutor(new HealAndFeed(this));
    15. this.getCommand("teleport").setExecutor(new Teleport(this));
    16. this.getCommand("warp").setExecutor(new WarpAndSetwarp(this));
    17. this.getCommand("setwarp").setExecutor(new WarpAndSetwarp(this));
    18. this.getCommand("motd").setExecutor(new MOTD(this));
    19. this.getCommand("setmotd").setExecutor(new MOTD(this));
    20. this.getCommand("deaths").setExecutor(new Deaths(this));
    21. Bukkit.getServer().getPluginManager().registerEvents(new MOTD(this), this);
    22. Bukkit.getServer().getPluginManager().registerEvents(new Deaths(this), this);
    23. final FileConfiguration config = this.getConfig();
    24. config.options().copyDefaults(true);
    25. saveConfig();
    26. final FileConfiguration deaths = this.getConfig();
    27. deaths.options().copyDefaults(true);
    28. saveConfig();
    29. this.getServer().getLogger().info("============================================");
    30. this.getServer().getLogger().info("*********** SKYLIT CORE ENABLED ************");
    31. this.getServer().getLogger().info("============================================");
    32. this.getServer().getLogger().info("********* ENABLING VAULT DEPENDENCY ********");
    33. this.getServer().getLogger().info("============================================");
    34. }
    35.  
    36. public void onDisable(){
    37. this.getServer().getLogger().info("============================================");
    38. this.getServer().getLogger().info("*********** SKYLIT CORE DISABLED ***********");
    39. this.getServer().getLogger().info("============================================");
    40. }
    41. }
    42.  
     
  2. Offline

    Barinade

    plugin.getConfig().set("deaths."+player, plugin.getConfig().getInt("deaths."+player)+1);

    http://wiki.bukkit.org/Configuration_API_Reference#Getting_Values

    It's been a while since I've done anything Bukkit related, so I might be wrong here, but it seems as if you're missing some other necessary code. Review the link I posted, it should help.
     
  3. Offline

    toma2711

    Barinade Ok, I'll be sure to have a read of that in the morning
     
  4. Offline

    MordorKing78

    Put this in your DeathEvent,
    Code:java
    1. plugin.getConfig.set("Deaths.Players." + p, plugin.getConfig.getInt("Deaths.Players." + p)+1);

    And if you want it to be showed using a message:
    Code:java
    1. p.sendMessage("§eYour mistakes§b " + plugin.getConfig().getInt("Deaths.Players" + p));
     
Thread Status:
Not open for further replies.

Share This Page