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 >> 4, true); 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.
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?
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?
Yeah, I put the class in the right place. Here's the github page for it https://github.com/Blubberboy333/ServerMOTD_v0.1.0
https://github.com/Blubberboy333/ServerMOTD_v0.1.0/blob/master/src/ServerMOTD/Main.php#L27 this should be `class Main` instead.