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

Error when i try to set the ChatFormat

Discussion in 'Development' started by Jonas, May 20, 2017.

  1. Jonas

    Jonas Baby Zombie

    Messages:
    192
    I tried to set the default group from pureperm when a player is a config, but it comes an error. Here is my Code with that i tried to set the Chatformat:
    PHP:
    $event->setFormat(PurePerms::getDefaultGroup());
    Here is the error:
    Code:
    [Server]
    [Server] Deprecated: Non-static method _64FF00\PurePerms\PurePerms::getDefaultGroup() should not be called statically in /storage/emulated/0/PocketMine/plugins/Nick/src/UniverseNick/JonasGehtMitte/Nick.php on line 181
    [Server] [PocketMine] [13:11:16] CRITICAL> Could not execute task UniverseNick\JonasGehtMitte\Refresh: Using $this when not in object context
    [Server] [PocketMine] [13:11:16] CRITICAL> Error: "Using $this when not in object context" (EXCEPTION) in "/PurePerms.phar/src/_64FF00/PurePerms/PurePerms" at line 332
    
     
    Last edited: May 20, 2017
  2. Lowkey

    Lowkey Slime

    Messages:
    94
    Line 332?
     
  3. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    getDefaultGroup is not a static method, so that should be
    PHP:
    $event->setFormat($server->getPluginManager()->getPlugin("PurePerms")->getDefaultGroup());
    assume $server is an instance of \pocketmine\Server

    You may want to read further on static methods at https://secure.php.net/manual/en/language.oop5.static.php.
     
    Last edited: May 20, 2017
    jasonwynn10 and SOFe like this.
  4. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Thx, but it doesnt change my Rang Admin etc. To Guest
     
  5. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    :facepalm: Yes, because it is just getting the default group, not the group of the user.
     
    jasonwynn10 likes this.
  6. Jonas

    Jonas Baby Zombie

    Messages:
    192
    How can i make this?
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    $event->setFormat($server->getPluginManager()->getPlugin("PurePerms")->getUserDataMgr()->getGroup($event->getPlayer()));
     
    Last edited: May 20, 2017
  8. Keith

    Keith Spider Jockey

    Messages:
    42
    GitHub:
    k3ithos
    You typed two "->" after getPlugin() :p
     
    0x15f likes this.
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    my bad :p
     
  10. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    AnD ThAt's WhY Y0u Sh0UlD NeVeR UsE ThE PmMP c0De Ed1T0r t0 Wr1tE C0De
     
    Last edited: May 20, 2017
    [deleted] and jasonwynn10 like this.
  11. Jonas

    Jonas Baby Zombie

    Messages:
    192
    When i use this then comes an error. The -> behind the getPlugin() have i deleted. And i have wrote in my Plugin use pocketmine\IPlayer;
    Code:
    [Server] [PocketMine] [09:03:59] CRITICAL> "Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'Nick v1.0.1': Argument 1 passed to _64FF00\PurePerms\data\UserDataManager::getGroup() must implement interface pocketmine\IPlayer, string given, called in /storage/emulated/0/PocketMine/plugins/Nick/src/UniverseNick/JonasGehtMitte/Nick.php on line 168 on UniverseNick\JonasGehtMitte\Nick
    [Server] [PocketMine] [09:03:59] CRITICAL> TypeError: "Argument 1 passed to _64FF00\PurePerms\data\UserDataManager::getGroup() must implement interface pocketmine\IPlayer, string given, called in /storage/emulated/0/PocketMine/plugins/Nick/src/UniverseNick/JonasGehtMitte/Nick.php on line 168" (EXCEPTION) in "/PurePerms.phar/src/_64FF00/PurePerms/data/UserDataManager" at line 56
    
     
  12. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Read the error. It's soo clear. Here, let me rephrase the error.
    You provided argument 1 for getGroup() as a string while it should've actually been IPlayer::class.
     
    jasonwynn10 likes this.
  13. Jonas

    Jonas Baby Zombie

    Messages:
    192
    So?
    PHP:
    $this->getServer()->getPluginManager()->getPlugin("PurePerms")->getUserDataMgr()->getGroup();
     
  14. Jonas

    Jonas Baby Zombie

    Messages:
    192
    PHP:
    ...->getGroup(IPlayer $nick);
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    ...->getGroup(Server::getInstance()->getOfflinePlayer("playername"));
     
  16. Jonas

    Jonas Baby Zombie

    Messages:
    192
    why getOfflinePlayer()? And i got the same error when i replace "playername" to $nick
     
  17. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    what was the error?
     
    Muqsit likes this.
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    getOfflinePlayer() returns IPlayer. I wouldn't recommend using getPlayer() or getPlayerExact() as it would return Player(which implements IPlayer) only if the player was online.

    And we don't know what $nick is.
     
  19. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Code:
    [Server] [PocketMine] [16:59:08] CRITICAL> "Could not pass event 'pocketmine\event\player\PlayerChatEvent' to 'Nick v1.0.1': Argument 1 passed to _64FF00\PurePerms\PurePerms::setGroup() must implement interface pocketmine\IPlayer, string given, called in /storage/emulated/0/PocketMine/plugins/Nick/src/UniverseNick/JonasGehtMitte/Nick.php on line 168 on UniverseNick\JonasGehtMitte\Nick
    [Server] [PocketMine] [16:59:08] CRITICAL> TypeError: "Argument 1 passed to _64FF00\PurePerms\PurePerms::setGroup() must implement interface pocketmine\IPlayer, string given, called in /storage/emulated/0/PocketMine/plugins/Nick/src/UniverseNick/JonasGehtMitte/Nick.php on line 168" (EXCEPTION) in "/PurePerms.phar/src/_64FF00/PurePerms/PurePerms" at line 659
    [Server] [PocketMine] [16:59:08] INFO> [Developer] Guest | Serus Haralain > a
     
  20. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It was answered.
    getOfflinePlayer() doesn't mean you can't get an online player. If the player is online, getOfflinePlayer() returns the online player.
     
  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.