added ability to add comments for entries in .properties files, deleted experimental-mob-ai since it does nothing

This commit is contained in:
GameHerobrine 2025-09-12 12:54:49 +03:00
parent 8046d0e17c
commit 2a827c42c4
4 changed files with 65 additions and 9 deletions

View file

@ -137,6 +137,16 @@ class ServerAPI{
"auto-save" => true,
"enable-mob-ai" => true,
"abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT
], comments: [
"level-type" => [
"Alowed types:",
"FLAT - flat world",
"DEFAULT - use one of the 4 pregenerated worlds from pocketmine",
"VANILLA - unfinished, attempts to generate vanilla 0.8.1 world. This geneeator is very slow."
],
"abort-reading-after-N-packets" => [
"Sets max amount of packets the server can read before forcing tick check."
]
]);
Entity::$allowFly = $this->getProperty("allow-flight", true);
if(!Entity::$allowFly){

View file

@ -95,7 +95,6 @@ class PocketMinecraftServer{
"discord-bot-name" => "NostalgiaCore Logger",
"despawn-mobs" => true,
"mob-despawn-ticks" => 18000,
"experimental-mob-ai" => false,
"force-20-tps" => false,
"enable-mob-pushing" => Living::$entityPushing,
"keep-chunks-loaded" => self::$KEEP_CHUNKS_LOADED,
@ -106,6 +105,42 @@ class PocketMinecraftServer{
"allow-dropping-single-items" => Player::$allowDroppingSingleItems,
"enable-light-updates" => self::$ENABLE_LIGHT_UPDATES,
"min-block-breaking-progress" => self::$BLOCK_BREAKING_PROGRESS,
], comments: [
"min-block-breaking-progress" => [
"Affects how strict block breaking speed check is.",
"0 - allow blocks to be mined instantly",
"0.8 - allow breaking blocks after 80% of vanilla block break time.",
"The value should be in range from 0 to 1."
],
"enable-light-updates" => [
"Enabling light updates may affects performance and will increase world generation time.",
"Disabling light updates will disable all light-related features(like light-based mob spawning)"
],
"allow-dropping-single-items" => [
"Allows players to drop any amount of items from stack in the slot.",
"While it is not possible using vanilla client, some custom clients(like Ninecraft) have this feature"
],
"disable-emojis-in-chat" => [
"Disallows players to send certain symbols in chat to prevent client lags"
],
"use-experimental-hotbar" => [
"Changes serverside hotbar behavior to be more like in 0.8 rather than 0.7(when disabled)",
"May cause more problems than old hotbar"
],
"enable-mob-pushing" => [
"Enables or disables serverside mob pushing",
"If enabled it may cause performance issues when there are a lot of mobs in a small enclosed area",
"If disabled it will cause small entity position desync(that should be fixed every time a server sends a new movement packet to the client)"
],
"force-20-tps" => [
"Forces server to run at 20 tps on some platforms where sleeping for small amount of time is not possible(hi windows & 16 tps)",
],
"discord-ru-smiles" => [
"Replaces cyrillic symbols Ы Ь Ъ Ё with emojis when sending a message using discord webhook(as it is done in some custom clients)"
],
"keep-chunks-loaded" => [
"If disabled chunks won't be loaded into memory until the player(or something else) loads them"
]
]);
self::$BLOCK_BREAKING_PROGRESS = $this->extraprops->get("min-block-breaking-progress");
Player::$disableEmojisInChat = $this->extraprops->get("disable-emojis-in-chat");
@ -120,7 +155,6 @@ class PocketMinecraftServer{
self::$KEEP_CHUNKS_LOADED = $this->extraprops->get("keep-chunks-loaded");
self::$ENABLE_LIGHT_UPDATES = $this->extraprops->get("enable-light-updates");
PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data");
MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai");
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
if(self::$FORCE_20_TPS){

View file

@ -2,7 +2,6 @@
class MobController
{
public static $ADVANCED = false;
public static $AUTOJUMP = false;
public static $landed = false;
public static $DANGEROUS_BLOCKS = [

View file

@ -35,6 +35,9 @@ class Config{
* @var array
*/
private $config;
private $comments;
/**
* @var string
*/
@ -54,8 +57,8 @@ class Config{
* @param array $default
* @param null|boolean $correct
*/
public function __construct($file, $type = CONFIG_DETECT, $default = [], &$correct = null){
$this->load($file, $type, $default);
public function __construct($file, $type = CONFIG_DETECT, $default = [], &$correct = null, $comments = []){
$this->load($file, $type, $default, comments:$comments);
$correct = $this->check();
}
@ -66,13 +69,14 @@ class Config{
*
* @return boolean
*/
public function load($file, $type = CONFIG_DETECT, $default = []){
public function load($file, $type = CONFIG_DETECT, $default = [], $comments = []){
$this->correct = true;
$this->type = (int) $type;
$this->file = $file;
if(!is_array($default)){
$default = [];
}
$this->comments = $comments;
if(!file_exists($file)){
$this->config = $default;
$this->save();
@ -113,9 +117,8 @@ class Config{
if(!is_array($this->config)){
$this->config = $default;
}
if($this->fillDefaults($default, $this->config) > 0){
$this->save();
}
$this->fillDefaults($default, $this->config);
$this->save();
}else{
return false;
}
@ -158,6 +161,16 @@ class Config{
private function writeProperties(){
$content = "#Properties Config file\r\n#" . date("D M j H:i:s T Y") . "\r\n";
foreach($this->config as $k => $v){
//evil \r\n
if(isset($this->comments[$k])){
$com = $this->comments[$k];
$gen = "";
if(!is_array($com)) $gen .= "#$com\r\n";
else{
foreach($com as $lin) $gen .= "#$lin\r\n";
}
$content .= $gen;
}
if(is_bool($v) === true){
$v = $v === true ? "on" : "off";
}elseif(is_array($v)){