Tutorial Make a minigame plugin!

Discussion in 'Resources' started by xTrollxDudex, Aug 15, 2013.

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

    Slideroller

    Still errors
     
  2. Offline

    xTrollxDudex

  3. Offline

    DailyLove

    Code:java
    1. public void loadGames(){
    2. arenaSize = 0;
    3.  
    4. if(data.getCustomConfig().getIntegerList("Arenas.Arenas").isEmpty()) {
    5. return;
    6. }
    7. for(int i : plugin.getConfig().getIntegerList("Arenas.Arenas")){
    8. Arena a = createArena(deserializeLoc(plugin.getConfig().getString(i)));
    9. a.getId() = i;
    10. }
    11.  
    12. }


    I'm getting an error on getString(i); It say "getString (java.lang.String) in MemorySection cannot be applied."

    Also on a.getId() = i; It says "Variable expected."
     
  4. Offline

    xTrollxDudex

    DailyLove
    Sorry... It's pretty late right now, I'll fix that tomorrow

    Ok. It should work now :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 6, 2015
  5. Offline

    JPG2000

    xTrollxDudex One thing, why do you use ID's? It would be as easy to use Arena names.
     
  6. Offline

    xTrollxDudex

    JPG2000
    It's easier to manage. And I'm too lazy include names in setup, so...
     
  7. Offline

    JPG2000

    xTrollxDudex Not at all, its pretty much the same thing.
     
  8. Offline

    xTrollxDudex

    JPG2000
    Well, since this tutorial into provide an example as to how you could create a minigame plugin, the parameters can be edited to your own liking. I personally prefer numbers but others may differ.
     
  9. Offline

    DailyLove

    xTrollxDudex What did you change?

    I'm still getting an error on a.getId() = i; and "i" in createArena(deserializeLoc(plugin.getConfig().getString(i)));
     
  10. Offline

    xTrollxDudex

    DailyLove
    That part actually works... I'm not sure about you, but it works for me. Let me check one more time.
     
  11. Offline

    DailyLove

  12. Offline

    xTrollxDudex

    DailyLove
    Hmm. Surprising thing is, I use the exact same IDE. Try now, I updated it...
     
  13. Offline

    CookieGamer100

  14. Offline

    xTrollxDudex

  15. Offline

    DailyLove

    How would I get the players from a arena,

    something like
    Code:java
    1. for(Player p : a.getPlayers()) {
    2. p.teleport(loc);
    3. }


    When I do that it tells me to change p to String. Is there another method so I can keep the getPlayers(), but also use one to get all the players of the arena to teleport them.
     
  16. Offline

    Slideroller

    Um most of the errors were fixed except for 1
    Line:122
    Problem:num
    Code->plugin.getConfig().set("Arenas." + num, null);
     
  17. Offline

    xTrollxDudex

    DailyLove
    Here:
    PHP:
    for(String s a.players) {
        
    Player p Bukkit.getServer().getPlayer(s);
        if(
    != null) {
            
    p.teleport(loc);
        }
    }
    Slideroller
    Submit a PR
     
  18. Offline

    DailyLove

    Thank you so much :)
     
    xTrollxDudex likes this.
  19. Offline

    xTrollxDudex

    Slideroller
    Never mind then! Found the prob. It's fixed now.

    *sighs* jeez. Stupid mistakes :p
     
  20. Offline

    Goblom

  21. Offline

    CookieGamer100

    How would I remove players from all Arenas? Could I maybe have some code or could you put it in the github :)
    I know you could get all online players and check if there in the arena then remove them with a string but I'm sort of to Java/Bukkit :p
     
  22. Offline

    Goblom

  23. Offline

    xTrollxDudex

    CookieGamer100
    PHP:
    public void removePlayers(Arena a) {
        for(
    String s a.players) {
            
    Player p Bukkit.getServer().getPlayer(s);
            if(
    != null) {
                
    removePlayer(p);
            }
        }
    }
    Goblom
    I now think that although APIs are useful, they do not provide as equal learning opportunity as implementing arenas on your own. This introduces a lot of people to topics such as
    - OOP programming
    - Using Collections
    - Using the Config and YAML APIs in Bukkit
    - Persistance
    - among others
    Thanks for the advertising though :p

    Oh and regards to your second comment, that's not gonna work. It just clears the list...
     
    CookieGamer100 likes this.
  24. Offline

    DailyLove

    I'm getting a NPE that I can't manage to fix.

    Full Stack Trace

    Code:java
    1. // Line 227
    2. plugin.getConfig().set("Arenas." + num, serializeLoc(l));
    3.  
    4. // Line 274
    5. Arena a = createArena(deserializeLoc(plugin.getConfig().getString("Arenas." + i)));
    6.  
    7. // Line 290
    8. return l.getWorld().getName()+","+l.getBlockX()+","+l.getBlockY()+","+l.getBlockZ();


    Basically the problem is orignating on line 274, which is the loadGames() method, than goes to the createArena() method, which is the error on line 227. Then leads to the serializeLoc() method error on line 290 due to line 227 error.

    Any help to fix that?
     
  25. Offline

    xTrollxDudex

    DailyLove
    What the... Can you print out the location before creating the arena on line 274 and print it out after deserializing the location in the createArena() method?

    Hmm. Let mg try to add a ConfigurationSection not null check...
     
  26. Offline

    DailyLove

    xTrollxDudex It's successfully putting the arena data in the config, but once it tries to run the loadGames() method again it throws the NPE. It's whenever it's not empty is it throwing the NPE.
     
  27. Offline

    xTrollxDudex

    DailyLove
    I think it's because the list is null, try now, I made the list from create and delete returned from the config...
     
  28. Offline

    DailyLove

    Nevermind I found the problem, actually two problems :)

    When you do createArena(deserializeLoc(blah blah)); It keeps duplicating the arenas everytime the arena is enabled. so I created a method called reloadArena and use that instead.

    Code:java
    1. public Arena reloadArena(Location l) {
    2. int num = arenaSize + 1;
    3. arenaSize++;
    4.  
    5. Arena a = new Arena(l, num);
    6. arenas.add(a);
    7.  
    8. return a;
    9. }


    Also in your deserializeLoc method you use st[1] twice. So I changed it to be like this

    Code:java
    1. public Location deserializeLoc(String s){
    2. String[] st = s.split(",");
    3.  
    4. return new Location(Bukkit.getWorld(st[0]), Integer.parseInt(st[1]), Integer.parseInt(st[2]), Integer.parseInt(st[3]));
    5. }


    Other than that great job! Thank you so much for your help.
     
    xTrollxDudex likes this.
  29. Offline

    zakkinu2

    Assist How will you check how many people are in an arena.
     
  30. Offline

    JPG2000

    zakkinu2 Get the arenas and do .players.size(). Totally now self advertising, but my Arena method (Made a tutorial) has a get max players settings. Check my link.

    Also, this doesn't count as advertising since I helped the person. So xTrollxDudex , 1+ me.
     
    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page