Solved ArrayList small problem (3 lines)

Discussion in 'Plugin Development' started by RAFA_GATO_FOFO, Apr 9, 2014.

Thread Status:
Not open for further replies.
  1. Hey guys,

    So I'm trying to make a /team new [TeamName] command. Why does this not work?

    Code:java
    1. public static void newTeam(String TeamName,Player player){
    2. private static List<String> TeamName = new ArrayList<String>();
    3. }


    Error: Illegal modifier for parameter TeamName; only final is permitted

    N3rdFall

    How would I make it work? Create a team with the name the player inputs.

    N3rdFall
    Thanks for nothing then I guess. I'd like to see you asking for help sometimes and getting answers like that. But I guess that's the internet community for me.

    N3rdFall
    As you're probably aware, some of the newer users of these Forums like myself are actually autodidact and for myself, I've been learning by watching videos and reading tutorials. When you tell me to read up on Java Syntax that's much like telling a foreigner to read grammar if he can't conjugate a verb.
    I mean't no offense but it's not particularly helpful if you get the picture. I will eventually learn that I guess.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    mazentheamazin

    RAFA_GATO_FOFO
    My apologize if this comes out rude. However, understanding Java syntax 100% is a MUST before even going into an API, this is due to it will break your understanding of Java (If you ever plan to make programs outside of Bukkit) and (Learning the language itself) make you reliant on some of the methods Bukkit API Provides. One last thing, programming languages are much more different and should not be compared to language used to communicate between me and you.
     
  3. Offline

    Cloaking_Ocean

    RAFA_GATO_FOFO What he means by modifier is when you say:
    "private static" These are modifiers (A key word you should know if you want to code in Java)
    private means that other classes not in your direct package cannot access the variable, although since you're in a method you don't need modifiers.

    SIMPLE FIX:

    just take out the "private static" before initializing the List.

    Note: Also if the modifiers you made were a result of Eclipse (or whatever compiler you have) trying to fix something I think you might need to change "List<String> TeamName = new ArrayList<String>();" to "ArrayList<String> TeamName = new ArrayList<String>();"

    Remember I'm not sure about the list part. And btw, if you are wanting to learn java it would be good to go to some programming websites or someplace you can learn. For me, after taking Computer Programming in School it has helped so much because I can understand when people say the keywords "modifiers", "Methods", "parameters" and such.

    Suggested Sites:
    learn.code.org
    www.codecademy.com
    http://docs.oracle.com/javase/tutorial/

    Btw the docs.oracle.com/javase/tutorial/ is a bit less fun because it's just a bunch of text and pictures. What I suggest is finding out how classes work and their organization and also learning important keywords such as modifiers, methods, etc..

    RAFA_GATO_FOFO if you still need any help with programming just msg me. I'm still a noob too xD
     
  4. mazentheamazin Cloaking_Ocean
    I get what you guys are saying, I'll try to understand a bit more about Java Syntax in the next few days.
    I'm kinda tired right now and I may not be thinking straight but my goal here was to have the TeamName (which would be a string inputted by the player in the command) be the name of a List of Strings which would be the team. Does this make sense? If not then I'll just go to sleep and take a fresh look at this tomorrow, hopefully coming up with a fix or a proper explanation of what I'm trying to reach.

    Code:java
    1. public void newTeam(String TeamName, Player player){
    2. //TeamName is a String that the players input via command
    3. //Creating a list of strings with the name TeamName should be
    4. List<String> TeamName = new ArrayList<String>();
    5. }


    At least that's what I got off a Tutorial from TheBCBroz on YT. I may be confused and if I am just say "you're confused" and I'll refresh tomorrow, no problem whatsoever.
     
  5. Offline

    mazentheamazin

    [​IMG]

    Just to get straight to what I am trying to say, I would not recommend learning the Bukkit API from the TheBCBroz, I'd say PogoStick29 is better. Personally, I did not learn through tutorials/videos, I've learnt from the Wiki (for the basics), then by looking through the JavaDocs, and some threads on bukkit to learn certain things.
     
  6. Offline

    Gater12

    thenewboston has videos on the basics of Java, if you're interested.
     
  7. Offline

    mazentheamazin

  8. Offline

    PogoStick29

    It looks like this thread briefly dissolved into fighting then came back to actual help, but I'd like to weigh in on the dispute. RAFA_GATO_FOFO, it is important to learn the Java API before moving on to Bukkit. If you check out the Java 101 series on my channel, it might be able to help you. N3rdFall, while you offered good advice, you were a bit vague and came off as a bit pushy. I vote that this thread be marked [Solved].
     
  9. Offline

    Wizehh

    RAFA_GATO_FOFO
    Also, you should opt for OOP over void methods: create Team class, then make a new instance of the class when you want to create a new team.
     
  10. Offline

    Lorinthio

    Why not make a hashmap and nest lists in it?

    Hashmap<String, Player[]> teams

    Then using that class variable you can add new strings and apply group updates to the key

    Ill try to get you a code snippet shortly with a method to make it work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Lorinthio
    Any news on that snippet? I haven't looked at this in a while but I'd still like it.
     
  12. Offline

    Lorinthio

    Oh yeah let me make it sorry bout that

    Code:java
    1. public HashMap<String, List<Player>> teams = new HashMap<String, List<Player>>();
    2. public Integer teamSize = 6;
    3.  
    4. public void createTeam(String Teamname){
    5. List<Player> emptyteam = new ArrayList<Player>();
    6. teams.put(Teamname, emptyteam);
    7. }
    8.  
    9. public void addPlayerToTeam(String Teamname, Player player){
    10. List<Player> currentteam = teams.get(Teamname);
    11. if(currentteam.size() >= teamSize){
    12. log.info("Team is full cancelling");
    13. return;
    14. }
    15. currentteam.add(player);
    16. teams.put(Teamname, currentteam);
    17. }
    18.  
    19. public void removePlayerFromTeam(String Teamname, Player player){
    20. List<Player> currentteam = teams.get(Teamname);
    21. currentteam.remove(player);
    22. if(currentteam.size() == 0){
    23. log.info("Team is empty, deleting");
    24. teams.remove(Teamname);
    25. }
    26.  
    27. }


    Hope that helps you out!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  13. Lorinthio
    Yeah that solves my problem man, thanks a lot!
     
  14. Offline

    Lorinthio

    Sure thing! Good luck with your plugin!
     
Thread Status:
Not open for further replies.

Share This Page