Saving a player for an inventory?

Discussion in 'Plugin Development' started by ESSHD, Feb 19, 2015.

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

    ESSHD

    Hello,

    I'm wondering how I could save a players name, then open a custom inventory with their name so I can use my MySQL stats.

    Any ideas?

    Thanks, ESSHD
     
  2. Offline

    Qwertyness_

    What exactly do you mean by save a player's name? To a configuration file? Database?
     
  3. Offline

    ESSHD

    @Qwertyness_ Just to a variable while they check their stats
     
  4. Offline

    Qwertyness_

    String playerName = player.getName();
     
  5. Offline

    TheEntropy

    @ESSHD Well, if you just want to save more than one player in memory, you can easily do that with a static arraylist.

    Code:
    
    // create an arraylist and store the player in it
    public static ArrayList<String> players = new ArrayList<String>();
    players.add(player.getName());
    
    // then you can check if the player is in the arraylist
    if (players.contains(player.getName()) {
    
    // do something
    
    }
    
    edit: keep in mind that you should only make it static if you'll need it after you've finished calling the method in that class. If you don't make the arraylist static, Java's garbage collector will eat it.
     
  6. Offline

    1Rogue

    Explain your justification for making your arraylist static, and justification for exposing the entire field.

    By the way, this:
    Is 100% untrue
     
    Last edited: Feb 19, 2015
    Skionz likes this.
  7. Offline

    TheEntropy

    @1Rogue So demanding!

    That post was just a 'wildcard' example, really. Perhaps he will need it in more than just that class? Perhaps the values within that arraylist will be needed much after the garbage collector has passed by?
     
  8. Offline

    Garris0n

    ಠ_ಠ
    ( ಠ_ಠ) (ಠ_ಠ) (ಠ_ಠ )
     
    Konato_K and fireblast709 like this.
  9. Offline

    1Rogue

    I asked because you're suggesting someone do something that is a completely terrible idea.

    Need something in another class? You don't use static for that:

    Code:java
    1. private final Object myfield = /* some value */;
    2.  
    3. public Object getObject() {
    4. return this.myField;
    5. }

    Here's an additional 50 links: http://bukkit.org/threads/how-to-us...-that-extends-javaplugin.285074/#post-2613361

    If you're going to make remarks about the garbage collector, it might help to understand how it actually works. The garbage collector won't randomly collect values if there's a strong reference to them.

    I'll propose another question. How will you handle me doing these three things?:

    Code:java
    1. YourClass.players = null;
    2.  
    3. YourClass.players.clear();
    4.  
    5. //third
    6. List rand = new ArrayList();
    7. rand.add(42);
    8. rand.add("bleh");
    9. rand.add(new Object());
    10. YourClass.players = rand;
     
  10. Offline

    TheEntropy

    @1Rogue I honestly didn't know that.
     
  11. Offline

    Garris0n

    But what if the garbage collector is feeling angry because he isn’t making enough money to live off of and his parents won’t bail him out since “he’s a grown man” and his wife divorced him because he always came home smelling like garbage so he’s breaking down and feeling depressed inside and he really just wants to jump off the garbage truck and be run over by a car because that’s the only thing that will make him feel better but he can’t do that because he’d be leaving two loving kids behind and they’ve already been through enough in the divorce and he already only gets to see them twice a week because their mom could afford a better lawyer so he goes home every night sobbing smelling like garbage and his water has been shut off so he can’t even take a shower and it’s really getting to him so out of frustration he garbage collects a random non-static object?
     
    YoshiGenius and hintss like this.
  12. Offline

    Not2EXceL

    uuid do you speak it mothurfliffler
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page