Solved [Help] how to make a variable that represent every player?

Discussion in 'Plugin Development' started by Cheesepro, Aug 25, 2014.

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

    Cheesepro

    So since [ Player player = (Player) sender; ] this line will set the sender to variable "player" so is there a line that will set every player to variable "everyone" ?

    Because This is what I'm trying to do...
    Code:java
    1. PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(playername, false, 0);
    2. ((CraftPlayer) the_variable_that_represent_everyone ).getHandle().playerConnection.sendPacket(packet);
     
  2. Offline

    Gerov

    Cheesepro Make a Player[] array, and get all the players from the server.
     
  3. Offline

    Zupsub

    You should definitely learn java, before programming with bukkit or even nms/ProtocolLib.

    Just a hint: No, there isn't such a variable. Loop through all players instead.
     
  4. Offline

    Rocoty

    Cheesepro A variable can never represent more than one object. What this means is that you cannot have a variable reference all players at once. What you can do is have a variable refer to a Collection or array containing all players.
     
  5. Offline

    Cheesepro

    This line doesn't seemed to work...
    Code:java
    1. Player[] onlineplayers = getServer().getOnlinePlayers();

    in this part of code:
    Code:java
    1. ((CraftPlayer) onlineplayers).getHandle().playerConnection.sendPacket(packet);

    It said "can not cast Player[] to CraftPlayer"
     
  6. Offline

    Zupsub

    If already said all that is need to say:
     
  7. Offline

    Cheesepro

    Zupsub
    but if I do this
    Code:
    for(Player onlineplayers : Bukkit.getServer().getOnlinePlayers()) {
     
    }
    how am I gona put it in this?
    Code:
    ((CraftPlayer) onlineplayers).getHandle().playerConnection.sendPacket(packet);
    IT will work if I do this?
    Code:
    for(Player onlineplayers : Bukkit.getServer().getOnlinePlayers()) {
    ((CraftPlayer) onlineplayers).getHandle().playerConnection.sendPacket(packet);
    }
     
  8. Offline

    jimbo8

    Put them in a hashmap or a list.
     
  9. Offline

    Zupsub

    What's wrong with his current solution?
     
Thread Status:
Not open for further replies.

Share This Page