public function forceShutdown() { if ($this->hasStopped) { return; } try { if (!$this->isRunning()) { $this->sendUsage(SendUsageTask::TYPE_CLOSE); } $this->hasStopped = true; $this->shutdown(); if ($this->rcon instanceof RCON) { $this->rcon->stop(); } if ($this->getProperty("network.upnp-forwarding", false) === true) { $this->logger->info("[UPnP] Removing port forward..."); UPnP::RemovePortForward($this->getPort()); } $this->getLogger()->debug("Disabling all plugins"); $this->pluginManager->disablePlugins(); foreach ($this->players as $player) { $player->close($player->getLeaveMessage(), $this->getProperty("settings.shutdown-message", "Server closed")); } $this->getLogger()->debug("Unloading all levels"); foreach ($this->getLevels() as $level) { $this->unloadLevel($level, true); } $this->getLogger()->debug("Removing event handlers"); HandlerList::unregisterAll(); $this->getLogger()->debug("Stopping all tasks"); $this->scheduler->cancelAllTasks(); $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX); $this->getLogger()->debug("Saving properties"); $this->properties->save(); $this->getLogger()->debug("Closing console"); $this->console->shutdown(); $this->console->notify(); $this->getLogger()->debug("Stopping network interfaces"); foreach ($this->network->getInterfaces() as $interface) { $interface->shutdown(); $this->network->unregisterInterface($interface); } //$this->memoryManager->doObjectCleanup(); gc_collect_cycles(); } catch (\Throwable $e) { $this->logger->logException($e); $this->logger->emergency("Crashed while crashing, killing process"); @kill(getmypid()); } }