diff --git a/src/Player.php b/src/Player.php index 97d45111..3a98b0d4 100755 --- a/src/Player.php +++ b/src/Player.php @@ -960,11 +960,11 @@ class Player{ if($gm < 0 or $gm > 3 or $this->gamemode === $gm){ return false; } - + if($this->server->api->dhandle("player.gamemode.change", ["player" => $this, "gamemode" => $gm]) === false){ return false; } - + $inv =& $this->inventory; if($gm === VIEW){ $this->armor = []; @@ -988,23 +988,10 @@ class Player{ foreach($this->inventory as $slot => $item){ $inv[$slot] = BlockAPI::getItem(AIR, 0, 0); } + $this->blocked = true; $this->gamemode = $gm; - - $spwnPos = $this->getSpawn(); - $pk = new StartGamePacket(); - $pk->seed = $this->level->getSeed(); - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->spawnX = $spwnPos->x; - $pk->spawnY = $spwnPos->y; - $pk->spawnZ = $spwnPos->z; - $pk->generator = $this->level->generatorType; - $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; - $this->dataPacket($pk); - $this->sendSettings(); - + $this->sendChat("Your gamemode has been changed to " . $this->getGamemode() . ", you've to do a forced reconnect.\n"); + $this->server->schedule(30, [$this, "close"], "gamemode change", false, true); //Forces a kick } if($this->gamemode === SPECTATOR){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 34fa1b4c..34cc16c9 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -78,7 +78,7 @@ class PocketMinecraftServer{ "enable-mob-ai" => false, "enable-nether-reactor" => true, "enable-explosions" => true, - "enable-rail-connection" => false, + "enable-rail-connection" => true, "save-player-data" => true, "save-console-data" => true, "query-plugins" => false, diff --git a/src/utils/LightUtils.php b/src/utils/LightUtils.php index fb826eb8..9c775626 100644 --- a/src/utils/LightUtils.php +++ b/src/utils/LightUtils.php @@ -1,21 +1,12 @@ instanceof LightingBlock, $block: Block - */ public static function getLightValueFromNearbySource($source, $block){ if($source === null || $block === null){ return 0; } - $distance = sqrt(LightUtils::sqr($source->x - $block->x) + LightUtils::sqr($source->y - $block->y) + LightUtils::sqr($source->z - $block->z)); /*Distance between 2 3d objects*/ - $result = floor($source->getMaxLightValue() - $distance); //i dont need something like 0.2192032434454... - return $result <= 0 ? 0 : $result; //if result is smaller or equals 0 then return 0 else return result - } - - /* Used only internally for calculating 2^(2) */ - private static function sqr($val){ - return pow($val, 2); + $distance = sqrt(($source->x - $block->x)*($source->x - $block->x) + ($source->y - $block->y)*($source->y - $block->y) + ($source->z - $block->z)*($source->z - $block->z)); + $result = floor($source->getMaxLightValue() - $distance); + return $result < 0 ? 0 : $result; } } \ No newline at end of file diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 2bb6afce..af77f218 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -14,29 +14,12 @@ class Utils{ }*/ const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k\\xF0\\x9F..(\k\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; public static function getEntityTypeByID($id){ - switch($id){ - case 10: - case 11: - case 12: - case 13: - case 32: - case 33: - case 34: - case 35: - case 36: - return ENTITY_MOB; - case 62: - case 65: - case 80: - case 81: - case 82: - case 83: - case 84: - return ENTITY_OBJECT; - case 66: - return FALLING_SAND; - } - return $id; + return match($id){ + MOB_CHICKEN, MOB_COW, MOB_CREEPER, MOB_ENDERMAN, MOB_MOOSHROOM, MOB_PIG, MOB_PIGMAN, MOB_SHEEP, MOB_SILVERFISH, MOB_SKELETON, MOB_SLIME, MOB_SPIDER, + MOB_VILLAGER, MOB_WOLF, MOB_ZOMBIE => ENTITY_MOB, + OBJECT_ARROW, OBJECT_EGG, OBJECT_MINECART, OBJECT_PAINTING, OBJECT_PRIMEDTNT, OBJECT_SNOWBALL, OBJECT_TRIPOD_CAMERA => ENTITY_OBJECT, + default => $id, + }; } public static function wrapAngleTo360($angle)