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

Why this won't work?

Comments in 'Plugin Development' started by Marcelo234, Feb 6, 2016.

  1. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys...Why this won't work?
    There are two Plugins
    1. Plugin "McKaff_Settings"
    2. Plugin "McKaff_BowBash"

    So the "McKaff_Settings" plugin have a folder, named "PlayersInfo"...If a player join to a server he will get a file...My name in MCPE is "Jogi"..So if "Jogi" join, he get a file (McKaff_Settings/PlayersInfo/Jogi.yml)
    The file (McKaff_Settings/PlayersInfo/Jogi.yml) looks like that:
    Code:
    ---
    Language: EN
    ...
    
    So i have a other plugin where I need this Info (What a language the player selected)....
    McKaff_Settings:
    PHP:
    //.........

    public $messagesEN;
    public 
    $messagesDE;

    //...........

    //Register English Messages
            
    $this->messagesEN = new Config($this->getDataFolder() ."languages/English.yml",Config::YAML);
            
    //Register Deutsch Messages
            
    $this->messagesDE = new Config($this->getDataFolder() ."languages/Deutsch.yml",Config::YAML);
           

    //.........

    public function PlayerLanguage(Player $player$message) {
            
    $this->player = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($player->getName()), Config::YAML);
            
    $language $this->player->get("Language");
            if(
    $language == "DE") {
                
    $player->sendMessage($this->messagesDE->get($message));
            }
            if(
    $language == "EN") {
                
    $player->sendMessage($this->messagesEN->get($message));
            }
        }
    So and now the McKaff_BowBash plugin:
    PHP:
    //............

    public $networkplugin;
       
        public function 
    onEnable(){
            
    $this->getLogger()->info(TextFormat::GREEN."[McKaff_BowBash] succesfully enabled!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->registerSettings();
            
    $this->saveDefaultConfig();
        }
       
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."[McKaff_BowBash] disabled!");
        }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            if(
    strtolower($cmd->getName()) == "bb"){
                if(isset(
    $args[0])){
                    if(
    $sender instanceof Player){
                        switch(
    strtolower($args[0])){
                                case 
    "create":
                                        
    $this->getLanguageFromNetwork($sender'has_no_permission');
                                break;
                        }
                    }
                }
            }
        }

    public function 
    getLanguageFromNetwork($player$message){
                
    $ec $this->networkplugin->settings;
                switch(
    $ec->getName()){
                    case 
    "McKaff_Settings":
                        
    $ec->PlayerLanguage($player$message);
                    break;
                }
        }
       
        public function 
    registerSettings(){
            
    $settings = ["McKaff_Settings"];
            foreach(
    $settings as $plugin){
                
    $networkplugin $this->getServer()->getPluginManager()->getPlugin($plugin);
                if(
    $networkplugin instanceof Plugin && $networkplugin->isEnabled()){
                    
    $this->settings $networkplugin;
                    
    $this->getServer()->getLogger()->info(TextFormat::BLUE."[BB]Sucesfully connected with $plugin");
                }
                else{
                    
    $this->getServer()->getLogger()->info(TextFormat::RED."[BB]WARNING! Can't find $plugin");
                }
            }
        }

    //...............
    Thanks Marcelo234
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    What is the error? Any console messages or crash dumps?
  3. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Sorry (i forgot to write the Error)
    ERROR:
    Code:
    [09:27:25] [Server thread/CRITICAL]: Unhandled exception executing command 'bb create' in bb: Trying to get property of non-object
    [09:27:25] [Server thread/NOTICE]: InvalidStateException: "Trying to get property of non-object" (E_NOTICE) in "/McKaff_BowBash/src/McKaff_BowBash/BowBash" at line 53
    
  4. Addisonep
    Offline

    Addisonep New Member

    Joined:
    May 11, 2015
    Posts:
    14
    Minecraft User:
    Addisonep
    It says it all in the error message... "Trying to get property of non-object"
  5. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Yeah.. What is wrong
  6. Addisonep
    Offline

    Addisonep New Member

    Joined:
    May 11, 2015
    Posts:
    14
    Minecraft User:
    Addisonep
    It's trying to get the property of a non-object... What's on line 53?
  7. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    delete
    $ec= $this->networkplugin->settings

    add
    $ec= $this->settings
  8. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Now there is no error
    If the Player Type /bb create nothing happens
  9. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    use getLogger()->info() in order to check if the functions are called correctly.
    And check if there are messages in languages Config.
    PocketKiller likes this.
  10. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey guys I changed the code to test this.....
    NEW CODE:
    1.Plugin
    McKaff_BowBash:
    PHP:
    <?php

    namespace McKaff_BowBash;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\plugin\Plugin;

    class 
    BowBash extends PluginBase implements Listener{
       
        public 
    $networkplugin;
       
        public function 
    onEnable(){
            
    $this->getLogger()->info(TextFormat::GREEN."[McKaff_BowBash] succesfully enabled!");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->registerSettings();
            
    $this->saveDefaultConfig();
        }
       
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."[McKaff_BowBash] disabled!");
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
            if(
    strtolower($cmd->getName()) == "bb"){
                if(isset(
    $args[0])){
                    if(
    $sender instanceof Player){
                        switch(
    strtolower($args[0])){
                                case 
    "create":
                                        
    $this->getLanguageFromNetwork($sender);
                                break;
                        }
                    }
                }
            }
        }
       
        public function 
    getLanguageFromNetwork(Player $player){
                
    $ec $this->settings;
                switch(
    $ec->getName()){
                    case 
    "McKaff_Settings":
                        
    $ec->PlayerLanguage($player);
                    break;
                }
        }
           public function 
    registerSettings(){
            
    $settings = ["McKaff_Settings"];
            foreach(
    $settings as $plugin){
                
    $networkplugin $this->getServer()->getPluginManager()->getPlugin($plugin);
                if(
    $networkplugin instanceof Plugin && $networkplugin->isEnabled()){
                    
    $this->settings $networkplugin;
                    
    $this->getServer()->getLogger()->info(TextFormat::BLUE."[BB]Sucesfully connected with $plugin");
                }
                else{
                    
    $this->getServer()->getLogger()->info(TextFormat::RED."[BB]WARNING! Can't find $plugin");
                }
            }
        }
    }
    2.Plugin
    McKaff_Settings:
    PHP:
    public function PlayerLanguage(Player $player) {
            
    //$this->player = new Config($this->getDataFolder() . "PlayersInfo/" . strtolower($player->getName()), Config::YAML);
            //$language = $this->player->get("Language");
            
    if($language == "DE") {
                
    //$player->sendMessage($this->messagesDE->get($message));
                
    $player->sendMessage(TextFormat::GREEN."Deutsch");
                
    $this->getLogger()->info(TextFormat::GREEN."Deutsch");
            }
            if(
    $language == "EN") {
                
    //$player->sendMessage($this->messagesEN->get($message));
                
    $player->sendMessage(TextFormat::GREEN."English");
                
    $this->getLogger()->info(TextFormat::GREEN."English");
            }
        }
    I changed the few things, that I can see if the Problem is caused by $messagesDE or $messagesEN;
    CURRENT ERROR:

    Code:
    [13:54:56] [Server thread/CRITICAL]: Unhandled exception executing command 'bb create' in bb: Missing argument 2 for McKaff_Settings\Main::PlayerLanguage(), called in C:\Users\Marcelo\Desktop\McKaff_BowBash\McKaff_BowBash\plugins\McKaff_BowBash\src\McKaff_BowBash\BowBash.php on line 56 and defined
    [13:54:56] [Server thread/WARNING]: RuntimeException: "Missing argument 2 for McKaff_Settings\Main::PlayerLanguage(), called in C:\Users\Marcelo\Desktop\McKaff_BowBash\McKaff_BowBash\plugins\McKaff_BowBash\src\McKaff_BowBash\BowBash.php on line 56 and defined" (E_WARNING) in "/McKaff_Settings_v0.1.0.phar/src/McKaff_Settings/Main" at line 775
    
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    It seems to be you did not update the code on your machine.
  12. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    This code is copied from my machine....What to do?
  13. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Okay I updated something in
    McKaff_Settings:
    PHP:
    public function PlayerLanguage(Player $player) {
            
    //$this->player = new Config($this->getDataFolder() . "PlayersInfo/" . strtolower($player->getName()), Config::YAML);
            //$language = $this->player->get("Language");
            //if($language == "DE") {
                //$player->sendMessage($this->messagesDE->get($message));
                
    $player->sendMessage(TextFormat::GREEN."Deutsch");
                
    $this->getLogger()->info(TextFormat::GREEN."Deutsch");
            
    //}
            //if($language == "EN") {
                //$player->sendMessage($this->messagesEN->get($message));
            //    $player->sendMessage(TextFormat::GREEN."English");
            //    $this->getLogger()->info(TextFormat::GREEN."English");
            //}
        
    }
    Because I can't get the language if $language isn't in the code!
    But the ERROR is already there.....
  14. Yosshi999
    Offline

    Yosshi999 New Member Plugin Developer

    Joined:
    Mar 13, 2014
    Posts:
    29
    Plugins:
    1
    Minecraft User:
    Yosshi999
    BowBash.php sees only Settings.phar ,
    not Settings.php .
    You used '/makeplugin' or something and made the Settings.phar plugin didn't you?
    Delete McKaff_Settings_v0.1.0.phar
  15. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Okay...yes i Made a McKaff_Settings.phar
  16. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    So now i followed your instructions .....The McKaff_Settings Plugin isn't a .phar anymore....
    So I have changed a few things too...But there is one more Error...
    1.Plugin McKaff_Settings:
    PHP:
     public function PlayerLanguage(Player $player$message) {
            
    $this->player = new Config($this->getDataFolder() . "PlayersInfo/" strtolower($player->getName()), Config::YAML);
            
    $language $this->player->get("Language");
            if(
    $language == "DE") {
                
    $player->sendMessage($this->messagesDE->get($message));
                
    $player->sendMessage(TextFormat::GREEN."Deutsch");
                
    $this->getLogger()->info(TextFormat::GREEN."Deutsch");
            }
            if(
    $language == "EN") {
                
    $player->sendMessage($this->messagesEN->get($message));
                
    $player->sendMessage(TextFormat::GREEN."English");
                
    $this->getLogger()->info(TextFormat::GREEN."English");
            }
        }
    2.Plugin McKaff_BowBash:
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args){
            if(
    strtolower($cmd->getName()) == "bb"){
                if(isset(
    $args[0])){
                    if(
    $sender instanceof Player){
                        switch(
    strtolower($args[0])){
                                case 
    "create":
                                        
    $this->getLanguageFromNetwork($sender'test');
                                break;
                        }
                    }
                }
            }
        }
       
        public function 
    getLanguageFromNetwork(Player $player$message){
            
    $networkplugin $this->getServer()->getPluginManager()->getPlugin("McKaff_Settings");
            
    $ec $this->$networkplugin;
                
    $ec->PlayerLanguage($player$message);
        }
    ERROR:
    Code:
    [16:30:49] [Server thread/CRITICAL]: Unhandled exception executing command 'bb create' in bb: Object of class McKaff_Settings\Main could not be converted to string
    [16:30:49] [Server thread/NOTICE]: ClassCastException: "Object of class McKaff_Settings\Main could not be converted to string" (E_RECOVERABLE_ERROR) in "/McKaff_BowBash/src/McKaff_BowBash/BowBash" at line 54
    
    Thanks Marcelo234
  17. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    So what the Server means with this Error Message? String....
  18. Marcelo234
    Offline

    Marcelo234 New Member

    Joined:
    Oct 18, 2014
    Posts:
    204
    Hey Guys now it works.....So for all who are interested in the Code here is the right form....
    Plugin: McKaff_BowBash [Main]
    PHP:
    public function getLanguageFromNetwork(Player $player$message){
            
    $networkplugin $this->getServer()->getPluginManager()->getPlugin("McKaff_Settings");
                
    $networkplugin->PlayerLanguage($player$message);
        }
    Thanks for all your Help..

Share This Page

Advertisement