Player specific variables/booleans

Discussion in 'Plugin Development' started by PokerulerPlayz, Sep 5, 2015.

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

    PokerulerPlayz

    I'm quite new to programming in Java, and so I might be coming on here frequently for help, but this is something I just can't find on the forums.

    I'm creating a plugin that I'm hoping is going to be a lobby plugin, where the player has all kinds of items in there inventory, like Player toggling, Chat toggling, and all of that.

    I'm trying to make a mute chat toggle, and have all of it set up, mostly. My problem is that I don't know how to give players variables, like Timmy's mute chat is True, but Jimmy's mute chat is False. I'm guessing it will have something to do with a config, because I also want the boolean to save, that way if the server restarts, or if they log off, it will be the same when they join back in.

    Also, it would be nice to have an example to test for a player that has a certain boolean set to true, that way I can give that player the toggle mute slime ball/magma cream.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @PokerulerPlayz You can make a list for the different functions, add the player uuid to the list if he wants something enabled, remove it when he wants it disabled
     
  3. Offline

    PokerulerPlayz

    Could you please give me an example? Like I said in the beginning, I am quite new to Java, so I can't quite do this. :)
     
  4. Offline

    timtower Administrator Administrator Moderator

    I won't give code. Did that once, didn't work out well in the end.
     
    Zombie_Striker and mythbusterma like this.
  5. Offline

    mythbusterma

    @PokerulerPlayz

    His explanation was a little vague.

    You can use Maps to associate players with other Objects (Boolean included). However, if you only need to test for presence, a Set will work fine (as they are either in the Set or not in the Set). When storing players, you should use their UUID instead of the Player Object, so as to avoid memory leaks.
     
    Konato_K likes this.
  6. Offline

    PokerulerPlayz

    Is it possible to move a map to other class files, like from the Main class to a listener class?
     
  7. Yes it is.
     
  8. Create for example an ArrayList<String> for each on/off feature. There are also other better solutions.
    Then add the UniqueID of the player in the PlayerInteractEvent to the list. You need to convert it before doing this with uuid.toString(). Then check if the list contains the UUID with: if(list.contains(e.getPlayer().getUniqueID().toString()))

    You can remove the UUID with list.remove(String).
     
  9. Offline

    PokerulerPlayz

    ... could you please give me an example on how to do this? Something tells me you won't, because that response seemed more like a troll :p
     
  10. Offline

    Evonoucono

    @PokerulerPlayz
    If your looking for Player Specific variables like the title says, another option would be to create a HashMap<String, Integer> . When you add a player use hashMapName.put(p.getname, #); Later you can get that number by doing hashMapName.get(p.getname);
     
  11. Make the HashMap/ArrayList static. Then you can access it with YourClass.YorList
     
    ZP18 likes this.
  12. Offline

    mythbusterma

    Or don't encourage bad practices.
     
    Konato_K and timtower like this.
  13. Offline

    teej107

    No you can't. Learn what static is used for and the visibility modifiers.
     
  14. Offline

    meguy26

    @PokerulerPlayz
    Simple suggestion: Choose a small challenge or something, and using java, overcome said challenge. This will help you learn java before blindly diving in to a large API like Bukkit.
     
    Konato_K likes this.
Thread Status:
Not open for further replies.

Share This Page