Solved Sorting a list / Indexing problems

Discussion in 'Plugin Development' started by CoderMusgrove, Dec 29, 2013.

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

    CoderMusgrove

    I have been following a tutorial by xTrollxDudex on how to make a minigame. I have ran into a couple complications while making it, and I have fixed all except for one, as far as I know. xTrollxDudex did indeed help me fix a couple of them, and there is one problem I cannot fix.

    The last issue that I am currently encountering is when creating arenas. Say I have this as my arenas.yml file:
    Code:
    arena:
      '1': world, 0, 0, 0
      '2': world, 0, 0, 0
      '3': world, 0, 0, 0
     
    arenas:
    - 1
    - 2
    - 3
    And I remove arena 2:
    Code:
    arena:
      '1': world, 0, 0, 0
      '3': world, 0, 0, 0
     
    arenas:
    - 1
    - 3
    I want to fill the gaps for this, so I have an indexer checking as if each arena is in order, so it will fill up. Each time I create an arena, I will sort the list so the indexer doesn't mess up, and as well so the arenas.yml is well organized. I can recreate arena 2, but the arena list does not get sorted, but the arenas list does (recognize the plural), so it will look like this:
    Code:
    arena:
      '1': world, 0, 0, 0
      '3': world, 0, 0, 0
      '2': world, 0, 0, 0 // this needs to move up one
     
    arenas:
    - 1
    - 2
    - 3
    I use Collections.sort(arenas) when sorting the arenas integer list. I have tried the same thing for the arena list, but what it actually does is it converts it into an array, and completely empties it.

    I'm sorry, there may be a very easy solution to this, which I expect, but I cannot figure out how to sort the arena list in order by their key. How do I sort the arena list by their key?
     
  2. Offline

    BillyGalbreath

    You cannot reorder items in yml that I'm aware of. The newest entries will always go to the end. If you're that worried about it you could try deleting the entire file, clearing the config memory, then rebuilding it again with the sorted list. But I dont know if that will even work.
     
  3. Offline

    CoderMusgrove

    The only way I have been able to think of it is setting the arena list into some sort of list, sorting it somehow, and then setting the values for arena.
     
  4. Offline

    xTrollxDudex

    CoderMusgrove
    I found a solution; you can do
    PHP:
    Collections.sort(arenas, new Comparator<Arena>() {
        @
    Override 
        
    public int compare(Arena aArena b) {
            return 
    a.getId() - b.getId();
        }
    }
     
    CoderMusgrove likes this.
  5. Offline

    CoderMusgrove

    I have one more issue I would like to address, it has to deal with indexing, and I have no idea why it's doing this. So when I create an arena, and I have a skipped part (list: 1, 3;) I would like to add the missing number, if I just have 3 numbers, this indexer will work fine to find the missing number. Say I have this list:

    Code:
    arena:
      '1': world, 0, 0, 0
      '2': world, 0, 0, 0
      '3': world, 0, 0, 0
     
    arenas:
    - 1
    - 2
    - 3
    If I remove 2 from this list, and type /arena create it will be the same like that again. Now when I get to over three numbers in the list:
    Code:
    arena:
      '1': world, 0, 0, 0
      '2': world, 0, 0, 0
      '3': world, 0, 0, 0
      '4': world, 0, 0, 0
     
    arenas:
    - 1
    - 2
    - 3
    - 4
    And I remove 2, making the list look like this:
    Code:
    arena:
      '1': world, 0, 0, 0 // no more 2
      '3': world, 0, 0, 0
      '4': world, 0, 0, 0
     
    arenas:
    - 1
    - 3
    - 4
    Once again, I type /arena create it should recreate 2, but instead it just overwrites 3, and makes it look like this:
    Code:
    arena:
      '1': world,0,0,0
      '3': world,0,0,0
      '4': world,0,0,0
    arenas:
    - 1
    - 3
    - 3
    - 4
    
    My for loop in the createArena method in my ArenaManager class that is supposed to handle filling in the empty slots:
    Code:
    for (int i = 0; i < arenas.size(); i++)
        if (i + 1 != arenas.get(i).getId()) num = i + 1;
    If you feel like viewing all of the code of my ArenaManager class: http://pastebin.com/FNEwfL76

    Now, I did a debug test to see what's going on with the values. So here is a console log of everything when I first start creating arenas:

    PHP:
    [09:18:29 INFO]: CONSOLEReload complete.
    [
    09:18:32 INFO]: Shzylo issued server command: /arena create
    [09:18:39 INFO]: Shzylo issued server command: /arena create
    [09:18:39 INFO]: i1
    [09:18:39 INFO]: id1
    [09:18:41 INFO]: Shzylo issued server command: /arena create
    [09:18:41 INFO]: i1
    [09:18:41 INFO]: id1
    [09:18:41 INFO]: i2
    [09:18:41 INFO]: id2
    [09:18:42 INFO]: Shzylo issued server command: /arena create
    [09:18:42 INFO]: i1
    [09:18:42 INFO]: id1
    [09:18:42 INFO]: i2
    [09:18:42 INFO]: id2
    [09:18:42 INFO]: i3
    [09:18:42 INFO]: id3
    [09:18:54 INFO]: Shzylo issued server command: /arena remove 2
    [09:19:03 INFO]: Shzylo issued server command: /arena create
    [09:19:03 INFO]: i1
    [09:19:03 INFO]: id1
    [09:19:03 INFO]: i2
    [09:19:03 INFO]: id3
    [09:19:03 INFO]: i3
    [09:19:03 INFO]: id4
    After I first remove 2 from the list, I see on the second part that the index i + 1 is not equal to the current id, so it should have created the arena there, but I don't know why. How would I fix this?
     
  6. Offline

    xTrollxDudex

    CoderMusgrove
    Remove "arenaSize--;" from the removeArena method, that should fix it.
     
  7. Offline

    CoderMusgrove

    xTrollxDudex it didn't change the outcome at all, so removing that line didn't help.
     
  8. Offline

    xTrollxDudex

  9. Offline

    CoderMusgrove

    xTrollxDudex Yes, but just to clarify, I stopped my localhost server, deleted the files relevant to the plugin, made sure everything was exporting correctly in eclipse. After all of that, I started up the server and tried again. It still does the same, which is fail.
     
  10. Offline

    xTrollxDudex

  11. Offline

    CoderMusgrove

    I don't see what incrementing arenaSize within the removeArena method will do, it doesn't even interfere with the for loop. I'll give it a go though.

    EDIT:
    After testing this, I kind of need the arenaSize-- to be there..

    Update

    I was doing further testing into this, and I saw if I have this in my integer list:
    Code:
    arenas:
    - 1
    - 3
    - 3
    - 4
    
    It will create 2, so obviously there is a pretty bad indexing problem somehow, but exactly how is my indexer wrong?
    Code:
    for (int i = 0; i < arenas.size(); i++)
        if (i + 1 != arenas.get(i).getId()) num = i + 1;
    
    I have found no problems with this, but I will do further testing, wish me luck.

    Further testing, here is a full console log; the integer j is equal to i + 1:
    PHP:
    [00:18:34 INFO]: arenaSize:1
    [00:18:34 INFO]: arenas.size:0
    [00:18:34 INFO]: num:1
    [00:18:34 INFO]: num:1
    [00:18:34 INFO]: arenas.size:1
    [00:18:35 INFO]: Shzylo issued server command: /arena create
    [00:18:35 INFO]: arenaSize:2
    [00:18:35 INFO]: arenas.size:1
    [00:18:35 INFO]: num:2
    [00:18:35 INFO]: i:0  |  j:1  |  ID:1
    [00:18:35 INFO]: EQUAL i:0/j:1ID:1
    [00:18:35 INFO]: j:1
    [00:18:35 INFO]: num:2
    [00:18:35 INFO]: arenas.size:2
    [00:18:36 INFO]: Shzylo issued server command: /arena create
    [00:18:36 INFO]: arenaSize:3
    [00:18:36 INFO]: arenas.size:2
    [00:18:36 INFO]: num:3
    [00:18:36 INFO]: i:0  |  j:1  |  ID:1
    [00:18:36 INFO]: EQUAL i:0/j:1ID:1
    [00:18:36 INFO]: j:1
    [00:18:36 INFO]: i:1  |  j:2  |  ID:2
    [00:18:36 INFO]: EQUAL i:1/j:2ID:2
    [00:18:36 INFO]: j:2
    [00:18:36 INFO]: num:3
    [00:18:36 INFO]: arenas.size:3
    [00:18:39 INFO]: Shzylo issued server command: /arena remove 2
    [00:18:41 INFO]: Shzylo issued server command: /arena create
    [00:18:41 INFO]: arenaSize:3
    [00:18:41 INFO]: arenas.size:2
    [00:18:41 INFO]: num:3
    [00:18:41 INFO]: i:0  |  j:1  |  ID:1
    [00:18:41 INFO]: EQUAL i:0/j:1ID:1
    [00:18:41 INFO]: j:1
    [00:18:41 INFO]: i:1  |  j:2  |  ID:3
    [00:18:41 INFO]: NOT EQUAL i:1/j:2ID:3
    [00:18:41 INFO]: j:2
    [00:18:41 INFO]: num:2
    [00:18:41 INFO]: arenas.size:3
    [00:18:42 INFO]: Shzylo issued server command: /arena create
    [00:18:42 INFO]: arenaSize:4
    [00:18:42 INFO]: arenas.size:3
    [00:18:42 INFO]: num:4
    [00:18:42 INFO]: i:0  |  j:1  |  ID:1
    [00:18:42 INFO]: EQUAL i:0/j:1ID:1
    [00:18:42 INFO]: j:1
    [00:18:42 INFO]: i:1  |  j:2  |  ID:2
    [00:18:42 INFO]: EQUAL i:1/j:2ID:2
    [00:18:42 INFO]: j:2
    [00:18:42 INFO]: i:2  |  j:3  |  ID:3
    [00:18:42 INFO]: EQUAL i:2/j:3ID:3
    [00:18:42 INFO]: j:3
    [00:18:42 INFO]: num:4
    [00:18:42 INFO]: arenas.size:4
    [00:18:57 INFO]: Shzylo issued server command: /reload
    [00:18:57 INFO]: [McMurdererDisabling McMurderer vBETA
    [00:18:57 INFO]: [McMurdererMcMurderer has stopped successfully!
    [
    00:18:57 INFO]: [McMurdererLoading McMurderer vBETA
    [00:18:57 INFO]: [McMurdererEnabling McMurderer vBETA
    [00:18:57 INFO]: [McMurdererMcMurderer has started successfully!
    [
    00:18:57 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:18:57 INFO]: ShzyloReload complete.
    [
    00:18:57 INFO]: Shzylo issued server command: /reload
    [00:18:57 INFO]: [McMurdererDisabling McMurderer vBETA
    [00:18:57 INFO]: [McMurdererMcMurderer has stopped successfully!
    [
    00:18:57 INFO]: [McMurdererLoading McMurderer vBETA
    [00:18:57 INFO]: [McMurdererEnabling McMurderer vBETA
    [00:18:57 INFO]: [McMurdererMcMurderer has started successfully!
    [
    00:18:57 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:18:58 INFO]: ShzyloReload complete.
    [
    00:19:09 INFO]: Shzylo issued server command: /reload
    [00:19:09 INFO]: [McMurdererDisabling McMurderer vBETA
    [00:19:09 INFO]: [McMurdererMcMurderer has stopped successfully!
    [
    00:19:09 INFO]: [McMurdererLoading McMurderer vBETA
    [00:19:09 INFO]: [McMurdererEnabling McMurderer vBETA
    [00:19:09 INFO]: [McMurdererMcMurderer has started successfully!
    [
    00:19:09 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:19:09 INFO]: ShzyloReload complete.
    [
    00:19:10 INFO]: Shzylo issued server command: /arena create
    [00:19:10 INFO]: arenaSize:1
    [00:19:10 INFO]: arenas.size:0
    [00:19:10 INFO]: num:1
    [00:19:10 INFO]: num:1
    [00:19:10 INFO]: arenas.size:1
    [00:19:11 INFO]: Shzylo issued server command: /arena create
    [00:19:11 INFO]: arenaSize:2
    [00:19:11 INFO]: arenas.size:1
    [00:19:11 INFO]: num:2
    [00:19:11 INFO]: i:0  |  j:1  |  ID:1
    [00:19:11 INFO]: EQUAL i:0/j:1ID:1
    [00:19:11 INFO]: j:1
    [00:19:11 INFO]: num:2
    [00:19:11 INFO]: arenas.size:2
    [00:19:12 INFO]: Shzylo issued server command: /arena create
    [00:19:12 INFO]: arenaSize:3
    [00:19:12 INFO]: arenas.size:2
    [00:19:12 INFO]: num:3
    [00:19:12 INFO]: i:0  |  j:1  |  ID:1
    [00:19:12 INFO]: EQUAL i:0/j:1ID:1
    [00:19:12 INFO]: j:1
    [00:19:12 INFO]: i:1  |  j:2  |  ID:2
    [00:19:12 INFO]: EQUAL i:1/j:2ID:2
    [00:19:12 INFO]: j:2
    [00:19:12 INFO]: num:3
    [00:19:12 INFO]: arenas.size:3
    [00:19:12 INFO]: Shzylo issued server command: /arena create
    [00:19:12 INFO]: arenaSize:4
    [00:19:12 INFO]: arenas.size:3
    [00:19:12 INFO]: num:4
    [00:19:12 INFO]: i:0  |  j:1  |  ID:1
    [00:19:12 INFO]: EQUAL i:0/j:1ID:1
    [00:19:12 INFO]: j:1
    [00:19:12 INFO]: i:1  |  j:2  |  ID:2
    [00:19:12 INFO]: EQUAL i:1/j:2ID:2
    [00:19:12 INFO]: j:2
    [00:19:12 INFO]: i:2  |  j:3  |  ID:3
    [00:19:12 INFO]: EQUAL i:2/j:3ID:3
    [00:19:12 INFO]: j:3
    [00:19:12 INFO]: num:4
    [00:19:12 INFO]: arenas.size:4
    [00:19:14 INFO]: Shzylo issued server command: /arena create
    [00:19:14 INFO]: arenaSize:5
    [00:19:14 INFO]: arenas.size:4
    [00:19:14 INFO]: num:5
    [00:19:14 INFO]: i:0  |  j:1  |  ID:1
    [00:19:14 INFO]: EQUAL i:0/j:1ID:1
    [00:19:14 INFO]: j:1
    [00:19:14 INFO]: i:1  |  j:2  |  ID:2
    [00:19:14 INFO]: EQUAL i:1/j:2ID:2
    [00:19:14 INFO]: j:2
    [00:19:14 INFO]: i:2  |  j:3  |  ID:3
    [00:19:14 INFO]: EQUAL i:2/j:3ID:3
    [00:19:14 INFO]: j:3
    [00:19:14 INFO]: i:3  |  j:4  |  ID:4
    [00:19:14 INFO]: EQUAL i:3/j:4ID:4
    [00:19:14 INFO]: j:4
    [00:19:14 INFO]: num:5
    [00:19:14 INFO]: arenas.size:5
    [00:19:17 INFO]: Shzylo issued server command: /arena remove 3
    [00:19:19 INFO]: Shzylo issued server command: /arena create
    [00:19:19 INFO]: arenaSize:5
    [00:19:19 INFO]: arenas.size:4
    [00:19:19 INFO]: num:5
    [00:19:19 INFO]: i:0  |  j:1  |  ID:1
    [00:19:19 INFO]: EQUAL i:0/j:1ID:1
    [00:19:19 INFO]: j:1
    [00:19:19 INFO]: i:1  |  j:2  |  ID:2
    [00:19:19 INFO]: EQUAL i:1/j:2ID:2
    [00:19:19 INFO]: j:2
    [00:19:19 INFO]: i:2  |  j:3  |  ID:4
    [00:19:19 INFO]: NOT EQUAL i:2/j:3ID:4
    [00:19:19 INFO]: j:3
    [00:19:19 INFO]: i:3  |  j:4  |  ID:5
    [00:19:19 INFO]: NOT EQUAL i:3/j:4ID:5
    [00:19:19 INFO]: j:4
    [00:19:19 INFO]: num:4
    [00:19:19 INFO]: arenas.size:5
    [00:19:22 INFO]: Shzylo issued server command: /arena create
    [00:19:22 INFO]: arenaSize:6
    [00:19:22 INFO]: arenas.size:5
    [00:19:22 INFO]: num:6
    [00:19:22 INFO]: i:0  |  j:1  |  ID:1
    [00:19:22 INFO]: EQUAL i:0/j:1ID:1
    [00:19:22 INFO]: j:1
    [00:19:22 INFO]: i:1  |  j:2  |  ID:2
    [00:19:22 INFO]: EQUAL i:1/j:2ID:2
    [00:19:22 INFO]: j:2
    [00:19:22 INFO]: i:2  |  j:3  |  ID:4
    [00:19:22 INFO]: NOT EQUAL i:2/j:3ID:4
    [00:19:22 INFO]: j:3
    [00:19:22 INFO]: i:3  |  j:4  |  ID:4
    [00:19:22 INFO]: EQUAL i:3/j:4ID:4
    [00:19:22 INFO]: j:4
    [00:19:22 INFO]: i:4  |  j:5  |  ID:5
    [00:19:22 INFO]: EQUAL i:4/j:5ID:5
    [00:19:22 INFO]: j:5
    [00:19:22 INFO]: num:3
    [00:19:22 INFO]: arenas.size:6
    [00:19:25 INFO]: Shzylo issued server command: /arena create
    [00:19:25 INFO]: arenaSize:7
    [00:19:25 INFO]: arenas.size:6
    [00:19:25 INFO]: num:7
    [00:19:25 INFO]: i:0  |  j:1  |  ID:1
    [00:19:25 INFO]: EQUAL i:0/j:1ID:1
    [00:19:25 INFO]: j:1
    [00:19:25 INFO]: i:1  |  j:2  |  ID:2
    [00:19:25 INFO]: EQUAL i:1/j:2ID:2
    [00:19:25 INFO]: j:2
    [00:19:25 INFO]: i:2  |  j:3  |  ID:3
    [00:19:25 INFO]: EQUAL i:2/j:3ID:3
    [00:19:25 INFO]: j:3
    [00:19:25 INFO]: i:3  |  j:4  |  ID:4
    [00:19:25 INFO]: EQUAL i:3/j:4ID:4
    [00:19:25 INFO]: j:4
    [00:19:25 INFO]: i:4  |  j:5  |  ID:4
    [00:19:25 INFO]: NOT EQUAL i:4/j:5ID:4
    [00:19:25 INFO]: j:5
    [00:19:25 INFO]: i:5  |  j:6  |  ID:5
    [00:19:25 INFO]: NOT EQUAL i:5/j:6ID:5
    [00:19:25 INFO]: j:6
    [00:19:25 INFO]: num:6
    [00:19:25 INFO]: arenas.size:7
    >reload
    [00:19:42 INFO]: [McMurdererDisabling McMurderer vBETA
    [00:19:42 INFO]: [McMurdererMcMurderer has stopped successfully!
    [
    00:19:42 INFO]: [McMurdererLoading McMurderer vBETA
    [00:19:42 INFO]: [McMurdererEnabling McMurderer vBETA
    [00:19:42 INFO]: [McMurdererMcMurderer has started successfully!
    [
    00:19:42 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:19:42 INFO]: CONSOLEReload complete.
    [
    00:19:47 INFO]: Shzylo issued server command: /reload
    [00:19:47 INFO]: [McMurdererDisabling McMurderer vBETA
    [00:19:47 INFO]: [McMurdererMcMurderer has stopped successfully!
    [
    00:19:47 INFO]: [McMurdererLoading McMurderer vBETA
    [00:19:47 INFO]: [McMurdererEnabling McMurderer vBETA
    [00:19:47 INFO]: [McMurdererMcMurderer has started successfully!
    [
    00:19:47 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [00:19:47 INFO]: ShzyloReload complete.
    [
    00:19:49 INFO]: Shzylo issued server command: /arena create
    [00:19:49 INFO]: arenaSize:1
    [00:19:49 INFO]: arenas.size:0
    [00:19:49 INFO]: num:1
    [00:19:49 INFO]: num:1
    [00:19:49 INFO]: arenas.size:1
    [00:19:49 INFO]: Shzylo issued server command: /arena create
    [00:19:49 INFO]: arenaSize:2
    [00:19:49 INFO]: arenas.size:1
    [00:19:49 INFO]: num:2
    [00:19:49 INFO]: i:0  |  j:1  |  ID:1
    [00:19:49 INFO]: EQUAL i:0/j:1ID:1
    [00:19:49 INFO]: j:1
    [00:19:49 INFO]: num:2
    [00:19:49 INFO]: arenas.size:2
    [00:19:54 INFO]: Shzylo issued server command: /arena create
    [00:19:54 INFO]: arenaSize:3
    [00:19:54 INFO]: arenas.size:2
    [00:19:54 INFO]: num:3
    [00:19:54 INFO]: i:0  |  j:1  |  ID:1
    [00:19:54 INFO]: EQUAL i:0/j:1ID:1
    [00:19:54 INFO]: j:1
    [00:19:54 INFO]: i:1  |  j:2  |  ID:2
    [00:19:54 INFO]: EQUAL i:1/j:2ID:2
    [00:19:54 INFO]: j:2
    [00:19:54 INFO]: num:3
    [00:19:54 INFO]: arenas.size:3
    [00:19:55 INFO]: Shzylo issued server command: /arena create
    [00:19:55 INFO]: arenaSize:4
    [00:19:55 INFO]: arenas.size:3
    [00:19:55 INFO]: num:4
    [00:19:55 INFO]: i:0  |  j:1  |  ID:1
    [00:19:55 INFO]: EQUAL i:0/j:1ID:1
    [00:19:55 INFO]: j:1
    [00:19:55 INFO]: i:1  |  j:2  |  ID:2
    [00:19:55 INFO]: EQUAL i:1/j:2ID:2
    [00:19:55 INFO]: j:2
    [00:19:55 INFO]: i:2  |  j:3  |  ID:3
    [00:19:55 INFO]: EQUAL i:2/j:3ID:3
    [00:19:55 INFO]: j:3
    [00:19:55 INFO]: num:4
    [00:19:55 INFO]: arenas.size:4
    [00:20:14 INFO]: Shzylo issued server command: /arena create
    [00:20:14 INFO]: arenaSize:5
    [00:20:14 INFO]: arenas.size:4
    [00:20:14 INFO]: num:5
    [00:20:14 INFO]: i:0  |  j:1  |  ID:1
    [00:20:14 INFO]: EQUAL i:0/j:1ID:1
    [00:20:14 INFO]: j:1
    [00:20:14 INFO]: i:1  |  j:2  |  ID:2
    [00:20:14 INFO]: EQUAL i:1/j:2ID:2
    [00:20:14 INFO]: j:2
    [00:20:14 INFO]: i:2  |  j:3  |  ID:3
    [00:20:14 INFO]: EQUAL i:2/j:3ID:3
    [00:20:14 INFO]: j:3
    [00:20:14 INFO]: i:3  |  j:4  |  ID:4
    [00:20:14 INFO]: EQUAL i:3/j:4ID:4
    [00:20:14 INFO]: j:4
    [00:20:14 INFO]: num:5
    [00:20:14 INFO]: arenas.size:5
    [00:20:21 INFO]: Shzylo issued server command: /arena create
    [00:20:21 INFO]: arenaSize:6
    [00:20:21 INFO]: arenas.size:5
    [00:20:21 INFO]: num:6
    [00:20:21 INFO]: i:0  |  j:1  |  ID:1
    [00:20:21 INFO]: EQUAL i:0/j:1ID:1
    [00:20:21 INFO]: j:1
    [00:20:21 INFO]: i:1  |  j:2  |  ID:2
    [00:20:21 INFO]: EQUAL i:1/j:2ID:2
    [00:20:21 INFO]: j:2
    [00:20:21 INFO]: i:2  |  j:3  |  ID:3
    [00:20:21 INFO]: EQUAL i:2/j:3ID:3
    [00:20:21 INFO]: j:3
    [00:20:21 INFO]: i:3  |  j:4  |  ID:4
    [00:20:21 INFO]: EQUAL i:3/j:4ID:4
    [00:20:21 INFO]: j:4
    [00:20:21 INFO]: i:4  |  j:5  |  ID:5
    [00:20:21 INFO]: EQUAL i:4/j:5ID:5
    [00:20:21 INFO]: j:5
    [00:20:21 INFO]: num:6
    [00:20:21 INFO]: arenas.size:6
    And back to how I was using createArena:
    Code:java
    1. public Arena createArena(Location loc) {
    2. int num = arenaSize + 1;
    3. arenaSize++;
    4.  
    5. System.out.println();
    6. System.out.println("arenaSize:" + arenaSize);
    7. System.out.println("arenas.size:" + arenas.size());
    8. System.out.println("num:" + num);
    9.  
    10. for (int i = 0; i < arenas.size(); i++) {
    11. int j = i + 1;
    12. System.out.println("i:" + i + " | j:" + j + " | ID:" + arenas.get(i).getId());
    13. if (j != arenas.get(i).getId()) {
    14. System.out.println("NOT EQUAL @ i:" + i + "/j:" + j + "; ID:" + arenas.get(i).getId());
    15. num = j;
    16. } else System.out.println("EQUAL @ i:" + i + "/j:" + j + "; ID:" + arenas.get(i).getId());
    17. System.out.println("j:" + j);
    18. }
    19.  
    20. System.out.println("num:" + num);
    21.  
    22. setLastCreated(num);
    23.  
    24. Arena a = new Arena(loc, num);
    25. arenas.add(a);
    26. ArenaConfig.getConfig().set("arena." + num, serializeLoc(loc));
    27. List<Integer> list = ArenaConfig.getConfig().getIntegerList("arenas");
    28. list.add(num);
    29. ArenaConfig.getConfig().set("arenas", list);
    30. ArenaConfig.save();
    31. sortLists();
    32.  
    33. System.out.println("arenas.size:" + arenas.size());
    34.  
    35. return a;
    36. }


    And it completely cleared of all printing methods:
    Code:java
    1. public Arena createArena(Location loc) {
    2. int num = arenaSize + 1;
    3. arenaSize++;
    4.  
    5. for (int i = 0; i < arenas.size(); i++) {
    6. int j = i + 1;
    7. if (j != arenas.get(i).getId()) num = j;
    8. }
    9.  
    10. setLastCreated(num);
    11.  
    12. Arena a = new Arena(loc, num);
    13. arenas.add(a);
    14. ArenaConfig.getConfig().set("arena." + num, serializeLoc(loc));
    15. List<Integer> list = ArenaConfig.getConfig().getIntegerList("arenas");
    16. list.add(num);
    17. ArenaConfig.getConfig().set("arenas", list);
    18. ArenaConfig.save();
    19. sortLists();
    20.  
    21. return a;
    22. }


    I really don't understand my problem, all I know right now is it's how I check for the arena ID stuff, something messes up.

    SOLVED! SO MUCH TRIAL AND ERROR!
    After reviewing the printed statements, I saw this:
    Code:
    [00:19:19 INFO]: NOT EQUAL @ i:2/j:3; ID:4
    [00:19:19 INFO]: j:3
    [00:19:19 INFO]: i:3  |  j:4  |  ID:5
    [00:19:19 INFO]: NOT EQUAL @ i:3/j:4; ID:5
    Two instances of "Not Equal". This problem is solved by adding break;
    I need to touch up on my programming stuffs. :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page