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

how to cancel "You teleported to spawn"???

Comments in 'Plugin Development' started by Xenturio, Nov 13, 2014.

  1. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    how to cancel "You teleported to spawn"???

    i made a minigame but if u die u will be teleported automaticly to mainworld spawn.
    how to cancel this ?
    thebigsmileXD likes this.
  2. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    if i use this:

    public function onPlayerRespawnEvent(PlayerRespawnEvent $event)
    {
    if ($event->getPlayer()->getLevel()->getName() == in_array($event->getPlayer()->getLevel()->getName(), $this->config->get("Spielwelt")))
    {
    $event->setCancelled();
    }
    }

    then i get this error
    PocketMine-MP Crash Dump Thu Nov 13 13:06:14 UTC 2014

    Error: Event is not Cancellable
    File: /src/pocketmine/event/Event
    Line: 69
    Type: error

    Code:
    [60] /**
    [61] * @param bool $value
    [62] *
    [63] * @return bool
    [64] *
    [65] * @throws \BadMethodCallException
    [66] */
    [67] public function setCancelled($value = true){
    [68] if(!($this instanceof Cancellable)){
    [69] throw new \BadMethodCallException("Event is not Cancellable");
    [70] }
    [71] $this->isCancelled = (bool) $value;
    [72] }
    [73]
    [74] /**

    what can i do ?
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PlayerRespawnEvent cannot be cancelled.

    In other thinking, it is impossible to disallow player to click the respawn button.

    Change spawn position by setRespawnPosition().
  4. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    i cant because the minigame is on a other world xD and if u die u spawn back to mainworld

    i can teleport the player after death to the right position but after 1 second the game teleports the player to the server spawn point
  5. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    then create a script to teleport players back to the current level.
  6. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  7. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    stop, with the entitydeath event i can teleport the player to a current position.
    after that the game teleport me back to the world spawn.
    but how i get it after the last teleport tospawn? with lvl change event ^^?

    --edit hm i think lvl change is fail ...
  8. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    It actually says in the Error log Event is not cancelable
  9. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  10. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,201
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    get the spawn location of the target level then teleport.
    LDX likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder


    Read...
    To instantiate a position:
    PHP:
    use pocketmine\level\Position;
    ...
    $level $server->getLevelByName($levelName);
    $position = new Position($x$y$z$level);
  12. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    but what if you only want only teleport back to home from this level, then the same effect and that is not what i want.

    thats right and i can use this but by death. the teleport goes happends befor - then the simple respawn to main world so nothing helps...
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then get the object of this level.

    No. The teleportation goes right after PlayerRespawnEvent is called. Therefore, you can use $event->setRespawnPosition(Position) to change the position where the player is teleported to for respawning.
    thebigsmileXD, Xenturio and iJoshuaHD like this.
  14. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    onPlayerRespawnEvent

    $position = new Vector3(x, y, z);
    $event->setRespawnPosition($position);


    this is usefull thank u at first - but i get an notice in console after each death in "Spielwelt"

    11:40:20 [NOTICE] An E_RECOVERABLE_ERROR error happened: "Argument 1 passed to pocketmine\event\player\PlayerRespawnEvent::setRespawnPosition() must be an instance of pocketmine\level\Position, instance of pocketmine\math\Vector3 given, called in phar:///home/mcpe3/plugins/SurvivalHiveMinigame.phar/src/main/minigame.php on line 187 and defined" in "/src/pocketmine/event/player/PlayerRespawnEvent" at line 55

    ---edit GOT IT!!!
    new Position(x, y, z) is better ^^^THX FOR HELP!!!
    thebigsmileXD likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use new Position() instead of new Vector3(). Just put the level the player is currently in (Player::getLevel()) for the level.
  16. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    [QUOTE=" Just put the level the player is currently in (Player::getLevel()) for the level.[/QUOTE]

    dont need this make it with a other - if () - code but thanks for help!!!
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    dont need this make it with a other - if () - code but thanks for help!!![/QUOTE]
    I don't understand. What do you mean?
  18. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The player is still in a level. Do you want to always teleport to the same world or to the current world the player is in?
  20. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio
    it works fine =) if u are in minigame world and u die u respawn in the same world at the setted position.
    and the best thing if u do it with the death event as well - your stuff dont gone ^^ so you can rescue your stuff by death

Share This Page

Advertisement