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

This does not work?

Comments in 'Plugin Development' started by Legoboy0215, Jun 26, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Does anyone have a idea why this code does not work?
    PHP:
        public function onWorldChange(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            
    $target $event->getTarget()->getName();
            
    $level $this->getServer()->getDefaultLevel();
            
    $x $level->getSafeSpawn()->getX();
            
    $y $level->getSafeSpawn()->getY();
            
    $z $level->getSafeSpawn()->getZ();
            if(
    $target === "testspawn" or $target === "newsurvival" or $target === "townpvp" or $target === "freebuild"){
              
    $player->sendMessage(TextFormat::GREEN "This world is not open to the public...");
              
    $player->setLevel($level);
              
    $player->teleport(new Vector3($x$y$z$level));
        }
    }
    I use ManyWorlds for teleportation, but I doubt it is the problem...
    Last edited: Jun 26, 2015
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    The code just teleports the player to the world he wants to go and does not even send the message... XD
  3. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    First of all Vector3 represents a point coordinate in 3d space. Its parameters must be just the X, Y and Z coordinates. You should use Position instead.
    Second: Position wants the fourth parameter as a Level instance. So you must put
    PHP:
    $event->getTarget()
    Instead of the target name
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Then I would not need the $target? I just use target to check the target worlds name...
  5. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You can use $target variable just to check the world name.
    Then if you want to use $target variable you must get the Level instance from the $target string.
    PHP:
    $this->getServer()->getLevelByName($target);
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    So this?
    PHP:
        public function onWorldChange(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            
    $target $event->getTarget();
            
    $level $this->getServer()->getDefaultLevel();
            
    $x $level->getSafeSpawn()->getX();
            
    $y $level->getSafeSpawn()->getY();
            
    $z $level->getSafeSpawn()->getZ();
            if(
    $target === "testspawn" or $target === "newsurvival" or $target === "townpvp" or $target === "freebuild"){
              
    $player->sendMessage(TextFormat::GREEN "This world is not open to the public...");
              
    $player->setLevel($level);
              
    $player->teleport(new Position($x$y$z$level));
        }
    }
  7. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    No, you must specify the target level also on teleport
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    I thought I did...
    PHP:
    $level $this->getServer()->getDefaultLevel();
  9. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    PHP:
    $level $event->getTarget();
    Wait...
    I don't understand where you should be teleported.
    if the if block is true, should the player be teleported to the main world?
    CraftYourBukkit and Legoboy0215 like this.
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    You start at a world called spawn, which is the default world. They type /mw tp testspawn, then they teleport to the world called "testspawn", which is also the world I do NOT want players even me to go. $level is the world called spawn where you started with. So I mean if $target (Where the player went) is called "testspawn", they will be teleported back to the server spawn.
  11. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Ah ok, your code is right :)
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    But it does not work...
  13. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You don't need $player->setLevel($level);
    Then make sure you registered events
  14. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    You shouldn't be doing that. This is because that is done within a "teleport", so calling a new teleport within a teleport is a bit dangerous.

    If you want to stop the player from doing this, you should do
    PHP:
    $event->setCancelled();
    If you really want to teleport them out, you should do it in a delayed task.
    Legoboy0215 likes this.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    That is the problem. I do not know how to use a delayed task...
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Even this does not work...
    PHP:
        public function onWorldChange(EntityLevelChangeEvent $event){
            
    $player $event->getEntity();
            
    $target $event->getTarget()->getName();
            if(
    $target === "testspawn" or $target === "newsurvival" or $target === "townpvp" or $target === "freebuild"){
              
    $player->sendMessage(TextFormat::GREEN "This world is not open to the public...");
              
    $event->setCancelled();
        }
    }
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    "Doesn't work" can mean many things. Specify how, please.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Sorry.. Nothing any more. I used MTP then it is ok, but if I use MW it does not even show the message.

Share This Page

Advertisement