Able to store kills?

Discussion in 'Plugin Development' started by Treeline1, Oct 14, 2014.

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

    Treeline1

    Hey
    I was wondering if it was possible to store the amount of kills someone has gotten in a document? I don't want MySQL or database but an easy way.
    And then also a way to display it on a scoreboard?
     
  2. Offline

    teej107

  3. Offline

    candyfloss20

    Treeline1
    This is the simple way to do it:
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent e) {
    3. Player killer = e.getEntity().getKiller();
    4.  
    5. int deaths = getConfig().getInt(killer.getUniqueId()+".Deaths");
    6. getConfig().set(killer.getUniqueId()+".Deaths", deaths+1);
    7. saveConfig();
    8. }


    You dont have to but i would Recommend doing this:
    so you know who the player is
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent e) {
    3. Player player = e.getPlayer();
    4. getConfig().set(player.getUniqueId() + ".UserName", player.getName());
    5. saveConfig();
    6. }


    Config:
    Code:
    candyfloss20s-uuid:
        UserName: candyfloss20
        Deaths: 1
     
    Treeline1 likes this.
  4. Offline

    Treeline1

    candyfloss20
    "
    candyfloss20s-uuid:
    UserName: candyfloss20
    Deaths: 1
    "
    Do I need to do this manually? Or is this updated automatically? Do I add it to the class etc?
     
  5. Offline

    Treeline1

    AdamQpzm I am fairly new to Bukkit and Java.... Its helpful...
     
  6. Treeline1 Trust me, you'd be better off starting with Java with the Oracle tutorials or a Java book, and then learning Bukkit from the tutorial on the Bukkit wiki. Spoon-feeding isn't all that helpful, and undoubtedly a major problem with it is that it seems helpful to the people feeding and the people being fed. :)
     
  7. Offline

    candyfloss20

    Treeline1,
    AdamQpzm Is Right you should learn Java 1st!

    Oh and do you still want the code to add a scoreboard??

    As long as you use saveConfig(); it will update and format its self

    I know but I was in Treeline1 shoes once and no one would help me,
    So I want to help people like him out :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  8. Offline

    xMrPoi

    If you're getting the player's data and then editing it, make sure that it actually exists first.
     
  9. candyfloss20 That assumes that spoon-feeding is helpful, which it is not ;)
     
  10. Offline

    candyfloss20

    xMrPoi, Oh Yer Poop! :D

    Use this (Small part from my Custom SG):
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent e) {
    3. xCraftPlayer xUser = new xCraftPlayer(e.getPlayer());
    4.  
    5. if (!Game.getPlugin().getConfig().contains(xUser.getUniqueIdentifier().toString())) {
    6. Game.getPlugin().getConfig().set(xUser.getUniqueIdentifier() + ".Deaths", 0);
    7. Game.getPlugin().getConfig().set(xUser.getUniqueIdentifier() + ".Kills", 0);
    8. Game.getPlugin().getConfig().set(xUser.getUniqueIdentifier() + ".Wins", 0);
    9. Game.getPlugin().getConfig().set(xUser.getUniqueIdentifier() + ".DeathMatchesReached", 0);
    10. }
    11. Game.getPlugin().getConfig().set(xUser.getUniqueIdentifier() + ".Username", xUser.getName());
    12. Game.getPlugin().saveConfig();
    13. }
     
  11. Offline

    xMrPoi

    xCraftPlayers? :confused:
     
  12. Offline

    candyfloss20

    xMrPoi
    Custom Player interface
    Adds:
    .getRank();
    .setRank(Rank r);

    .getGems();
    .setGems(Int g);

    .getCredits();
    .setCredits(Int c);

    and some more...
    (so I don't have to do the long code to connect to the Database all the time)
     
  13. Offline

    xMrPoi

    candyfloss20 likes this.
Thread Status:
Not open for further replies.

Share This Page