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

Debugging Cheat Sheet

Comments in 'Resources' started by PEMapModder, Jul 28, 2014.

  1. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Now, you have finished your plugin without testing it. And you are testing it and getting errors. Read this page if you are puzzled with the errors.

    Fatal errors
    Fatal errors are usually caused by errors that stopped the server from running. They usually can be categorized into three reasons:
    • Syntax errors
      • Use a good text editor with syntax coloring, or use an IDE. Check brackets, semicolons, commas, etc.
      • Note the line number and the unexpected token. If you see "unexpected T_***", ignore the "T_". It means token, which in fact means nothing.
    • Call to undefined function
      • Check if there are typos.
      • If you are using a global function (not a class function), check it up in the PHP documentation.
      • If you are using a class function as $object->functionName(), try to log the class name of $object using
        PHP:
        $this->getLogger()->debug("\$object class name: ".get_class($object));
    • Trying to call member function of non-object
      • This is usually caused by a function that returns an object (e.g. Server::getPlayer($name)) but does not always returns an object (e.g. because no players with name (similar to) $name is online.
      • Do not ignore the possibility of human errors. Even though it is caused by human errors (like typing the wrong name), a plugin with certain quality should always prevent the server easily crashed by players (so griefers cannot easily crash the server)
      • You are advised to use instanceof instead of checking the return value with === false or === null, because sometimes null is returned and sometimes false is returned, and there is a high possibility that you remembered wrong. Using instanceof can always check if it is a valid object. Examples:
        PHP:
        $player $this->getServer()->getPlayer($args[0]);
        if(!(
        $player instanceof Player)){ // instead of if($player === null) or if($player === false)
            
        return "Player $args[0] isn't online!";
        }
        $world $this->getServer()->getLevelByName($args[1]);
        if(!(
        $world instanceof Level)){ // instead of if($world === null) or if($world === false)
            
        return "World $args[1] doesn't exist!";
        }
      • Check if a variable is valid (using $ref->valid()) if you use WeakRef. This error can be caused by $ref->get()->callFunction().
      • This error can also be caused by a pthreads bug: sometimes static class properties (static fields) become weak references, and therefore these static references could strangely get null'ed. The object may not have been garbaged, but the reference just broke. Therefore, don't use static instances. It is not accepted in plugins, generally, either.
    • Uncaught exceptions
      • There are several places in the PocketMine-MP source that throws exceptions. Here are the most frequently met exceptions:
        • Autoloader couldn't find a file to include for ***
          • Check if there are typos.
          • Did you forget to do the
            PHP:
            use name\space\ClassName;
            alias use declaration? Check.
          • If it is another class in your plugin, check if foo\bar\ClassName class is placed at src/foo/bar/ClassName.php.
          • Do not put your class inside an if-block.
        • Tried to modify empty chunk
          • You used the $level->setBlock() function, where your target is an non-existent or not-yet-loaded chunk in the world.
          • Try to generate/load that chunk first using
            PHP:
            $level->loadChunk($x >> 4$z >> 4true);
          • There is a chance that your chunk is outside the world (although almost impossible). Check that too (although I don't think anyone would use such a world).
        • Event is not cancellable
          • You used $event->setCancelled() or $event->isCancelled(), but that event is not cancellable in the first palce.
          • Do not cancel that event because it can't be cancelled. Find another way to cancel that event, if possible.
          • Cancel an entity's death by watching EntityDamageEvent and EntityDamageByEntityEvent, checking the final damage
        • Plugin *** is disabled / plugin *** attempted to *** while disabled/not enabled
          • Don't do anything in the onLoad() function
          • Schedule only subclasses of PluginTask.
          • Do not call PocketMine-MP API functions outside the main thread.
          • Try to stop your thread/AsyncTask from running if your plugin is disabled.
        • Couldn't load plugin: main class not found
          • Same as Autoloader couldn't find a file to include for ***.
          • Check if the YAML is formatted correctly.
        • Projected dataFolder *** exists and is not a directory
          • Don't save any files without a file extension in your plugins/ folder.
        • *** is not applicable to ***
          • You modified an incorrect modifier of the event of EntityDamageEvent.
          • Check the documentation to use the valid modifier.
        • Undefined Level reference
          • The world is possibly unloaded, or by other means collected by the GC (Garbage Collector).
          • If you want to make a strong reference, use $position->setStrong() or add the true parameter at the end of the position constructor.
            • Warning: Do NOT set a position to strong reference unless you know exactly what you are doing!
        • Invalid level name
          • Level names passed to Server::loadLevel() must be a valid folder name.
        • Invalid PluginDescription name
          • Plugins must have a valid name.
        • Failed to correctly release the reference on free
          • Check with $weakRef->valid() before using $weakRef->get().
    Fixing Strange Bugs
    If you find out that there are strange parameters passed to a function, try using the debug_backtrace() function. Thanks to @Intyre for this tip :)

    To be continued.
    Last edited: Aug 15, 2014
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Post occupied in case I need an extension post slot to extend the main post.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  5. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    I keep getting this
    ClassNotFoundException: "Class ServerMOTD\Main not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 131
    I've looked in the plugin.yml, made sure it was formated the right way, but it still won't work. Any suggestions?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Did you make sure the class is placed at the correct place? Can you push your code to a git repo or create a zip?
  7. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Potato likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
  9. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Thanks, I'll try that
  10. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    That worked! Thanks so much :D

Share This Page

Advertisement