Developing a group based plugin.

Discussion in 'Plugin Development' started by lightniinja, Apr 13, 2013.

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

    lightniinja

    Hello,
    Firstly, I'll describe what I'm trying to achieve.
    I'll presume you've played on a minigame-style server, and if you haven't I'd recommend you checked one out (I personally play PiCraft.)
    These minigame servers contain groups, for example (Prepare for the best table you've ever seen):
    [​IMG]
    What I'd like to know, is how are they storing these groups?
    Would I need to make a new "Player" object? With fields such as
    Code:
    playing = GameType.Spleef // The player is currently in the game 'spleef'
    playing = GameType.none // The player is not currently playing any game.
    playing = GameType.wait // The player is waiting for the game 'x' to start.
    And with GameType.wait, I could somehow store the game ID, or something similar to that.
    Which brings me to a new topic, storing games.
    For this one, I have it mapped out quite well in my head (Soon to be in a text document), that
    I could keep the games in a MySQL database, adding a new row when a game is qued to start, and removing the game when it finishes.

    Sorry if this is unclear, just ask if you need anything explaining.
    This stuff looks alot easier to understand in my eyes, but people don't think alike!

    Hoping someone can help me, and thanks for taking the time to read this!

    -- Matthew (lightniinia).
     
  2. Offline

    pers2981

    I'd just use a hashmap.

    To set it up:
    public final HashMap<String, Boolean> PlayingSpleef= new HashMap<String, Boolean>();

    To add a player:
    PlayingSpleef.put(player.getName(),True);

    When the game is over, or if you want to remove them from the group simply use:
    PlayingSpleef.remove(player.getName());
     
  3. pers2981
    Why not Map<String, GameType> ?
     
  4. Offline

    lightniinja

    So, I could just listen for all the different events where a player could leave the server (Kick, Disconnect, etc), and remove them from the Hashmap then, and just add them when they join the minigame? That would remove the need for a custom "Player" class, wouldn't it?
     
  5. lightniinja
    You can't really make a custom Player class to actually replace the Player class if that's what you meant.

    What you can do is asign objects on player names by using a Map, you could make a CustomPlayer object and give it alot of fields to store stuff but you'll still have to use a Map to asign it to a player name.

    Also, don't use Player object in lists or maps or stuff because it will just cause you problems, use String and player's name.
     
  6. Offline

    lightniinja

    Digi
    I wasn't meaning to replace the Player class, rather to make a custom one, as you suggested, like Essentials 'User' class, which contains the values like whether the player is AFK, godmode, etc, do you think that would be a good idea?
     
  7. Offline

    Qwahchees

    What I used to do group storing of information was HashSets, which are similar to HashMaps but just contain one value. I stored the player's name (not the actual player, as this is bad practice) and from then on used HashSetName.contains() and HashSetName.remove() to work my plugin. It works like a charm.
     
Thread Status:
Not open for further replies.

Share This Page