Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to teleport a player in a task.

Comments in 'Plugin Development' started by AndrewBit, Oct 20, 2015.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    How I can teleport a player in a repeatingTask?
    I'm trying to save in my main class the player.

    I'm using this:

    *at the top of my main class:
    PHP:
    public $player ""
    And next, in another function:

    PHP:
    $playerName $player->getName();
    $this->player $server->getPlayer($playerName);
    *it's inside a switch.

    $player is defined as $this->getServer()->getPlayer() and $server is defined as $this->getServer().

    I add this to my task:
    PHP:
    $this->plugin->player->teleport(new Position(x,y,z,$map));
    But PHPStorm returns me:
    "Method teleport() not found in class string" ;_;
    Last edited: Oct 20, 2015
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I write "Postion" by a error lol, but in my plugin I didn't add "Postion".

    And I can't send the full code, it's a private plugin :p
  3. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    $this->player->teleport(new Position(x,y,z,$map));
    This needs OOP.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    why you get string from player object to get player object instead using it?
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why don't you define the Player in the Task itself in __construct()?
    Taha_The_Hacker likes this.
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    public $player
    public $task

    public function task($event){
          
    $player $event->getPlayer();
              
    $this->task $this->getServer()->getScheduler()->scheduleRepeatingTask(new FILE($this$player), /*TIME*/)->getTaskId();// added $player
    }
    __construct() in timer file :
    PHP:
      public function __construct(/*Main File name*/ $plugin$player){
        
    $this->plugin $plugin;
         
    $this->player $player;
        
    parent::__construct($plugin);
      }
    PHP:
    public function onRun(){
    $this->player->teleport(new Position(x,y,z,$map));
    }
    SeifValkierks likes this.
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    PHP:
    public $player//Semicolons:P
    public $task// ^


              
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new FILE($this$player), /*TIME*/);// Why should you need a function to run the timer?

    __construct() in timer file :
    PHP:
      public function __construct(/*Main File name*/ $pluginPlayer $player){ // I would actually only allow it if $player instanceof Player, as it otherwise could give you errors when tping if you put a string or whatever
        
    $this->plugin $plugin;
         
    $this->player $player;
        
    parent::__construct($plugin);
      }
    PHP:
    public function onRun($currenttick){ 
    $this->player->teleport(new Position($x,$y,$z,$map));//$x, $y $z also are variables, ofc they need to be defined first
    }
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    public $player = "";

    So you expect $plugin->player to be a string?
    CraftYourBukkit and jojoe77777 like this.

Share This Page

Advertisement