Creating an Arena From a Command

Discussion in 'Plugin Development' started by CodeAX2, May 1, 2017.

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

    CodeAX2

    Hi everyone! I am currently working on an eggwars plugin (a type of minigame). I currently created a class for an arena object that looks like this:
    Code:
    package EggWars;
    
    import org.bukkit.Location;
    import org.bukkit.World;
    
    public class Arena {
        int players;
        int teams;
        int minPlayers;
        World world;
       
        //First array is for teams. Second array is for individual players
        Location[][] spawnpoints;
    }
    
    I want to create a command where players enter something such as: /eggwars add <arena name>

    Here is my current code for the command:
    Code:
                    if(args.length > 0 && args.length < 3){
                        if(args[0].equalsIgnoreCase("add") && args.length == 2){
                            //Add a new arena with the name of args[1]!
                        } else if (args[0].equalsIgnoreCase("remove")){ // Also check to see if args[1] is an existing arena.
                           
                        }
                    }
    I am currently stuck on how to make a new arena based on args[1]. I have tried:
    Arena args[1] = new Arena();
    Which obviously did not work. So, how am I able to create a new Arena based on what the user input for their arena name, i.e User types:
    /eggwars add myArena
    and the code run is something like:
    Arena myArena = new Arena();

    So, how can I convert args[1] to something that can be used to name an object?
     
  2. Offline

    MrGeneralQ


    Create another class or use the main class and create a generic list in there. Add the Instance of your Arena Class in there. I would also suggest you to pass the Arena Name (unique) with the constructor so you can loop in the List and get the correct Arena.

    Also, you got some properties which I personly wouldn't do.

    int players; -> I assume this is the amount of players in there? Change that toA generic list of Players and use a method called for ex: "GetAmountOfPlayers() to return the ammount of items in your generic list.

    int teams -> I can't be wrong, but I think your int Teams is pretty much the same. Create a generic list of Teams (could be another class) and return the ammount GetAmmountOfTeams()


    Hope It helped you a bit


    and the answer to your question is simple:

    Use a constructor to pass the args. So it would look something like this


    Team myTeam = new Team(args[0]);
     
  3. Offline

    DoggyCode™

    Could get tricky.

    Instead create a Team object to mange each induviduals team's locations. Might also want to create your own implementation of Location :)
     
  4. Offline

    messageofdeath

    I would create an ArenaManager class. Put an arraylist of Arena classes and create methods around that like get,add,remove,getall. The typical stuff. Then add a constructor for new Arena classes.
    This is my typical setup for almost anything. If I didn't explain it well, this is an example from PaidRanks for my LadderManager.
    https://github.com/messageofdeath/P.../messageofdeath/PaidRanks/Utils/LadderManager
     
Thread Status:
Not open for further replies.

Share This Page