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

Could this be fixed?

Comments in 'Plugin Development' started by Exxarion, Mar 12, 2015.

  1. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    Hello Developers,

    I am trying to remove some bad practice from my plugin's utilities.php, but when I change it, the server crashes when player's enter. Here is the line with bad practice:

    PHP:
    public static function getWorldGamemode(Config $config$world) {
            return (isset(
    $config->get(WorldGM::CONFIG_WORLDS)[$world])) ? $config->get(WorldGM::CONFIG_WORLDS)[$world] : Server::getInstance()->getDefaultGamemode();
        }
    If you can correct it for me, that would be great.


    If you need the rest of the file, let me know.
  2. xFlare
    Offline

    xFlare Active Member Plugin Developer

    Joined:
    Sep 28, 2014
    Posts:
    199
    Plugins:
    1
    Minecraft User:
    xFlare
    Umm, try $this->getServer(); rather then Server::getInstance();
  3. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    Tried that, but the server crashed when a player joined. That's the problem there.
    xFlare likes this.
  4. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,397
    Plugins:
    14
    PHP:
    public function getWorldGamemode(Config $config$world) {
            return (
    $config->get(WorldGM::CONFIG_WORLDS)[$world]) != false $config->get(WorldGM::CONFIG_WORLDS)[$world] : $this->getServer()->getDefaultGamemode());
        }
    Last edited: Mar 13, 2015
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Pass the $server instance as a parameter into the function. You can't use $this in static function context.
    LDX likes this.
  6. Exxarion
    Offline

    Exxarion Active Member Plugin Developer

    Joined:
    Jan 5, 2014
    Posts:
    242
    Plugins:
    1
    Minecraft User:
    Notch
    That fixed it. I feel so stupid now -.-


    I ran into another problem, but I believe I can fix it, and Ill say if I cant. Thanks for the help!
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Actually, you should've shown us the error message. But I'm a genius who guesses it without being told! :p

Share This Page

Advertisement