"Can't invoke" help

Discussion in 'Plugin Development' started by glasseater, Nov 25, 2015.

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

    glasseater

    Hey everyone,

    I have a question. It might sound a bit nooby, but I'm trying to expand my knowledge on for loops.
    I am having this bug.
    I have this here:

    Code:
    Player[] onlinePlayers1 = Bukkit.getOnlinePlayers().toArray(new Player[Bukkit.getOnlinePlayers().size()]); {
                         Player[] player = onlinePlayers1;
    No errors there. However when I use "player" I get errors.
    For example at "player.getName()" it says
    "Cannot invoke getName() on the array type Player[]"

    At "player.hasPermission()"
    it says
    "Cannot invoke hasPermission(String) on the array type Player[]"

    How can I go about fixing this? Sorry if this sounds a big nooby :p

    - Glass
     
  2. Offline

    teej107

    @glasseater You are trying to invoke the method on the Array object itself. Anyways what's the point of your code? I am positive there is a better way to achieve what you are trying to do.
     
  3. Offline

    glasseater

    @teej107
    I'm setting a players particle effect inside a runnable. Please let me know if there is a better way to do this! I'm sorry I do not really understand how to make it so it doesn't invoke on the array?
     
  4. Offline

    teej107

  5. Offline

    glasseater

    @teej107
    Just setting one players particle, but for everyone on the server to see.
     
  6. Offline

    teej107

    I still don't quite understand. Are you having particles only on one player? Perhaps you should post what you have tried first. Or attempt something if nothing was attempted yet.
     
  7. Offline

    glasseater

    @teej107
    Yes only on the player who selects the particle effect.

    Heres what I have tried.
    Code:
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                double i = 0.0;
                double newY;
             
                @Override
                public void run() {
    
                    final double slice = 6.283185307179586 / points;
                    final double slice2 = 6.283185307179586 / (points * 2.5);
    Player[] onlinePlayers1 = Bukkit.getOnlinePlayers().toArray(new Player[Bukkit.getOnlinePlayers().size()]);                     Player[] player = onlinePlayers1;
                        final Player player = onlinePlayers1;
                        if (Particle.this.LavaPopperz.contains(player.getName()) && player.hasPermission("particle.lavapop")) {
     
  8. Offline

    rbrick

  9. Offline

    glasseater

    @rbrick
    I posted the wrong bit of code that's my fault. This still may be wrong but is it for the same reason?

    Code:
     Player[] onlinePlayers = Bukkit.getOnlinePlayers().toArray(new Player[Bukkit.getOnlinePlayers().size()]); {
         Player[] p = onlinePlayers;
    //Other code here
                
     
  10. Offline

    Chloe-chan

    I don't quite understand what you are trying to do, but I'll try to help out.
    1. The method
      Code:
      Bukkit.getOnlinePlayers()
      returns a collection of Player objects, which you do not need to turn them into an array. Simply use the the methods provided by the Collection.
    2. You are assigning a variable to another variable, which is redundant. I guess you are trying to find a particular player from the server ?
    3. If you are simply playing particle effects on a player, it should be played to the nearby players too. There is not a need for you to handle the visibility of the particles.
     
    rbrick likes this.
  11. Offline

    glasseater

    @Chloe-chan
    But then how would I define p/player? Because now im using Player[] player = onlinePlayers (which if I um understand correctly, thats where I am wrong. If I am correct with that bing wrong, how would I define the player?
     
  12. Offline

    Scimiguy

    for (Player p : Bukkit.getOnlinePlayers)
     
  13. Offline

    Chloe-chan

    Are you trying to find a particular player?
    If so, you can try
    Code:
    Bukkit.getPlayer("Notch");
    to get the player with name "Notch". NOTE: It is recommended to use UUID instead of player name.



    Are you trying to loop every player online ?
     
Thread Status:
Not open for further replies.

Share This Page