Util *BROKEN* *PLEASE READ* Create a Minigame!

Discussion in 'Resources' started by JPG2000, Nov 11, 2013.

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

    xTrollxDudex

    apple2114
    Obviously, you're just making things more complex, and you don't know sufficient Java. Please also learn to edit your posts instead of making a new post with an unnoticeable difference from the last one.
     
  2. Offline

    ksbdude

    I created a fully functional minigame plugin and used some of this code in the arena manager etc. It works perfectly except for when i try to reload. All values are saved to the config except when I reload/restart the server it acts like those values are not there even though when I look in config they are. I tried making a custom reload command just for the plugin but it dose not make a difference. Any idea why the X,Y,X etc are not being retrieved from the config?!? It returns null for most values but they are not null.
     
  3. Offline

    sockmonkey1

    So its not loading the arenas? Did you call the loadArena(); in the onEnable?
     
  4. Offline

    ksbdude

    Yes I did
     
  5. Offline

    PatoTheBest

  6. Offline

    sockmonkey1

    Its not saving to the config right, Oh, actaully I remember. There is an error in the original post in the load arenas. I'l fix it.

    Code:java
    1. public void loadArenas() {
    2.  
    3. //I just create a quick Config Variable, obviously don't do this.
    4. //Use your own config file
    5. FileConfiguration fc = null; //If you just use this code, it will erorr, its null. Read the notes above, USE YOUR OWN CONFIGURATION FILE
    6.  
    7. //Youll get an error here, FOR THE LOVE OF GAWD READ THE NOTES ABOVE!!!
    8. for (String keys: fc.getConfigurationSection("arenas").getKeys(false)) { //For each arena name in the arena file
    9.  
    10. //Now lets get all of the values, and make an Arena object for each:
    11. //Just to help me remember: Arena myArena = new Arena("My Arena", joinLocation, startLocation, endLocation, 17)
    12.  
    13. World world = Bukkit.getWorld("arenas." + keys + ".world");
    14.  
    15. //Arena's name is keys
    16.  
    17. double joinX = fc.getDouble("arenas." + keys + ".joinX");
    18. double joinY = fc.getDouble("arenas." + keys + ".joinY");
    19. double joinZ = fc.getDouble("arenas." + keys + ".joinZ");
    20. Location joinLocation = new Location(world, joinX, joinY, joinZ);
    21.  
    22. double startX = fc.getDouble("arenas." + keys + ".startX");
    23. double startY = fc.getDouble("arenas." + keys + ".startY");
    24. double startZ = fc.getDouble("arenas." + keys + ".startZ");
    25.  
    26. Location startLocation = new Location(world, startX, startY, startZ);
    27.  
    28. double endX = fc.getDouble("arenas." + keys + ".endX");
    29. double endY = fc.getDouble("arenas." + keys + ".endX");
    30. double endZ = fc.getDouble("arenas." + keys + ".endX");
    31.  
    32. Location endLocation = new Location(world, endX, endY, endZ);
    33.  
    34. int maxPlayers = fc.getInt("arenas." + keys + ".maxPlayers");
    35.  
    36. //Now lets create an object to represent it:
    37. Arena arena = new Arena(keys, joinLocation, startLocation, endLocation, 17);
    38.  
    39. }
    40.  
    41.  
    42. }


    In the original code he used fc.getDouble("arenas." + "keys." + "endX");
    it should be fc.getDouble("arenas." + keys + ".endX");
    He actually does this for almost all of the locations.
     
  7. Offline

    bluegru

    JPG2000
    I get NPE in this line:
    Code:java
    1. player.teleport(arena.getJoinLocation());

    Maybe it's because I removed this:
    Code:java
    1. Arena arena = new Arena(arenaName, lobbyLocation, startLocation, endLocation, maxPlayers);

    But shouldn't this work, becuase it's still in the loadArenas() method?
     
  8. Offline

    PatoTheBest

    Just remove Arena arena = and keep the rest
     
  9. Offline

    bluegru

  10. Offline

    ever_x

    Ok so I am trying long and hard to get my create method to work. I've simplified any causes of error by removing the bulk of the code and I am left with this
    Code:java
    1.  
    2. public void createArena(String arenaName, Location joinLocation, Location startLocation, Location endLocation, int maxPlayers) {
    3. Arena arena = new Arena(arenaName, joinLocation, startLocation, endLocation, maxPlayers);
    4.  
    5. plugin.getConfig().set("cake.lie", true);//Line that is causing an error :(
    6. plugin.saveConfig();
    7.  

    However, I look in the console and line 237 (commented above) causes a null pointer error. I have
    Code:java
    1. plugin//.blablabla();
    set up as so:
    Code:java
    1.  
    2. public static TheNameOfMyPluginsMainClass plugin;
    3.  

    Any ideas?
    I used the tutorial linked to me in a previous reply to set up my config file and this should be the way to do it, but it clearly isn't!
     
  11. Offline

    PatoTheBest

  12. Offline

    bluegru

    I thin you have to change this:
    Code:java
    1. World world = Bukkit.getWorld("arenas." + keys + ".world");

    to:
    Code:java
    1. World world = Bukkit.getWorld(fc.getString("arenas." + keys + ".world"));

    And you have to save it in the createArena method:
    Code:java
    1. fc.set(path + "world", joinLoction.getWorld().getName());
     
  13. Offline

    mrgreen33gamer

    How does the configuration work with the x, y, and z?
     
  14. Offline

    97WaterPolo

    JPG2000
    Trying to send a scoreboard to all players that are in the game. How would I do that? I originally thought
    Code:
                for (Arena a: Arena.arenaObjects)
                {
                    for (Player ingame : a.getPlayers())
                    {
                       ingame.setScoreboard(board);
                    }
                }
    Problem is a.getPlayers() returns a list of strings, how would I get the players themselves from that and send it to just the players in that arena without sending it to players in another?
     
  15. Offline

    bluegru

    97waterpolo
    Code:java
    1. Bukkit.getPlayer(ingame).setScoreboard(board);
     
  16. Offline

    97WaterPolo

    bluegru
    Problem is in game is a string not a Player though.
     
  17. Offline

    bluegru

    97waterpolo
    I know,
    thats why you should use
    Code:java
    1. Bukkit.getPlayer("playerName")

    It returns the player
     
  18. Offline

    97WaterPolo

    bluegru
    Ohhhhhhh, sweet, thank you! Will try this when home!
     
  19. Offline

    ever_x

    I have a problem in my endArena method. I didn't check if this had been solved earlier on in the thread, but who cares:
    Code:java
    1. public void endArena(String arenaName)
    2. {
    3. if (getArena(arenaName) != null)
    4. {
    5. Arena arena = getArena(arenaName);
    6. CountdownManager.cancelCountdownTask(arena);
    7. CountdownManager.cancelGraceTask(arena);
    8. arena.sendMessage(ChatColor.GREEN + "[Knockout] " + ChatColor.GOLD
    9. + "Game Over! Thanks for playing.");
    10. for (String s : arena.getPlayers())// Error Here!
    11. {
    12. Player player = Bukkit.getPlayer(s);
    13. InventoryManager.restoreInventory(player);
    14. arena.getPlayers().remove(player.getName());//This is probably what's causing it :(
    15. }
    16. }
    17. }

    With this code I get a Caused by: java.util.ConcurrentModificationException error. How can I fix this, as it is the same (or similar in structure) as the original demo code! I googled it and it seems that removing a value in the list whilst iterating is the cause, but I can't think of a fix!
    Thanks for any help.
     
  20. Offline

    FisheyLP

    JPG2000
    You used in your Arenas.class a sendMessage method, to send every player in a arena a message, i think.. but how can i use it??? please explain it me noob friendly :p
     
  21. Offline

    bluegru

    FisheyLP
    First get the arena with:
    Code:java
    1. Arena arena = ArenaManager.getManager().getArena("arenaname");

    The you can send the message to all player in the arena:
    Code:java
    1. arena.sendMessage("message");
     
  22. Offline

    sockmonkey1

    ever_x
    Did you google it?
    I had the same issue. It actually should be fixed by JPG2000 in the OP.
    A good fix is to declare a new arraylist that you can make changes to. The problem is because you're taking the arraylist then removing items from it then using it again. Java dosen't like that. haha

    Code:java
    1. ArrayList<String> players = new ArrayList<String>(
    2. arena.getPlayers());
    3. for (String s : players) {
     
  23. Offline

    ever_x

    sockmonkey1
    Yes, thank you for the reply. I did google it and was aware of why the error might be being caused. Your code worked a charm! I was thinking something along the lines of creating a new ArrayList but wasn't sure how to go about it. Thank you once again.
     
  24. Offline

    sockmonkey1

    Sure I think jpg2000 should update that in the op. >.> NP ever_x anytime
     
  25. Offline

    Andrisb

    Hi,
    Could someone give me 100% completed plugin (with plugin.yml and configs)? I need all source codes to analyze this plugin.
    Thanks.
     
  26. Offline

    sockmonkey1

    Andrisb
    No one is going to do that. I've made some before but none that I have on github. I have this one that I made. It doesn't work (as in the game mechanics) but the arena classes and the other things are okay.
    I suggest you learn java first, then bukkit api.
    Here it is on github.
     
  27. Offline

    callum2904

    How would i go about removing an arena and removing all stored data for that arena?
     
  28. Offline

    bluegru

    callum2904
    I think its:
    Code:java
    1. Arena arena = getArena("ArenaName");
    2. Arena.arenaObjects.remove(arena);
     
  29. Offline

    callum2904

    That only removes it from the list, I cant get it to delete the contents of the arena from the yml file.
     
  30. Offline

    bluegru

    callum2904
    just set it null
    Code:java
    1. fc.set("Path", null);
     
Thread Status:
Not open for further replies.

Share This Page