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

PlayerWorld

Comments in 'Plugin Development' started by Marcelo234, Jan 22, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys, I want to get the World where the Player is....
    But how?....That WRONG!!
    PHP:
    $playerlevel $player->getLevel();
    How to write instead of this?Thx.:.Marcelo234
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    its correct, do you want Levelname?
  3. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    What do you want to get player level from?
    Get All Player World
    PHP:
    $this->getServer()->getPlayer()->getLevel();
    Get World using event
    PHP:
    public function test(PlayerCommandPreprocessEvent $ev){
    if(
    $ev->getMessage() == "a"){
    //If type "a" in chat, get level
    $ev->getPlayer()->getLevel();
    }
    }
    Get Level By World Name
    PHP:
    $this->getServer()->getLevelByName("NAME HERE");
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    everything is wrong except the last one, but he wants the Level that the player is on.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

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

    and Server::getPlayer() requires an argument! And why use PlayerCommandPreprocessEvent in specifically? And why search by name? He is talking about level of player! His code is already correct! Wtf are you doing?
    CraftYourBukkit and PocketKiller like this.
  6. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Yes, i want the Level Name were the player is on..
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    $playerlevel $player->getLevel()->getName();
  8. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Thx
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Either
    PHP:
    $playerlevel $player->getLevel()->getName();
    or
    PHP:
    $playerlevel $player->getLevel()->getFolderName();
    I personally use the second one, as that'd be more efficient in some ways(example: Resetting a world)
    PEMapModder likes this.
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Why this won't work?
    PHP:
    public function onPlayerInteract(PlayerInteractEvent $event) {
    $this->config = new config($this->getDataFolder() . "config.yml"Config::YAML, array());
            
    $lobby $this->getServer()->getLevelByName($this->config->get("lobby_spawn_world"));
            
    $playerlevel $player->getLevel()->getName();

    if(
    $event->getItem()->getId()==388){
    if(
    $lobby == $playerlevel) {
    $sender->sendMessage(TextFormat::RED."Yeah!");
    }
    }
    }
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    that is not on the topic of your thread.
    replace
    PHP:
    if($lobby == $playerlevel) {
    with
    PHP:
    if($lobby->getName() == $playerlevel) { // you was comparing a string with a Level object.
    or
    PHP:
    if($playerlevel == $this->config->get("lobby_spawn_world")) {
    Marcelo234 likes this.
  12. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Thx
  13. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    The Server chrash if i use this
  14. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    show code and console output
    Marcelo234 likes this.
  15. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    He said "How to get world name". I misunderstood.
    PocketKiller likes this.
  16. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey guys....Why this won't work?
    Code:
    PHP:
    public function onPlayerInteract(PlayerInteractEvent $event) {
    $player $event->getPlayer();
    $this->config = new config($this->getDataFolder() . "config.yml"Config::YAML, array());
            
    $lobby $this->getServer()->getLevelByName($this->config->get("lobby_spawn_world"));
            
    $playerlevel $player->getLevel()->getName();
    if(
    $event->getItem()->getId()==388){
    if(
    $lobby->getName() == $playerlevel) {
    $sender->sendMessage(TextFormat::RED."It works!");
    }
    }
    }
    And here the ERROR:
    Code:
    Fatal error: Call to a member function getName() on null in C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\plugins\McKaff_Settings\src\McKaff_Settings\Main.php on line 690
    
    Call Stack:
        0.0660     447912   1. {main}() C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\PocketMine-MP.phar:0
        0.0726     443056   2. require('phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\PocketMine-MP.phar:1
        0.6910     584936   3. pocketmine\Server->__construct() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/PocketMine.php:466
        6.4597   16614664   4. pocketmine\Server->start() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:1701
        6.5521   16715576   5. pocketmine\Server->tickProcessor() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2100
       22.6596   43496176   6. pocketmine\Server->tick() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2222
       22.6598   43496240   7. pocketmine\network\Network->processInterfaces() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/Server__32bit.php:2470
       22.6598   43496240   8. pocketmine\network\RakLibInterface->process() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/network/Network__32bit.php:160
       22.6632   43501952   9. raklib\server\ServerHandler->handlePacket() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:81
       22.6638   43502928  10. pocketmine\network\RakLibInterface->handleEncapsulated() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/raklib/server/ServerHandler__32bit.php:90
       22.6649   43504008  11. pocketmine\Player->handleDataPacket() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:140
       22.6659   43506184  12. pocketmine\level\Level->useItemOn() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/Player__32bit.php:1989
       22.6672   43507544  13. pocketmine\plugin\PluginManager->callEvent() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/level/Level__32bit.php:1669
       22.6675   43508096  14. pocketmine\plugin\RegisteredListener->callEvent() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/plugin/PluginManager.php:673
       22.6676   43508096  15. pocketmine\plugin\MethodEventExecutor->execute() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/plugin/RegisteredListener.php:96
       22.6677   43508304  16. McKaff_Settings\Main->onPlayerInteract() phar://C:/Users/Marcelo/Desktop/McKaff_Settings-TEST/McKaff_Settings-TEST/PocketMine-MP.phar/src/pocketmine/plugin/MethodEventExecutor.php:36
    
    [13:24:40] [Server thread/EMERGENCY]: An unrecoverable error has occurred and the server has crashed. Creating a crash dump
    [13:24:40] [Server thread/EMERGENCY]: Please upload the "C:\Users\Marcelo\Desktop\McKaff_Settings-TEST\McKaff_Settings-TEST\CrashDump_Sat_Jan_23-13.24.40-GMT_2016.log" file to the Crash Archive and submit the link to the Bug Reporting page. Give as much info as you can.
    
    Thx
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The lobby world isn't loaded.
  18. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    How to write? Right?
    PHP:
    public function onEnable() {
    $this->config = new config($this->getDataFolder() . "config.yml"Config::YAML, array());
            
    $this->getServer()->loadLevel($this->config->get("lobby_spawn_world"));
    }
    PocketKiller likes this.
  19. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Anything is wrong...(in my example about this message)??
  20. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    ERROR:
    Code:
    [14:10:30] [Server thread/CRITICAL]: pocketmine\utils\LevelException: "Invalid empty level name" (EXCEPTION) in "/src/pocketmine/Server__32bit" at line 1057
    

Share This Page

Advertisement