[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


    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


    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


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


    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


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


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

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


    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


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


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

Share This Page