Instructions on a team/gang plugin :D

Discussion in 'Plugin Development' started by BeastCraft3, Nov 12, 2014.

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

    BeastCraft3

    Hellau, Am wondering if anyone could give me an instruction on how to create a gang plugin. I don't want the code for it, but I would love if someone wrote down step by step what I should do so I can learn a little.
    as an example:
    Step 1) create a hashmap to store the gangs and a list to store players.
    step 2) etc...
    the first step was wrong I guess xD.
    Anyway please if you have any interest in training me please make instructions.

    I don't know if this will help you make an instructions but these are the commands I'll be creating:
    Gang create <Gangname> "To create a gang"
    Gang invite <Playername> "To invite a player"
    Gang disband <Gangname> "To disband a gang"
    Gang uninvite <Playername> "To uninvite a player"
    Gang leave "To leave your gang"
    Gang join <Gangname> "To join a gang"

    Regards,
    MrBeastie
     
  2. Offline

    mythbusterma

    BeastCraft3

    You seem to have a pretty good idea what you want, why do you need us?
     
  3. Offline

    BeastCraft3

    mythbusterma
    I don't trust me. I only know the basic. if you know how I should do It I would love to listen
     
  4. Offline

    mythbusterma

    BeastCraft3

    Try writing something out, if you have any issues you can come here. It doesn't seem like you need our help with this, at least, not yet.
     
    leon3001 likes this.
  5. Offline

    BeastCraft3

    BUMB
    I would like a quick written tutorial mythbusterma . so I don't need to edit everything because I did something wrong in the start.
     
  6. Offline

    FerusGrim

    1) Create a Gang object which stores information like name, tag, member list, etc.
    2) Create a GangManager object, which stores a List of the Gang objects, and has methods to return a Gang object when given an id, name, etc.
    3) ???
    4) Profit.

    Code:java
    1. public class Gang {
    2. private final int id;
    3. private final String name;
    4. private final List<UUID> members;
    5.  
    6. public Gang(int id, String name, List<UUID> members) {
    7. this.id = id;
    8. this.name = name;
    9. this.members = members;
    10. }
    11.  
    12. public int getId() {
    13. return this.id;
    14. }
    15.  
    16. public String getName() {
    17. return this.name;
    18. }
    19.  
    20. public List<UUID> getMembers() {
    21. return this.members;
    22. }
    23.  
    24. public boolean isMember(UUID uuid) {
    25. return getMembers().contains(uuid);
    26. }
    27.  
    28. // ... etc
    29. }


    Code:java
    1. public class GangManager {
    2. private final List<Gang> gangs = new ArrayList<Gang>();
    3.  
    4. public void addGang(int id, String name, List<UUID> members) {
    5. this.gangs.add(new Gang(id, name, members));
    6. }
    7.  
    8. public void removeGang(int id) {
    9. this.gangs.remove(getGang(id));
    10. }
    11.  
    12. public Gang getGang(int id) {
    13. for (Gang gang : this.gangs) {
    14. if (gang.getId() == id) {
    15. return gang;
    16. }
    17. }
    18. return null;
    19. }
    20. }


    Something like that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
    Konato_K and leon3001 like this.
  7. Offline

    BeastCraft3

  8. Offline

    Monkey_Swag

    FerusGrim why..... pls read my signature.
     
    teej107 and Regablith like this.
  9. Offline

    FerusGrim

    Eh. I provided a standard Object with a standard manager for the Object. It happens to be slightly related to the question at hand.

    However, unless he learns how to use it, he wouldn't be able to use it. And the knowledge of how to use it is more important to me than providing something that takes a few seconds to type out.
     
  10. Offline

    teej107

    FerusGrim why..... pls read my comment.

    BeastCraft3 Actually a Map should be sufficient enough.
     
  11. Offline

    Totom3

    FerusGrim I agree with you for the most part, but.... O(n) to get a Gang from it's ID? Why not use a Map<String, Gang> where the index is the gang's name? Or if you want to keep it indexed with their IDs then you could use an Integer... I don't see the point of using a List here

    EDIT: this also applies to the Gang object itself. For some reason you decided to store the members in a List, O(n) is back again! Why not a Set? This will also insure there are no duplicates.

    Monkey_Swag teej107 C'mon guys... He provided a class with a few getters and setters...
     
    FerusGrim likes this.
  12. Offline

    teej107

    Totom3 You yourself pointed out the flaws in his spoonfed code.


    Another way to use gangs would be to have a Map like this: Map<Player(or UUID), Gang>. If Gang is null under a certain player, then they aren't in one.
     
  13. Offline

    BeastCraft3

    teej107 Totom3 teej107 FerusGrim
    Guys... this wans't what I actually asked for.. I said I didn't want any code unless I asked. I'm not learning this properly if I get the plugin template premade. I was suppost to figure all this out my self. and yes I know how to use getters and setters, Totom3 teached me it.
    I would like a easy step by step written tutorial(NO CODE!) so I can learn how the good coders would make it....
     
  14. Offline

    FerusGrim

    BeastCraft3
    I supplied a step-guide above the template I gave you.
     
  15. Offline

    Totom3

    BeastCraft3
    Ok so I don't think there's too much to say about the commands class. You can simply make a switch statement over args[0] and do whatever needs to be done. Nothing complicated over here.

    For the mini-API that comes with the plugin, I'd suggest, as FerusGrim said, to use a Manager object. What I mean by that is an object that can add, remove, check for, list and clear entries (similarly to a Map). Here you'd store Gang objects. If you decide to use a Map internally, Gang would be the value of the map, and the key could be either the ID of the Gang or it's name (I'd go for the name). The advantage of wrapping a Map (in a Manager) instead of exposing it is that you can make sure it is used correctly. That may sound advanced but really, it's simple.

    The Gang object itself is really not complex. Ask yourself : what do I need to store about each Gang ? The internal name, display name, influence (maybe?), ID (not necessary) and the players that are in it. Make a few getters and setters and you're done. Still no complicated stuff.
     
Thread Status:
Not open for further replies.

Share This Page