Killstreak plugin not saving the kills

Discussion in 'Spigot Plugin Development' started by eatxaxcookie, May 26, 2015.

  1. Hi

    I am trying to make a killstreak plugin that saves your kills, deaths and streak but it does not save them to the config. It does add the player to the config if the player joins.

    Hope someone can help me with my problem and may have some tips. :)

    Code (Text):
    package nl.EATxAxCOOKIE.ShearKitPvP;

    import java.math.BigDecimal;

    import io.puharesource.mc.titlemanager.api.ActionbarTitleObject;
    import io.puharesource.mc.titlemanager.api.TitleObject;



    import net.milkbowl.vault.economy.Economy;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;

    public class ShearKitPvP extends JavaPlugin implements Listener{
       
         @Override
            public void onEnable() {
             getConfig().options().copyDefaults(true);
             saveConfig();
             Bukkit.getPluginManager().registerEvents(this, this);
           
             if (setupEconomy()) {
                 getLogger().info(ChatColor.AQUA + "Found Vault! Hooking in for economy!");
                 }
           
            }
       
       
           private boolean setupEconomy()
           {
               RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
               if (economyProvider != null) {
                   econ = economyProvider.getProvider();
               }

               return (econ != null);
           }
         
           public Economy econ = null;
         
            @Override
            public void onDisable() {
               
            }
           
            FileConfiguration cfg = getConfig();
           
            @EventHandler
            public void onJoin(PlayerJoinEvent e){
                Player p = e.getPlayer();
               
               
               
                if(cfg.get("stats."+p.getName())==null){
                    cfg.createSection("stats."+p.getName());
                    cfg.createSection("stats."+p.getName()+".kills");
                    cfg.createSection("stats."+p.getName()+".deaths");
                    cfg.createSection("stats."+p.getName()+".killstreak");
       
                    cfg.set("stats."+p.getName()+".kills", 0);
                    cfg.set("stats."+p.getName()+".deaths", 0);
                    cfg.set("stats."+p.getName()+".killstreak", 0);
       
                    saveConfig();
                }
               
            }
           
            void sendTitle(Player player, String title, String subtitle) {
                  new TitleObject(title, subtitle).send(player);
                }
           
            void sendAction(Player player, String message) {
                  new ActionbarTitleObject(message).send(player);
                }
            @EventHandler
            public void onDeath(PlayerDeathEvent e){
                Player p = e.getEntity();
                Player kill = e.getEntity().getKiller();
       
                cfg.set("stats."+p.getName()+".deaths", cfg.get("stats."+p.getName()+".deaths" +1));
                cfg.set("stats."+p.getName()+".killstreak", 0);
               
                if(kill instanceof Player){
                cfg.set("stats."+kill.getName()+".kills", cfg.get("stats."+kill.getName()+".kills" +1));
                cfg.set("stats."+kill.getName()+".killstreak", cfg.get("stats."+kill.getName()+".killstreak" +1));
               
                double money = new BigDecimal(cfg.getInt("stats."+kill.getName()+".killstreak")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
               
                sendTitle(kill,"§c§lKILL!","§bStreak: "+ cfg.get("stats."+kill.getName()+".killstreak") + " §a+" + (Double.toString(money)) + "§");
                for(Player allP : Bukkit.getOnlinePlayers()) {
                sendAction(allP,"§b"+ kill.getName() +" §c§l> §3§lKilled §c§l > §b" + p.getName());
                }
                kill.setLevel(kill.getLevel() + 3);
               
                econ.depositPlayer(kill, money);
               
                }
               
            }
               
    }
     
     
  2. Try saving :D
    Code (Text):
            @Override
            public void onDisable() {
               saveConfig();
            }
     
  3. Srry i meant when someone makes a kill or died it does not get added up in the config .
     
  4. The +1 is one bracket to left
    Also better work with uuids
     
  5. Inkzzz

    Resource Staff

    Furthermore, spreading your work into different classes to be more efficient.
     
  6. What Inkzzzmc said, you should try spreadying your code over different classes so it can be more efficienty and easier to find errors e.c.t
     
  7. To fix the problem...
    Code (Text):

    -- change --
    cfg.get("stats."+kill.getName()+".kills" +1));
    -- to --
    cfg.get("stats."+kill.getName()+".kills") + 1);
     
     
  8. Maybe first read the other answers before write the Same as I did?
     
    • Agree Agree x 1
  9. Why? does my answer help him any less? Or does the awareness of being the "first answer" somehow bestow gratitude upon yourself? It's not about being first, it's about helping. Your reply was unnecessary and rather ignorant. I opened the thread to read the issue and respond with a solution in a timely fashion, not to read comments from the masses. Had I wished to recite degenerate literature I would evoke within social media. Thanks.
     
    • Optimistic Optimistic x 1
  10. Your answer is useless as the answer was already given. I agree that there are a lot of comments from "the masses", but spamming the answer x times in different versions does not help to make this thread cleaner.
     
    • Agree Agree x 1
  11. I respect that you want help, but what was ignorant in my response ?!
     
  12. Just leave him. He is probably one of those guys that are always right
     
  13. 1. maybe this
    2. this dicussion doesnt help anybody
     
    • Agree Agree x 1
  14. False. I provided a visual representation of the solution. Depending on the user's preferred style of learning, all answers advise in the benefit of the user. Rather he is an auditory, visual, or tactile learner... Obviously my approach appeals to visual learners.


    EDIT:
    Further response is irrelevant. What exactly is your "beef"? Because I answered a question within a public forum? Or because my answer reflected yours and you had answered before me?

    No matter how you justify your trolling, this battle you seek is pathetic. Your initial response to me was quite uncalled for - just be happy we have access to these forums where others are willing to sacrifice their time to offer assistance.
     
    • Funny Funny x 1
    • Optimistic Optimistic x 1
  15. I had not that much time as i made the response but i think he would have understood it.
    I only said that your response was a bit unnecessary, thats my "beef" xD.
    But now stop this and be friends again :D
     
    • Agree Agree x 1
  16. Thx for the fix and the tips! :D
    and srry for the late response :p