Solved Help with keeping track of player specific things

Discussion in 'Plugin Development' started by darthteddy1, Nov 12, 2015.

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

    darthteddy1

    EXAMPLE: What would I need to do to keep track of a players amount of something (let's say deliveries) and how would I add to a players amount, get their current amount, set their current amount, and take from them. Thanks :)
     
  2. Offline

    CraftCreeper6

    @darthteddy1
    You want temporary storage or?
    If so, use a HashMap, they allow for a key and a value.

    If not, use a configuration file (Comes with Bukkit). You can use getConfig(); to have a look at the different things you can do with it.
     
  3. Offline

    darthteddy1

    @CraftCreeper6 well how would I save a players specific amount to a config?
     
  4. Offline

    CraftCreeper6

    @darthteddy1
    getConfig()#set(path, value);

    Path could be the players UUID (Or name if you are still at that stage) plus the factor you want to keep track of (Paths are seperated by "." e.g: "myuuid.mythingy")
    Value could be the *well value* of the factor.
     
  5. Offline

    Scimiguy

    wiki.bukkit.org/Configuration_API_Reference
     
  6. Offline

    darthteddy1

    Ok, everything works, BUT the givepackages command
    EDIT:
    How would I update the amount of packages a person has when i do a command. What I just tried:
    Code:
    getConfig().set(playerToGive.getName() +".balance", args[2]);
     
    Last edited by a moderator: Nov 12, 2015
  7. Offline

    Scimiguy

    Use the report button for that
     
  8. Offline

    Lordloss

    @darthteddy1

    This line of code should do the job. Did you made sure the config is saved after changing it?
     
  9. Offline

    Xerox262

    You shouldn't save the config every time you change it, you only need to save it when the plugin is disabled.
     
  10. Offline

    darthteddy1

    @Lordloss Thanks, now 1 last thing, how to I add to the current amount a player has? (EX: Person has 1, how do I add 2 to their current amount?)

    Also: This is supposed to save the item in my hand (I have a default item for this), and the location I'm at, but it never saves the item OR the place to the config! (Brackets in code might be off a little, its in the middle of my plugin file):
    Code:
            }else if(args[0].equalsIgnoreCase("setShopOpener")) {
                if(sender.hasPermission("Tokens.ADMIN")) {
                if(args[1].equals("1")) {
                Player p = (Player) sender;
                p.getWorld().getBlockAt(p.getLocation()).setType((Material) getConfig().get("Token_Shop.block"));
                getConfig().set("packageOpen1.location", p.getLocation());
               
           
                    if(args[1].equals("2")) {
                       
                        p.getWorld().getBlockAt(p.getLocation()).setType((Material) getConfig().get("Token_Shop.block"));
                        getConfig().set("packageOpen2.location", p.getLocation());
                       
                       
                       return true;
                } else if(args[0].equalsIgnoreCase("block")) {
                    if(sender.hasPermission("Tokens.SET")) {
               
                   
                    getConfig().set("Token_Shop.block", p.getItemInHand());
                    p.sendMessage("Item Recorded!");
                   
                   
                }
                    }}
        }}
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 15, 2015
  11. Offline

    darthteddy1

  12. Offline

    Zombie_Striker

    How can args[1] be "1" and "2"?
     
  13. Offline

    Scimiguy

    @Zombie_Striker
    Clearly you have no understand of Schrödinger's Integer


    @darthteddy1
    Seriously though. How would that ever work
    Also your spacing is awkward and misleading.. you should consider fixing it
     
  14. Offline

    darthteddy1

  15. Offline

    Scimiguy

    @darthteddy1
    If your problem is solved, then edit the title of this thread and mark it as solved
     
Thread Status:
Not open for further replies.

Share This Page