[SOLVED] Setting An Integer For Each Player

Discussion in 'Plugin Development' started by KaiBB, Dec 27, 2011.

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

    KaiBB

    Is there a way to have an int for each individual player? For example, a warning system with 3 warnings, and if "int warning == 0" than the player is banned. (This is not what I'm using, though. Just an example.) Thanks! :D
     
  2. Offline

    skore87

    HashMap<String,Integer> where string is the player name, and integer is the warnings. You would want to save and load this from a file though since this would lose the values if restarted or shut down.
     
  3. Offline

    KaiBB

    Wow. Thanks. I knew this, I just forgot lol. Thanks anyway! :D
     
  4. Offline

    Jaker232

    What? If the player has 0 warnings, they're banned? I'm confused.

    Yes, you can. If you want to add one warning to the Map, you use the .put(player, integer); function. Then you call a syncing task in your main class to check a Map, see if someone has 3 or more warnings, then set them banned.

    EDIT: Sniped by skore.
     
  5. Offline

    skore87

    I scored, get it? wink wink, nudge, nudge =P
     
  6. Offline

    SwearWord

    @KaiBB
    Do not use tasks for this. Have a simple function like this

    PHP:
    private static Map<StringIntegerwarnings = new HashMap<StringInteger>();
    public static 
    boolean addWarning(String player) {
        if(!
    warnings.containsKey(player)) {
            
    warnings.put(player1);
            return 
    false;
        }
        
    Integer w warnings.get(player);
        
    w++;
        return 
    w==3;
    }
    In the future, questions like these are answered faster and better if you go into #bukkitdev in irc.esper.net
     
  7. Offline

    Jaker232

    Thanks for telling me it's a bad function. It's the best method I could think, but you provided a better one.
     
  8. Offline

    KaiBB

    I wasn't really doing Warnings (as I specified in the post -.-'), but thanks.
    @Jaker232
     
  9. Offline

    AlbireoX

    You can always use a Trove TObjectIntMap :)
     
Thread Status:
Not open for further replies.

Share This Page