Simple java questions

Discussion in 'Plugin Development' started by IcyRelic, Jul 31, 2013.

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

    IcyRelic

    ok im trying to organize my code and i would like to know how i can do something like this

    getArena("arena name").getStatus();

    do i need a class called getArena? and then a method getStatus in it?

    kinda like the getServer().getAllowEnd();

    just returns a boolean
     
  2. Offline

    TheBoy3

    getArena would be a method. If you put the getArena method in the main plugin class, it would return the type Arena (which obviously is the arena), then getStatus() would be a method in the Arena class.

    :)
     
  3. Offline

    Xerfox

    Your need an API that let's you do that so for instance:



    Code:java
    1. public String getArena() {
    2.  
    3. But then of course you need to return it, and add in what you want it to do when get the arena.
    4.  
    5. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  4. Offline

    IcyRelic

    ok i got something somewhat working i have a class called Arena and a method with the following

    Code:java
    1. private Arena getArenaManager = new Arena();
    2. public final Arena getArena(String arena){
    3. return getArenaManager;
    4. }


    here is my arena.java
    Code:
    package me.icyrelic.com.ArenaManager;
     
    import java.util.HashMap;
     
    public class Arena {
       
        public HashMap<String, Boolean> arenas = new HashMap<String, Boolean>();
       
        public boolean getStatus(){
           
            return true;
           
        }
     
    }
    
    now how do i use the string i put in the getArena("arena name")

    in the getStatus method

    in my arena.java its not setting the arenaName and is returning with the system.out.println when it should return the other false because its not in the hashmap

    the console message comes out as " ERROR the string arenaName was not set"

    Code:java
    1. package me.icyrelic.com.ArenaManager;
    2.  
    3. import java.util.HashMap;
    4.  
    5. public class Arena {
    6.  
    7. private HashMap<String, Boolean> arenas = new HashMap<String, Boolean>();
    8.  
    9.  
    10. private static String arenaName = "";
    11. public Arena(String arena) {
    12. arenaName = arena;
    13. }
    14.  
    15. public boolean getStatus(){
    16.  
    17. if(arenas.containsKey(arenaName)){
    18. if(arenas.get(arenaName)){
    19. return true;
    20. }else{
    21. return false;
    22. }
    23. }else{
    24. System.out.println(arenaName+" ERROR the string arenaName was not set");
    25. return false;
    26. }
    27.  
    28. }
    29.  
    30. }
    31.  


    got it working changed the getArena to
    Code:
        public final Arena getArena(String arena){
            return new Arena(arena);
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page