Solved Error splitting up Teams

Discussion in 'Plugin Development' started by TheCraftGamer, Aug 10, 2013.

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

    TheCraftGamer

    Hey there,

    I am trying to put the Players into different teams but I am getting the following error:

    Code:java
    1. 2013-08-10 19:56:54 [SEVERE] Could not pass event PlayerJoinEvent to HeartBattle v1.0
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    4. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    5. at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    6. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
    7. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
    8. at net.minecraft.server.v1_6_R2.PlayerList.c(PlayerList.java:208)
    9. at net.minecraft.server.v1_6_R2.PlayerList.a(PlayerList.java:104)
    10. at net.minecraft.server.v1_6_R2.PendingConnection.e(PendingConnection.java:135)
    11. at net.minecraft.server.v1_6_R2.PendingConnection.d(PendingConnection.java:48)
    12. at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:132)
    13. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:592)
    14. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:239)
    15. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:481)
    16. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:413)
    17. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    18. Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    19. at java.util.ArrayList.rangeCheck(ArrayList.java:604)
    20. at java.util.ArrayList.get(ArrayList.java:382)
    21. at de.fabian3355.heartbattle.Phase1.Phase1_Start(Phase1.java:88)
    22. at de.fabian3355.heartbattle.Events.Join(Events.java:68)
    23. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    24. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    25. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    26. at java.lang.reflect.Method.invoke(Method.java:601)
    27. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    28. ... 14 more


    The Code is the following:
    Code:java
    1. List<String> players = new ArrayList<>();
    2. for (Player player : Bukkit.getOnlinePlayers()) {
    3. players.add(player.getName());
    4. }
    5.  
    6. Collections.shuffle(players);
    7.  
    8. int Teamgroesse = Bukkit.getOnlinePlayers().length / 4;
    9. int team = 1;
    10. int Spielerzahl = 1;
    11. while (team < 5) {
    12.  
    13. for (int x = 1; x <= Teamgroesse; x++) {
    14.  
    15. Main.Team.put(players.get(x), team);
    16. players.remove(x);
    17. Spielerzahl++;
    18. x--;
    19. }
    20.  
    21. team++;
    22. }


    Any ideas what I'm doing wrong? Or any ideas how to solve this problem?
    Thanks
     
  2. Offline

    caseif

  3. Offline

    Firefly

    TheCraftGamer


    You're starting your for loop from the index 1 rather than 0 and then trying to access an element at index 1 when there is none. Change your for loop so that it starts iterating at index 0 and stops when x is less than (not less than or equal to) your other variable.

    Edit: Also remove 'x--' that's counter-intuitive since the for-loop increases the value of x each time it iterates.

    Edit 2: Quoted AngryNerd for some reason.
     
  4. Offline

    TheCraftGamer

    Firefly Thank you so much!! Finally solved this problem. Still can't believe it!
     
Thread Status:
Not open for further replies.

Share This Page