MobArena Hook, list players? Collection to Array??

Discussion in 'Plugin Development' started by LegacyGaming, Oct 31, 2014.

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

    LegacyGaming

    I have made a mob arena hook, of which i need to get the players in a specific arena. I need this in the form of an array but with the hook its in a collection.
    Code:java
    1. @EventHandler
    2. public void Reward_1(NewWaveEvent event) {
    3. int Wave = event.getWaveNumber();
    4. Collection<Player> Players = event.getArena().getAllPlayers();
    5. File Config = new File("./Plugins/RCP/config.yml");
    6. YamlConfiguration LoadConfig = YamlConfiguration.loadConfiguration(Config);
    7. int CW = LoadConfig.getInt("Reward_1-Waves");
    8. int CR = LoadConfig.getInt("Reward_1-Reward");
    9. if (Wave % CW == 0) {
    10. <Function Here>
    11. }
    12. }

    I have looked at a few ways of converting a collection to an array, they gave me errors in the console. Am i missing something with that?
     
  2. Offline

    teej107

  3. Offline

    LegacyGaming

    Yeah, that's the one i already tried...
     
  4. Offline

    teej107

    LegacyGaming Show your code. I've tried it and it does work.
     
  5. Offline

    LegacyGaming

    If that is correct, would it be:
    Code:java
    1. String[] Player = Players.toArray (new String[Players.size ()]);

    With the code from the top
     
  6. Offline

    teej107

  7. Offline

    LegacyGaming

    Here is my code with that addition:
    Code:java
    1. @EventHandler
    2. public void Reward_1(NewWaveEvent event) {
    3. int Wave = event.getWaveNumber();
    4. Collection<Player> Players = event.getArena().getAllPlayers();
    5. String[] Player = Players.toArray(new String[Players.size ()]);
    6. File Config = new File("./Plugins/RCP/config.yml");
    7. YamlConfiguration LoadConfig = YamlConfiguration.loadConfiguration(Config);
    8. int CW = LoadConfig.getInt("Reward_1-Waves");
    9. int CR = LoadConfig.getInt("Reward_1-Reward");
    10. if (Wave % CW == 0) {
    11. <function>
    12. }
    13. }

    I really don't get what you are saying. The "Player" statement should be able to be used as a string right? Its a list of players that i want to get from the arena, that's all.
     
  8. Offline

    teej107

    Players aren't Strings. Strings aren't Players
     
  9. Offline

    LegacyGaming

    That doesn't really help.
     
  10. Offline

    teej107

    LegacyGaming You are trying to add a collection of players to an array that only accepts String
     
  11. Offline

    LegacyGaming

    I want to convert a collection of players to an array. If that's not right then could you please help me with the code?
     
  12. Offline

    teej107

  13. Offline

    LegacyGaming

    So, like this?
    Code:java
    1. Player[] Player = Players.toArray(new Player[Players.size ()]);
     
  14. Offline

    teej107

  15. Offline

    LegacyGaming

    Thanks, i got it working. How would i make it give all users in that array an item or something, without repeating the code. If that is possible.
     
  16. Offline

    teej107

    LegacyGaming For-loops. Btw, you can iterate through collections using for loops. I don't know why you would be needing an array of players.
     
  17. Offline

    LegacyGaming

    Ok thanks :D
     
Thread Status:
Not open for further replies.

Share This Page