1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Type error when I add config instead of a message

Discussion in 'Development' started by str0nix, Jul 29, 2020.

  1. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Greetings,

    I added a config file to my plugin and when I changed the message from "You are healed" to $this->myConfig->get("XY") I get this error when I execute the command in game. (Internal Server Error)

    [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type string, bool given, called in phar://C:/Users/Varga Domonkos Péter/Documents/Minecraft PE Szerverek/Szerver 1/PocketMine-MP.phar/src/pocketmine/Player.php on line 3510" (EXCEPTION) in "src/pocketmine/lang/BaseLang" at line 129

    And here is the code of the command:

    case "heal":
    if($sender instanceof Player){
    if($sender->hasPermission("servercore.heal")){
    $sender->setHealth($sender->getMaxHealth());
    $sender->sendMessage($this->myConfig->get("heal_success"));
    }
    } else {

    }
    break;

    Thanks for any help in advance, have a great day! :)
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also you dont need an empty else Lol, why are you used else ?
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    please show us full code, or show us what is $this->myconfig?
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    sorry, is $sender, CommandSender?
    SHOW FULL CODE
     
  5. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    I can't show you, because the forum doesn't let me send comment or message which is contain more than 1000 characters. How could I show you then? Is there any other option to do this?
     
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    so, you should set $this->myconfig = $this->getConfig();
    onEnable. do you used this? (Still im waiting for your full code
     
  7. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    just show onEnable and onCommand
     
  8. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Trough pastebin, I'm able to show you. https://pastebin.com/z0z4knUh
     
  9. Primus

    Primus Zombie Pigman

    Messages:
    749
    When getting a value from config, it will return a false if the key was not found. Make sure the config in "../plugin_data/YourPlugin/servercore.yml " has the key "heal_success".

    You can bypass empty key problem, by providing the default return value in second argument for Config::get().

    See, you're making an empty config file by giving an array()
    PHP:
    $this->myConfig = new Config($this->getDataFolder() . "servercore.yml"Config:: YAML, array());
    If you have prepared config, in your plugin resources folder use Plugin::saveDefaultConfig()
     
  10. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Maybe this is the problem, I just checked the plugin's data folder and for some reason the servercore.yml is an empty file, but in the src folder of the plugin i put the servercore.yml file with the config values to the resources folder but when I start my server the plugin generate an empty servercore.yml file...
     
  11. Primus

    Primus Zombie Pigman

    Messages:
    749
    You nowhere in the code specify to use the one in resource folder. Check out PluginBase::saveDefaultConfig(). But Note: the config must be named by default conventions 'config.yml' instead of your servercore.yml file. This will mean that you'll no longer will have to initialize your own ''myConfig" object, but instead use PluginBase::getConfig().
     
  12. str0nix

    str0nix Spider Jockey

    Messages:
    33
    GitHub:
    str0nixofficial
    Thank you very much! :)
     
    Primus likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.