Merge pull request #49 from Sunch233/master-enchant

a big code enchant
This commit is contained in:
GameHerobrine 2024-08-17 16:23:54 +03:00 • committed by GitHub
commit 83585f8d6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 408 additions and 702 deletions

View file

@ -130,7 +130,7 @@ class AchievementAPI{
return false; return false;
} }
if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){ if(!isset($player->achievements[$achievementId]) or !$player->achievements[$achievementId]){
return false; return false;
} }
return true; return true;
@ -140,7 +140,7 @@ class AchievementAPI{
if(isset(self::$achievements[$achievementId])){ if(isset(self::$achievements[$achievementId])){
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]); $result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]);
if($result !== false and $result !== true){ if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){ if(ServerAPI::request()->api->getProperty("announce-player-achievements")){
ServerAPI::request()->api->chat->broadcast($player->username . " has just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]"); ServerAPI::request()->api->chat->broadcast($player->username . " has just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");
}else{ }else{
$player->sendChat("You have just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]"); $player->sendChat("You have just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");

View file

@ -145,17 +145,11 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){ if($generator !== false and class_exists($generator)){
$generator = new $generator($options); $generator = new $generator($options);
}else{ }else{
switch(strtoupper($this->server->api->getProperty("level-type"))){ $generator = match (strtoupper($this->server->api->getProperty("level-type"))) {
case "FLAT": "FLAT" => new SuperflatGenerator($options),
$generator = new SuperflatGenerator($options); "VANILLA" => new VanillaGenerator($options),
break; default => new TemporalGenerator($options),
case "VANILLA": };
$generator = new VanillaGenerator($options);
break;
default:
$generator = new TemporalGenerator($options);
break;
}
} }
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed); $gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate(); $gen->generate();

View file

@ -57,38 +57,18 @@ class PlayerAPI{
} }
} }
}else{ }else{
switch($data["cause"]){ $message = match ($data["cause"]) {
case "cactus": "cactus" => " was pricked to death",
$message = " was pricked to death"; "lava" => " tried to swim in lava",
break; "fire" => " went up in flames",
case "lava": "burning" => " burned to death",
$message = " tried to swim in lava"; "suffocation" => " suffocated in a wall",
break; "water" => " drowned",
case "fire": "void" => " fell out of the world",
$message = " went up in flames"; "fall" => " hit the ground too hard",
break; "explosion" => " blew up",
case "burning": default => " died",
$message = " burned to death"; };
break;
case "suffocation":
$message = " suffocated in a wall";
break;
case "water":
$message = " drowned";
break;
case "void":
$message = " fell out of the world";
break;
case "fall":
$message = " hit the ground too hard";
break;
case "explosion":
$message = " blew up";
break;
default:
$message = " died";
break;
}
} }
$this->server->api->chat->broadcast($data["player"]->username . $message); $this->server->api->chat->broadcast($data["player"]->username . $message);
return true; return true;
@ -190,8 +170,8 @@ class PlayerAPI{
} }
break; break;
case "tp": case "tp":
if(count($args) <= 2 or substr($args[0], 0, 2) === "w:" or substr($args[1], 0, 2) === "w:"){ if(count($args) <= 2 or str_starts_with($args[0], "w:") or str_starts_with($args[1], "w:")){
if((!isset($args[1]) or substr($args[0], 0, 2) === "w:") and isset($args[0]) and ($issuer instanceof Player)){ if((!isset($args[1]) or str_starts_with($args[0], "w:")) and isset($args[0]) and ($issuer instanceof Player)){
$name = $issuer->username; $name = $issuer->username;
$target = implode(" ", $args); $target = implode(" ", $args);
}elseif(isset($args[1]) and isset($args[0])){ }elseif(isset($args[1]) and isset($args[0])){
@ -297,7 +277,7 @@ class PlayerAPI{
} }
public function teleport(&$name, &$target){ public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){ if(str_starts_with($target, "w:")){
$lv = $this->server->api->level->get(substr($target, 2)); $lv = $this->server->api->level->get(substr($target, 2));
if($lv instanceof Level){ if($lv instanceof Level){
$origin = $this->get($name); $origin = $this->get($name);

View file

@ -55,7 +55,7 @@ class PluginAPI extends stdClass{
return; return;
} }
foreach($this->plugins as $p){ foreach($this->plugins as $p){
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();}; if(method_exists($p[0], "__destruct")) $p[0]->__destruct();
} }
unset($this->plugins); unset($this->plugins);
} }

View file

@ -152,7 +152,7 @@ class ServerAPI{
//define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s //define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals"); MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs"); MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
if($this->getProperty("upnp-forwarding") == true){ if($this->getProperty("upnp-forwarding")){
console("[INFO] [UPnP] Trying to port forward..."); console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("server-port")); UPnP_PortForward($this->getProperty("server-port"));
} }
@ -245,7 +245,7 @@ class ServerAPI{
public function setProperty($name, $value, $save = true){ public function setProperty($name, $value, $save = true){
$this->config->set($name, $value); $this->config->set($name, $value);
if($save == true){ if($save){
$this->writeProperties(); $this->writeProperties();
} }
$this->loadProperties(); $this->loadProperties();

View file

@ -31,7 +31,7 @@ class TimeAPI{
$p = strtolower(array_shift($args)); $p = strtolower(array_shift($args));
switch($p){ switch($p){
case "check": case "check":
if(substr($args[0] ?? "", 0, 2) === "w:"){ if(str_starts_with($args[0] ?? "", "w:")){
$levelName = preg_replace("/w:/", "", $args[0]); $levelName = preg_replace("/w:/", "", $args[0]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
@ -44,7 +44,7 @@ class TimeAPI{
$output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n"; $output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
break; break;
case "add": case "add":
if(substr($args[1] ?? "", 0, 2) === "w:"){ if(str_starts_with($args[1] ?? "", "w:")){
$levelName = preg_replace("/w:/", "", $args[1]); $levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
@ -65,7 +65,7 @@ class TimeAPI{
$output .= "Added $addTime ticks" . $world . "\n"; $output .= "Added $addTime ticks" . $world . "\n";
break; break;
case "set": case "set":
if(isset($args[1]) and substr($args[1], 0, 2) === "w:"){ if(isset($args[1]) and str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]); $levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){
@ -92,7 +92,7 @@ class TimeAPI{
case "day": case "day":
case "sunset": case "sunset":
case "night": case "night":
if(count($args) > 1 && substr($args[1], 0, 2) === "w:"){ if(count($args) > 1 && str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]); $levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){

View file

@ -413,11 +413,7 @@ class Player{
* @return Item * @return Item
*/ */
public function getSlot($slot){ public function getSlot($slot){
if(isset($this->inventory[(int) $slot])){ return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0);
return $this->inventory[(int) $slot];
}else{
return BlockAPI::getItem(AIR, 0, 0);
}
} }
/** /**
@ -724,11 +720,7 @@ class Player{
* @return Item * @return Item
*/ */
public function getArmor($slot){ public function getArmor($slot){
if(isset($this->armor[(int) $slot])){ return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0);
return $this->armor[(int) $slot];
}else{
return BlockAPI::getItem(AIR, 0, 0);
}
} }
public function setArmor($slot, Item $armor, $send = true){ public function setArmor($slot, Item $armor, $send = true){
@ -779,7 +771,7 @@ class Player{
if($w === $data["tile"]){ if($w === $data["tile"]){
$pk = new ContainerSetSlotPacket; $pk = new ContainerSetSlotPacket;
$pk->windowid = $id; $pk->windowid = $id;
$pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"] : 0); $pk->slot = $data["slot"] + ($data["offset"] ?? 0);
$pk->item = $data["slotdata"]; $pk->item = $data["slotdata"];
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -1730,7 +1722,7 @@ class Player{
$pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level); $pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level);
$pData = $this->data->get("position"); $pData = $this->data->get("position");
$this->teleport($pos, isset($pData["yaw"]) ? $pData["yaw"] : false, isset($pData["pitch"]) ? $pData["pitch"] : false, true, true); $this->teleport($pos, $pData["yaw"] ?? false, $pData["pitch"] ?? false, true, true);
$this->entity->setHealth($this->data->get("health"), "spawn", true); $this->entity->setHealth($this->data->get("health"), "spawn", true);
$this->spawned = true; $this->spawned = true;
$this->server->api->player->spawnAllPlayers($this); $this->server->api->player->spawnAllPlayers($this);

View file

@ -106,7 +106,7 @@ class PocketMinecraftServer{
if(self::$FORCE_20_TPS){ if(self::$FORCE_20_TPS){
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!"); ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
} }
if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-msg")){
if($this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled."); console("[INFO] Discord Logger is enabled.");
}else{ }else{
@ -226,7 +226,7 @@ class PocketMinecraftServer{
} }
public function send2Discord($msg){ public function send2Discord($msg){
if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none"){
$url = $this->extraprops->get("discord-webhook-url"); $url = $this->extraprops->get("discord-webhook-url");
$name = $this->extraprops->get("discord-bot-name"); $name = $this->extraprops->get("discord-bot-name");
$this->asyncOperation(ASYNC_CURL_POST, [ $this->asyncOperation(ASYNC_CURL_POST, [
@ -548,7 +548,7 @@ class PocketMinecraftServer{
$this->custom["times_" . $CID] = 0; $this->custom["times_" . $CID] = 0;
} }
$ln = 15; $ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){ if($this->description == "" or !str_ends_with($this->description, " ")){
$this->description .= " "; $this->description .= " ";
} }
$txt = substr($this->description, $this->custom["times_" . $CID], $ln); $txt = substr($this->description, $this->custom["times_" . $CID], $ln);
@ -688,7 +688,7 @@ class PocketMinecraftServer{
E_DEPRECATED => "E_DEPRECATED", E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED",
]; ];
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"]; $er["type"] = $errorConversion[$er["type"]] ?? $er["type"];
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n"; $dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){ if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n"; $dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";

View file

@ -4,7 +4,7 @@ set_time_limit(0);
if(ini_get("date.timezone") == ""){ //No Timezone set if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT"); date_default_timezone_set("GMT");
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){ if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){
$time = time(); $time = time();
$time -= $time % 60; $time -= $time % 60;
//Example: USA //Example: USA
@ -24,7 +24,7 @@ if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set($d); date_default_timezone_set($d);
}else{ }else{
$d = @date_default_timezone_get(); $d = @date_default_timezone_get();
if(strpos($d, "/") === false){ if(!str_contains($d, "/")){
$d = timezone_name_from_abbr($d); $d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d); @ini_set("date.timezone", $d);
date_default_timezone_set($d); date_default_timezone_set($d);

View file

@ -7,7 +7,7 @@ require_once(FILE_PATH . "/src/functions.php");
/***REM_END***/ /***REM_END***/
define("DATA_PATH", realpath(arg("data-path", FILE_PATH)) . "/"); define("DATA_PATH", realpath(arg("data-path", FILE_PATH)) . "/");
if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === 0 ? false : true) === true and arg("disable-ansi", false) !== true){ if(arg("enable-ansi", !(strpos(strtoupper(php_uname("s")), "WIN") === 0)) === true and arg("disable-ansi", false) !== true){
define("ENABLE_ANSI", true); define("ENABLE_ANSI", true);
}else{ }else{
define("ENABLE_ANSI", false); define("ENABLE_ANSI", false);
@ -120,7 +120,7 @@ $inc = get_included_files();
$inc[] = array_shift($inc); $inc[] = array_shift($inc);
$srcdir = realpath(FILE_PATH . "src/"); $srcdir = realpath(FILE_PATH . "src/");
foreach($inc as $s){ foreach($inc as $s){
if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){ if(!str_contains(realpath(dirname($s)), $srcdir) and strtolower(basename($s)) !== "pocketmine-mp.php"){
continue; continue;
} }
$sha1sum ^= sha1_file($s, true); $sha1sum ^= sha1_file($s, true);
@ -130,7 +130,7 @@ ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OP
define("SOURCE_SHA1SUM", bin2hex($sha1sum)); define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/ /***REM_START***/
if(!file_exists(DATA_PATH . "server.properties") and arg("no-wizard", false) != true){ if(!file_exists(DATA_PATH . "server.properties") and !arg("no-wizard", false)){
$installer = new Installer(); $installer = new Installer();
} }
/***REM_END***/ /***REM_END***/

View file

@ -14,7 +14,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0); $this->setAge($data["Age"] ?? 0);
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){ if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
$this->setAge(-24000); $this->setAge(-24000);
} }

View file

@ -11,7 +11,7 @@ abstract class Creature extends Living{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = false; //force for now $this->inPanic = false; //force for now
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic"); $this->setHealth($this->data["Health"] ?? 1, "generic");
$this->enableAutojump = true; $this->enableAutojump = true;
$this->searchForClosestPlayers = true; $this->searchForClosestPlayers = true;
} }

View file

@ -141,7 +141,7 @@ class Entity extends Position
$this->isStatic = false; $this->isStatic = false;
$this->name = ""; $this->name = "";
$this->gravity = 0.08; $this->gravity = 0.08;
$this->state = $this->data["State"] = isset($this->data["State"]) ? $this->data["State"] : 0; $this->state = $this->data["State"] = $this->data["State"] ?? 0;
$this->tickCounter = 0; $this->tickCounter = 0;
$this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0; $this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0; $this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0;
@ -151,7 +151,7 @@ class Entity extends Position
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0; $this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
$this->speed = 0; $this->speed = 0;
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0; $this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0;
$this->headYaw = isset($this->data["headYaw"]) ? $this->data["headYaw"] : $this->yaw; $this->headYaw = $this->data["headYaw"] ?? $this->yaw;
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0; $this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0;
$this->position = array( $this->position = array(
"level" => $this->level, "level" => $this->level,
@ -178,9 +178,9 @@ class Entity extends Position
break; break;
case ENTITY_OBJECT: case ENTITY_OBJECT:
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; $this->x = $this->data["TileX"] ?? $this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y; $this->y = $this->data["TileY"] ?? $this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z; $this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic"); $this->setHealth(1, "generic");
$this->stepHeight = false; $this->stepHeight = false;
$this->setSize(1, 1); $this->setSize(1, 1);
@ -383,7 +383,7 @@ class Entity extends Position
* @return boolean * @return boolean
*/ */
public function isPickable(){ public function isPickable(){
return $this->isPlayer() ? !$this->dead : false; return $this->isPlayer() && !$this->dead;
} }
public function handleLavaMovement(){ //TODO maybe try merging with water? public function handleLavaMovement(){ //TODO maybe try merging with water?
@ -1496,7 +1496,6 @@ class Entity extends Position
{ {
if($this->class === ENTITY_PLAYER){ if($this->class === ENTITY_PLAYER){
$this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false); $this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false);
return;
} }
} }

View file

@ -51,7 +51,7 @@ class EntityAI
* @return TaskBase | false * @return TaskBase | false
*/ */
public function getTask($id){ public function getTask($id){
return isset($this->tasks[$id]) ? $this->tasks[$id] : false; return $this->tasks[$id] ?? false;
} }
public function isStarted($id){ public function isStarted($id){

View file

@ -87,7 +87,7 @@ class TaskAttackPlayer extends TaskBase
} }
public function onEnd(EntityAI $ai) public function onEnd(EntityAI $ai)
{ {
$ai->entity->target = false; $ai->entity->target = false;
} }

View file

@ -7,7 +7,7 @@ class Chicken extends Animal{
$this->timeUntilEgg = mt_rand(0,6000) + 6000; $this->timeUntilEgg = mt_rand(0,6000) + 6000;
$this->setSize(0.4, 0.7); $this->setSize(0.4, 0.7);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->setHealth($this->data["Health"] ?? 4, "generic");
$this->setName('Chicken'); $this->setName('Chicken');
$this->setSpeed(0.25); $this->setSpeed(0.25);
@ -37,10 +37,6 @@ class Chicken extends Animal{
public function fall(){} //chickens have no fall dmg? public function fall(){} //chickens have no fall dmg?
public function update($now){
parent::update($now);
}
public function dropAnEgg(){ public function dropAnEgg(){
if($this->closed){ if($this->closed){
return; return;

View file

@ -5,7 +5,7 @@ class Cow extends Animal{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 1.3); $this->setSize(0.9, 1.3);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setHealth($this->data["Health"] ?? 10, "generic");
$this->setName("Cow"); $this->setName("Cow");
$this->setSpeed(0.2); $this->setSpeed(0.2);
$this->ai->addTask(new TaskRandomWalk(0.8)); $this->ai->addTask(new TaskRandomWalk(0.8));

View file

@ -5,7 +5,7 @@ class Pig extends Animal implements Rideable{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 0.9); $this->setSize(0.9, 0.9);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic"); $this->setHealth($this->data["Health"] ?? 10, "generic");
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->setName("Pig"); $this->setName("Pig");
$this->setSpeed(0.25); $this->setSpeed(0.25);

View file

@ -7,10 +7,10 @@ class Sheep extends Animal{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 1.3); $this->setSize(0.9, 1.3);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); $this->setHealth($this->data["Health"] ?? 8, "generic");
$this->setName("Sheep"); $this->setName("Sheep");
$this->data["Sheared"] = isset($this->data["Sheared"]) ? $this->data["Sheared"] : 0; $this->data["Sheared"] = $this->data["Sheared"] ?? 0;
$this->data["Color"] = isset($this->data["Color"]) ? $this->data["Color"] : $this->sheepColor(); $this->data["Color"] = $this->data["Color"] ?? $this->sheepColor();
$this->setSpeed(0.25); $this->setSpeed(0.25);
$this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskRandomWalk(1.0));

View file

@ -7,7 +7,7 @@ class Creeper extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.6, 1.7); $this->setSize(0.6, 1.7);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic"); $this->setHealth($this->data["Health"] ?? 16, "generic");
$this->setName("Creeper"); $this->setName("Creeper");
$this->ignited = 0; $this->ignited = 0;
$this->setSpeed(0.25); $this->setSpeed(0.25);

View file

@ -4,7 +4,7 @@ class PigZombie extends Monster{ //TODO extends zombie
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.3, 1.95); $this->setSize(0.3, 1.95);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setHealth($this->data["Health"] ?? 12, "generic");
$this->setName("Pigman"); $this->setName("Pigman");
$this->setSpeed(0.25); $this->setSpeed(0.25);
$this->isImmuneToFire = true; $this->isImmuneToFire = true;

View file

@ -4,7 +4,7 @@ class Skeleton extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.6, 1.99); $this->setSize(0.6, 1.99);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); $this->setHealth($this->data["Health"] ?? 10, "generic");
$this->setName("Skeleton"); $this->setName("Skeleton");
$this->ai->removeTask("TaskAttackPlayer"); $this->ai->removeTask("TaskAttackPlayer");
$this->setSpeed(0.25); $this->setSpeed(0.25);

View file

@ -5,7 +5,7 @@ class Spider extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->setSize(1.4, 0.9); $this->setSize(1.4, 0.9);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic"); $this->setHealth($this->data["Health"] ?? 8, "generic");
$this->setName("Spider"); $this->setName("Spider");
$this->setSpeed(0.3); $this->setSpeed(0.3);
$this->ai->addTask(new TaskRandomWalk(1.2)); $this->ai->addTask(new TaskRandomWalk(1.2));

View file

@ -4,7 +4,7 @@ class Zombie extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->setSize(0.6, 1.85); $this->setSize(0.6, 1.85);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic"); $this->setHealth($this->data["Health"] ?? 12, "generic");
$this->setName("Zombie"); $this->setName("Zombie");
$this->setSpeed(0.23); $this->setSpeed(0.23);

View file

@ -139,7 +139,6 @@ class Arrow extends Entity{
++$this->groundTicks; ++$this->groundTicks;
if($this->groundTicks >= 1200){ //TODO customizeable? if($this->groundTicks >= 1200){ //TODO customizeable?
$this->close(); $this->close();
return;
} }
}else{ }else{
$this->inGround = false; $this->inGround = false;
@ -278,4 +277,4 @@ class Arrow extends Entity{
$player->dataPacket($pk); $player->dataPacket($pk);
} }
} }
} }

View file

@ -59,9 +59,9 @@ class Minecart extends Vehicle{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->canBeAttacked = true; $this->canBeAttacked = true;
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x; $this->x = $this->data["TileX"] ?? $this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; $this->y = $this->data["TileY"] ?? $this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z; $this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic"); //orig: 3 $this->setHealth(1, "generic"); //orig: 3
$this->setSize(0.98, 0.7); $this->setSize(0.98, 0.7);
$this->yOffset = $this->height / 2; $this->yOffset = $this->height / 2;

View file

@ -5,9 +5,9 @@ class Painting extends Entity{
const TYPE = OBJECT_PAINTING; const TYPE = OBJECT_PAINTING;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; $this->x = $this->data["TileX"] ?? $this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y; $this->y = $this->data["TileY"] ?? $this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z; $this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic"); $this->setHealth(1, "generic");
$this->canBeAttacked = true; $this->canBeAttacked = true;
$this->width = 1; $this->width = 1;

View file

@ -118,11 +118,7 @@ function arg($name, $default = false){
$arguments = arguments($argv); $arguments = arguments($argv);
} }
if(isset($arguments["commands"][$name])){ return $arguments["commands"][$name] ?? $default;
return $arguments["commands"][$name];
}else{
return $default;
}
} }
function arguments($args){ function arguments($args){
@ -144,7 +140,7 @@ function arguments($args){
foreach($args as $arg){ foreach($args as $arg){
// Is it a command? (prefixed with --) // Is it a command? (prefixed with --)
if(substr($arg, 0, 2) === '--'){ if(str_starts_with($arg, '--')){
$value = preg_split('/[= ]/', $arg, 2); $value = preg_split('/[= ]/', $arg, 2);
$com = substr(array_shift($value), 2); $com = substr(array_shift($value), 2);
@ -156,13 +152,12 @@ function arguments($args){
} }
// Is it a flag? (prefixed with -) // Is it a flag? (prefixed with -)
if(substr($arg, 0, 1) === '-'){ if(str_starts_with($arg, '-')){
$ret['flags'][] = substr($arg, 1); $ret['flags'][] = substr($arg, 1);
continue; continue;
} }
$ret['input'][] = $arg; $ret['input'][] = $arg;
continue;
} }
@ -180,25 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(ENABLE_ANSI === true){ if(ENABLE_ANSI === true){
$add = ""; $add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){ if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){ $add .= match ($matches[1]) {
case "ERROR": "ERROR", "SEVERE" => FORMAT_RED,
case "SEVERE": "INTERNAL", "DEBUG" => FORMAT_WHITE,
$add .= FORMAT_RED; "WARNING" => FORMAT_YELLOW,
break; "NOTICE" => FORMAT_AQUA,
case "INTERNAL": default => FORMAT_GRAY,
case "DEBUG": };
$add .= FORMAT_WHITE;
break;
case "WARNING":
$add .= FORMAT_YELLOW;
break;
case "NOTICE":
$add .= FORMAT_AQUA;
break;
default:
$add .= FORMAT_GRAY;
break;
}
} }
$message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET); $message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
}else{ }else{
@ -218,7 +201,7 @@ function getTrace($start = 1){
foreach($trace[$i]["args"] as $name => $value){ foreach($trace[$i]["args"] as $name => $value){
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", "; $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
} }
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? $trace[$i]["file"] : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; $messages[] = "#$j " . ($trace[$i]["file"] ?? "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
} }
return $messages; return $messages;
} }
@ -244,7 +227,7 @@ function error_handler($errno, $errstr, $errfile, $errline){
E_DEPRECATED => "E_DEPRECATED", E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED",
]; ];
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno; $errno = $errorConversion[$errno] ?? $errno;
console("[ERROR] A " . $errno . " error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0); console("[ERROR] A " . $errno . " error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
foreach(getTrace() as $i => $line){ foreach(getTrace() as $i => $line){
console("[TRACE] $line"); console("[TRACE] $line");

View file

@ -163,15 +163,15 @@ abstract class Block extends Position{
} }
public static function containsX($id, $v){ public static function containsX($id, $v){
return $v == null ? false : $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; return !($v == null) && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
} }
public static function containsY($id, $v){ public static function containsY($id, $v){
return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id]; return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
} }
public static function containsZ($id, $v){ public static function containsZ($id, $v){
return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id]; return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id];
} }
public static function updateShape(Level $level, $x, $y, $z){ public static function updateShape(Level $level, $x, $y, $z){

View file

@ -259,20 +259,14 @@ class Item{
//TODO remove? //TODO remove?
public function getPickaxeLevel(){ //Returns false or level of the pickaxe public function getPickaxeLevel(){ //Returns false or level of the pickaxe
switch($this->id){ return match ($this->id) {
case WOODEN_PICKAXE: WOODEN_PICKAXE => 1,
return 1; GOLDEN_PICKAXE => 2,
case GOLDEN_PICKAXE: STONE_PICKAXE => 3,
return 2; IRON_PICKAXE => 4,
case STONE_PICKAXE: DIAMOND_PICKAXE => 5,
return 3; default => false,
case IRON_PICKAXE: };
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
} }
public function isAxe(){ public function isAxe(){

View file

@ -80,7 +80,7 @@ class StairBlock extends TransparentBlock{
for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){ for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){
$v16 = $v11[$v15]; $v16 = $v11[$v15];
if($v16 == $v12){ if($v16 == $v12){
; //wat //wat
} }
} }
@ -360,4 +360,4 @@ class StairBlock extends TransparentBlock{
return array(); return array();
} }
} }
} }

View file

@ -11,21 +11,15 @@ class IronDoorBlock extends DoorBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){

View file

@ -93,21 +93,15 @@ class SlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -119,4 +113,4 @@ class SlabBlock extends TransparentBlock{
return array(); return array();
} }
} }
} }

View file

@ -89,21 +89,15 @@ class WoodSlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
} }
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -111,4 +105,4 @@ class WoodSlabBlock extends TransparentBlock{
array($this->id, $this->meta & 0x07, 1), array($this->id, $this->meta & 0x07, 1),
); );
} }
} }

View file

@ -9,21 +9,15 @@ class WoodStairsBlock extends StairBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
} }
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -31,4 +25,4 @@ class WoodStairsBlock extends StairBlock{
array($this->id, 0, 1), array($this->id, 0, 1),
); );
} }
} }

View file

@ -10,21 +10,15 @@ class CoalOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
case 2:
return 0.4;
case 1:
return 2.25;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
2 => 0.4,
1 => 2.25,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -37,4 +31,4 @@ class CoalOreBlock extends SolidBlock{
} }
} }
} }

View file

@ -10,15 +10,12 @@ class DiamondOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class DiamondOreBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -18,15 +18,12 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -39,4 +36,4 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
} }
} }
} }

View file

@ -10,15 +10,12 @@ class GoldOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class GoldOreBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,17 +10,13 @@ class IronOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -32,4 +28,4 @@ class IronOreBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,17 +10,13 @@ class LapisOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -33,4 +29,4 @@ class LapisOreBlock extends SolidBlock{
} }
} }
} }

View file

@ -10,21 +10,15 @@ class BricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class BricksBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -55,21 +55,15 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.7,
4 => 0.9,
3 => 1.35,
2 => 0.45,
1 => 2.65,
default => 17.5,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -88,4 +82,4 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
} }
return $drops; return $drops;
} }
} }

View file

@ -10,21 +10,15 @@ class CoalBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class CoalBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,21 +10,15 @@ class CobblestoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class CobblestoneBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,15 +10,12 @@ class DiamondBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
default:
return 25;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
default => 25,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class DiamondBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -21,21 +21,15 @@ class DoubleSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class DoubleWoodSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
} }
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -40,4 +34,4 @@ class DoubleWoodSlabBlock extends SolidBlock{
); );
} }
} }

View file

@ -10,15 +10,12 @@ class GoldBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class GoldBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -45,7 +45,6 @@ class GrassBlock extends SolidBlock{
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(295,0,1)); ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(295,0,1));
return; return;
} }
return;
} }
public static function onRandomTick(Level $level, $x, $y, $z){ public static function onRandomTick(Level $level, $x, $y, $z){
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){ if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){
@ -65,4 +64,4 @@ class GrassBlock extends SolidBlock{
} }
} }
} }

View file

@ -57,21 +57,15 @@ class IceBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.15;
case 3:
return 0.2;
case 2:
return 0.1;
case 1:
return 0.4;
default:
return 0.75;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.15,
3 => 0.2,
2 => 0.1,
1 => 0.4,
default => 0.75,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
default:
return 25;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
default => 25,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -32,4 +28,4 @@ class IronBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,17 +10,13 @@ class LapisBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -33,4 +29,4 @@ class LapisBlock extends SolidBlock{
} }
} }
} }

View file

@ -10,21 +10,15 @@ class MossStoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class MossStoneBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,21 +10,15 @@ class NetherBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class NetherBricksBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -10,21 +10,15 @@ class NetherrackBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.1;
case 3:
return 0.15;
case 2:
return 0.05;
case 1:
return 0.3;
default:
return 2;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.1,
3 => 0.15,
2 => 0.05,
1 => 0.3,
default => 2,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class NetherrackBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -16,21 +16,15 @@ class QuartzBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -42,4 +36,4 @@ class QuartzBlock extends SolidBlock{
return array(); return array();
} }
} }
} }

View file

@ -16,21 +16,15 @@ class SandstoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -43,4 +37,4 @@ class SandstoneBlock extends SolidBlock{
} }
} }
} }

View file

@ -10,21 +10,15 @@ class StoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -37,4 +31,4 @@ class StoneBlock extends SolidBlock{
} }
} }
} }

View file

@ -17,21 +17,15 @@ class StoneBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){ public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return 0.20; return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
} }
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
@ -44,4 +38,4 @@ class StoneBricksBlock extends SolidBlock{
} }
} }
} }

View file

@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_AXE: WOODEN_AXE => 1,
return 1; GOLDEN_AXE => 2,
case GOLDEN_AXE: STONE_AXE => 3,
return 2; IRON_AXE => 4,
case STONE_AXE: DIAMOND_AXE => 5,
return 3; default => false,
case IRON_AXE: };
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
} }
} }

View file

@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_HOE: WOODEN_HOE => 1,
return 1; GOLDEN_HOE => 2,
case GOLDEN_HOE: STONE_HOE => 3,
return 2; IRON_HOE => 4,
case STONE_HOE: DIAMOND_HOE => 5,
return 3; default => false,
case IRON_HOE: };
return 4;
case DIAMOND_HOE:
return 5;
default:
return false;
}
} }
} }

View file

@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_PICKAXE: WOODEN_PICKAXE => 1,
return 1; GOLDEN_PICKAXE => 2,
case GOLDEN_PICKAXE: STONE_PICKAXE => 3,
return 2; IRON_PICKAXE => 4,
case STONE_PICKAXE: DIAMOND_PICKAXE => 5,
return 3; default => false,
case IRON_PICKAXE: };
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
} }
} }

View file

@ -7,20 +7,14 @@ class ItemShovel extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_SHOVEL: WOODEN_SHOVEL => 1,
return 1; GOLDEN_SHOVEL => 2,
case GOLDEN_SHOVEL: STONE_SHOVEL => 3,
return 2; IRON_SHOVEL => 4,
case STONE_SHOVEL: DIAMOND_SHOVEL => 5,
return 3; default => false,
case IRON_SHOVEL: };
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
} }
} }

View file

@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool
} }
public function getLevel(){ public function getLevel(){
switch($this->id){ return match ($this->id) {
case WOODEN_SWORD: WOODEN_SWORD => 1,
return 1; GOLDEN_SWORD => 2,
case GOLDEN_SWORD: STONE_SWORD => 3,
return 2; IRON_SWORD => 4,
case STONE_SWORD: DIAMOND_SWORD => 5,
return 3; default => false,
case IRON_SWORD: };
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
} }
} }

View file

@ -16,7 +16,7 @@ class Matrix implements ArrayAccess{
for($r = 0; $r < $this->rows; ++$r){ for($r = 0; $r < $this->rows; ++$r){
$this->matrix[$r] = []; $this->matrix[$r] = [];
for($c = 0; $c < $this->columns; ++$c){ for($c = 0; $c < $this->columns; ++$c){
$this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0; $this->matrix[$r][$c] = $m[$r][$c] ?? 0;
} }
} }
} }
@ -140,15 +140,12 @@ class Matrix implements ArrayAccess{
if($this->isSquare() !== true){ if($this->isSquare() !== true){
return false; return false;
} }
switch($this->rows){ return match ($this->rows) {
case 1: 1 => 0,
return 0; 2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0],
case 2: 3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1],
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0]; default => false,
case 3: };
return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
}
return false;
} }
@ -166,4 +163,4 @@ class Matrix implements ArrayAccess{
return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")"; return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")";
} }
} }

View file

@ -104,22 +104,15 @@ class Vector3{
} }
public function getSide($side, $step = 1){ public function getSide($side, $step = 1){
switch((int) $side){ return match ((int)$side) {
case 0: 0 => new Vector3($this->x, $this->y - $step, $this->z),
return new Vector3($this->x, $this->y - $step, $this->z); 1 => new Vector3($this->x, $this->y + $step, $this->z),
case 1: 2 => new Vector3($this->x, $this->y, $this->z - $step),
return new Vector3($this->x, $this->y + $step, $this->z); 3 => new Vector3($this->x, $this->y, $this->z + $step),
case 2: 4 => new Vector3($this->x - $step, $this->y, $this->z),
return new Vector3($this->x, $this->y, $this->z - $step); 5 => new Vector3($this->x + $step, $this->y, $this->z),
case 3: default => $this,
return new Vector3($this->x, $this->y, $this->z + $step); };
case 4:
return new Vector3($this->x - $step, $this->y, $this->z);
case 5:
return new Vector3($this->x + $step, $this->y, $this->z);
default:
return $this;
}
} }
public function distance($x = 0, $y = 0, $z = 0){ public function distance($x = 0, $y = 0, $z = 0){
@ -277,4 +270,4 @@ class Vector3{
public function getIntermediateWithZValue(Vector3 $v, $y){ public function getIntermediateWithZValue(Vector3 $v, $y){
return $this->clipZ($v, $y); return $this->clipZ($v, $y);
} }
} }

View file

@ -15,7 +15,7 @@ class SetTimePacket extends RakNetDataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putInt($this->time); $this->putInt($this->time);
$this->putByte($this->started == true ? 0x80:0x00); $this->putByte($this->started ? 0x80:0x00);
} }
} }

View file

@ -39,7 +39,7 @@ class QueryHandler{
public function regenerateInfo(){ public function regenerateInfo(){
$str = ""; $str = "";
$plist = "NostalgiaCore " . MAJOR_VERSION; $plist = "NostalgiaCore " . MAJOR_VERSION;
if($this->server->extraprops->get("query-plugins") == true){ if($this->server->extraprops->get("query-plugins")){
$pl = $this->server->api->plugin->getList(); $pl = $this->server->api->plugin->getList();
if(count($pl) > 0){ if(count($pl) > 0){
$plist .= ":"; $plist .= ":";

View file

@ -38,37 +38,9 @@ abstract class RakNetInfo{
const ACK = 0xc0; const ACK = 0xc0;
public static function isValid($pid){ public static function isValid($pid){
switch((int) $pid){ return match ((int)$pid) {
case RakNetInfo::UNCONNECTED_PING: RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true,
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS: default => false,
case RakNetInfo::OPEN_CONNECTION_REQUEST_1: };
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
case RakNetInfo::UNCONNECTED_PONG:
case RakNetInfo::ADVERTISE_SYSTEM:
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
case RakNetInfo::NACK:
case RakNetInfo::ACK:
return true;
default:
return false;
}
} }
} }

View file

@ -143,7 +143,7 @@ class RakNetParser{
$orderChannel = false; $orderChannel = false;
} }
if($hasSplit == true){ if($hasSplit){
$splitCount = $this->getInt(); $splitCount = $this->getInt();
$splitID = $this->getShort(); $splitID = $this->getShort();
$splitIndex = $this->getInt(); $splitIndex = $this->getInt();

View file

@ -3,7 +3,7 @@
class CraftingRecipes{ class CraftingRecipes{
private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better! private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better!
// Building // Building
"CLAY:?x4=>CLAY_BLOCK:0x1", "CLAY:?x4=>CLAY_BLOCK:0x1",
"WOODEN_PLANKS:?x4=>WORKBENCH:0x1", "WOODEN_PLANKS:?x4=>WORKBENCH:0x1",
"GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1", "GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1",
@ -73,7 +73,7 @@ class CraftingRecipes{
]; ];
private static $big = [ // Probably means only craftable on crafting bench. Name it better! private static $big = [ // Probably means only craftable on crafting bench. Name it better!
// Building // Building
"WOOL:?x3,WOODEN_PLANKS:?x3=>BED:0x1", "WOOL:?x3,WOODEN_PLANKS:?x3=>BED:0x1",
"WOODEN_PLANKS:?x8=>CHEST:0x1", "WOODEN_PLANKS:?x8=>CHEST:0x1",
"STICK:?x6=>FENCE:0x2", "STICK:?x6=>FENCE:0x2",

View file

@ -26,7 +26,7 @@ abstract class Structure{
$this->mapSymToID[$sym] = $id; $this->mapSymToID[$sym] = $id;
} }
public function getMappingFor($sym){ public function getMappingFor($sym){
return isset($this->mapSymToID[$sym]) ? $this->mapSymToID[$sym] : Structure::MAP_NO_KEY; return $this->mapSymToID[$sym] ?? Structure::MAP_NO_KEY;
} }
protected function placeBlock($level, $sym, $tv){ protected function placeBlock($level, $sym, $tv){

View file

@ -15,6 +15,6 @@ class LightUtils{
$diffZ = ($source->z - $block->z); $diffZ = ($source->z - $block->z);
$distance = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ; $distance = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ;
$result = floor($source->getMaxLightValue() - $distance); $result = floor($source->getMaxLightValue() - $distance);
return $result <= 0 ? 0 : $result; return max($result, 0);
} }
} }

View file

@ -125,7 +125,7 @@ class MersenneTwister{
$this->init_with_integer(19650218); $this->init_with_integer(19650218);
$i = 1; $i = 1;
$j = 0; $j = 0;
$k = (N > $key_length ? N : $key_length); $k = (max(N, $key_length));
for(; $k; $k--){ for(; $k; $k--){
$mt[$i] = add_3($mt[$i] ^ $mt[$i] = add_3($mt[$i] ^
mul_by_1664525($mt[$i - 1] ^ (($mt[$i - 1] >> 30) & 3)), mul_by_1664525($mt[$i - 1] ^ (($mt[$i - 1] >> 30) & 3)),

View file

@ -63,7 +63,7 @@ class RailLogic
} }
public function canConnectTo(RailLogic $rail){ public function canConnectTo(RailLogic $rail){
return $this->connectsTo($rail) ? true : (count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true)); return $this->connectsTo($rail) || ((count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true)));
} }
public function hasNeighborRail($x, $y, $z){ public function hasNeighborRail($x, $y, $z){

View file

@ -4,7 +4,7 @@ class StopMessageThread extends Thread
{ {
private $page, $msg; private $page, $msg;
public function __construct(PocketMinecraftServer $server, $msg){ public function __construct(PocketMinecraftServer $server, $msg){
if($server->extraprops->get("discord-msg") == true and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){ if($server->extraprops->get("discord-msg") and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){
$this->msg = $server->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ", "<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg); $this->msg = $server->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ", "<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg);
$this->name = $server->extraprops->get("discord-bot-name"); $this->name = $server->extraprops->get("discord-bot-name");
$this->start(); $this->start();

View file

@ -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])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))"; 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])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))";
public static function getEntityTypeByID($id){ public static function getEntityTypeByID($id){
switch($id){ return match ($id) {
case 10: 10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB,
case 11: 62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT,
case 12: 66 => FALLING_SAND,
case 13: default => $id,
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;
} }
public static function wrapAngleTo360($angle) public static function wrapAngleTo360($angle)
@ -87,7 +70,7 @@ class Utils{
* PHP8 has internal function for doing it: {@link str_ends_with} * PHP8 has internal function for doing it: {@link str_ends_with}
*/ */
public static function endsWith($str, $check) { public static function endsWith($str, $check) {
return substr($str, -strlen($check)) === $check; return str_ends_with($str, $check);
} }
public static function hasEmoji($s){ public static function hasEmoji($s){
@ -148,7 +131,7 @@ class Utils{
public static function getOS(){ public static function getOS(){
$uname = php_uname("s"); $uname = php_uname("s");
if(stripos($uname, "Darwin") !== false){ if(stripos($uname, "Darwin") !== false){
if(strpos(php_uname("m"), "iP") === 0){ if(str_starts_with(php_uname("m"), "iP")){
return "ios"; return "ios";
}else{ }else{
return "mac"; return "mac";
@ -581,7 +564,7 @@ class Utils{
} }
public static function readBool($b){ public static function readBool($b){
return Utils::readByte($b, false) === 0 ? false : true; return Utils::readByte($b, false) != 0;
} }
public static function writeBool($b){ public static function writeBool($b){

View file

@ -376,7 +376,7 @@ class Level{
if(count($this->players) == 0) return false; if(count($this->players) == 0) return false;
if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla
foreach($this->players as $p){ foreach($this->players as $p){
if($p->isSleeping == false || $p->sleepingTime < 100){ if(!$p->isSleeping || $p->sleepingTime < 100){
return false; return false;
} }
} }
@ -906,7 +906,7 @@ class Level{
return false; return false;
} }
$now = microtime(true); $now = microtime(true);
if($this->stopTime == true){ if($this->stopTime){
$time = $this->startTime; $time = $this->startTime;
}else{ }else{
$time = $this->startTime + ($now - $this->startCheck) * 20; $time = $this->startTime + ($now - $this->startCheck) * 20;

View file

@ -133,8 +133,8 @@ class MobSpawner{
$b1 = $this->level->level->getBlockID($x, $y - 1, $z); $b1 = $this->level->level->getBlockID($x, $y - 1, $z);
if( if(
!StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) && !StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) &&
(StaticBlock::getIsSolid($b1) && ($grassOnly ? $b1 === GRASS : true) && (StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) &&
($highMob ? !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2) : true)) (!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2)))
){ ){
$allowed[] = $y; $allowed[] = $y;
} }