player and void

Discussion in 'Plugin Development' started by tschagg, Jan 20, 2013.

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

    tschagg

    hey guys, how i can import a Player, like args[0] to a void?

    Code:
                      public void run() {
                        //  how to define player ?
                          this.player.kickPlayer();
                      }
     
  2. Offline

    camyono

    You can't import something to "void". It tells you that there is no return value. If you want to have some arguments in the method you could do with: public void run( Player player )
     
  3. Offline

    Craftiii4

    Hm? do you mean like this?

    Code:
                      public void run(Player player) {
                          player.kickPlayer();
                      }
     
    tschagg likes this.
  4. Offline

    ImDeJay

    i know the problem your having and what you need to do is make your Player import a final

    like

    Code:
    final Player player = (Player) sender;
     
  5. Offline

    tschagg

    hm i got errors when i make (Player player)...

    Code:
                      plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                        @Override
                      public void run() {
                          this.player.kickPlayer();
                      }
                    }, 80L);
     
  6. Offline

    Craftiii4

    Why are you placing that code within an delayed task? You also failed to register the player within the brackets.
     
  7. Offline

    tschagg

    yeah thats what i ask, how to register the player in this void.
    i want a 4 sec delayed kick... like /kick2 <Player>
     
  8. Offline

    camyono

    remove the "this."

    Edit: Btw: it dont need to be final.
     
  9. Offline

    tschagg

    dont work without this...
    i fixed it a other way, i made a seperate command to it, bcause "Bukkit.dispatchCommand(Bukkit.getConsoleSender()" is workin in that void :)

    thanks for the help!
     
  10. Offline

    camyono

    No it won't work!

    Code:java
    1.  
    2. public class MyClass {
    3.  
    4. public Player player; // Here is no final "needed"
    5.  
    6. ...
    7.  
    8. public void myMethod() {
    9.  
    10. plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    11.  
    12. @Override
    13. public void run() {
    14. player.kickPlayer(); // You cannot work with "this" here to make a reference to MyClass!!!!! You only will get methods from Runnable and Object!
    15. }
    16. }, 80L);
    17.  
    18. }
    19.  
    20. }
    21.  


    You should learn inheritance and visibility of classes and its fields and methods
     
    tschagg likes this.
  11. Offline

    tschagg

    ok, thank you so much!
     
  12. Offline

    fireblast709

    why are people creating a Player field...
     
  13. Offline

    ImDeJay

    im trying to tell you to do this.

    Code:
    final Player player = (Player) sender;
     
     
    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                 @Override
               public void run() {
                   player.kickPlayer("test");
               }
             }, 80L);
     
Thread Status:
Not open for further replies.

Share This Page