mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Heap of bugfixes, cleanup and PHP 7 upgrades
This commit is contained in:
parent
c2a7c2c6cd
commit
2a7b736f18
@ -208,7 +208,7 @@ use pocketmine\utils\UUID;
|
||||
/**
|
||||
* Main class that handles networking, recovery, and packet sending to the server part
|
||||
*/
|
||||
class Player extends Human implements CommandSender, InventoryHolder, ChunkLoader, IPlayer, NetworkSession{
|
||||
class Player extends Human implements CommandSender, ChunkLoader, IPlayer, NetworkSession{
|
||||
|
||||
const SURVIVAL = 0;
|
||||
const CREATIVE = 1;
|
||||
@ -699,13 +699,11 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAchievement($achievementId){
|
||||
if(!isset(Achievement::$list[$achievementId]) or !isset($this->achievements)){
|
||||
$this->achievements = [];
|
||||
|
||||
if(!isset(Achievement::$list[$achievementId])){
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset($this->achievements[$achievementId]) and $this->achievements[$achievementId] != false;
|
||||
return isset($this->achievements[$achievementId]) and $this->achievements[$achievementId] !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -786,7 +784,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
private function unloadChunk($x, $z, Level $level = null){
|
||||
$level = $level === null ? $this->level : $level;
|
||||
$level = $level ?? $this->level;
|
||||
$index = Level::chunkHash($x, $z);
|
||||
if(isset($this->usedChunks[$index])){
|
||||
foreach($level->getChunkEntities($x, $z) as $entity){
|
||||
@ -1565,7 +1563,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$from = new Location($this->lastX, $this->lastY, $this->lastZ, $this->lastYaw, $this->lastPitch, $this->level);
|
||||
$to = $this->getLocation();
|
||||
|
||||
$delta = pow($this->lastX - $to->x, 2) + pow($this->lastY - $to->y, 2) + pow($this->lastZ - $to->z, 2);
|
||||
$delta = (($this->lastX - $to->x) ** 2) + (($this->lastY - $to->y) ** 2) + (($this->lastZ - $to->z) ** 2);
|
||||
$deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch);
|
||||
|
||||
if(!$revert and ($delta > 0.0001 or $deltaAngle > 1.0)){
|
||||
@ -1601,7 +1599,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
}
|
||||
|
||||
$this->speed = ($to->subtract($from))->divide($tickDiff);
|
||||
$this->speed = $to->subtract($from)->divide($tickDiff);
|
||||
}elseif($distanceSquared == 0){
|
||||
$this->speed = new Vector3(0, 0, 0);
|
||||
}
|
||||
@ -1828,7 +1826,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
|
||||
/** @var ByteTag $achievement */
|
||||
foreach($this->namedtag->Achievements as $achievement){
|
||||
$this->achievements[$achievement->getName()] = $achievement->getValue() > 0 ? true : false;
|
||||
$this->achievements[$achievement->getName()] = $achievement->getValue() !== 0;
|
||||
}
|
||||
|
||||
$this->namedtag->lastPlayed = new LongTag("lastPlayed", (int) floor(microtime(true) * 1000));
|
||||
@ -2653,7 +2651,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$diff = ($this->server->getTick() - $this->startAction);
|
||||
$p = $diff / 20;
|
||||
$f = min((($p ** 2) + $p * 2) / 3, 1) * 2;
|
||||
$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->getLevel(), $nbt, $this, $f == 2 ? true : false), $f);
|
||||
$ev = new EntityShootBowEvent($this, $bow, Entity::createEntity("Arrow", $this->getLevel(), $nbt, $this, $f == 2), $f);
|
||||
|
||||
if($f < 0.1 or $diff < 5){
|
||||
$ev->setCancelled();
|
||||
@ -3981,8 +3979,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
public function sendPosition(Vector3 $pos, float $yaw = null, float $pitch = null, int $mode = MovePlayerPacket::MODE_NORMAL, array $targets = null, float $baseOffsetOverride = null){
|
||||
$yaw = $yaw === null ? $this->yaw : $yaw;
|
||||
$pitch = $pitch === null ? $this->pitch : $pitch;
|
||||
$yaw = $yaw ?? $this->yaw;
|
||||
$pitch = $pitch ?? $this->pitch;
|
||||
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->entityRuntimeId = $this->getId();
|
||||
@ -4003,41 +4001,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
$this->newPosition = null;
|
||||
}
|
||||
|
||||
protected function checkChunks(){
|
||||
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){
|
||||
if($this->chunk !== null){
|
||||
$this->chunk->removeEntity($this);
|
||||
}
|
||||
$this->chunk = $this->level->getChunk($this->x >> 4, $this->z >> 4, true);
|
||||
|
||||
if(!$this->justCreated){
|
||||
$newChunk = $this->level->getChunkPlayers($this->x >> 4, $this->z >> 4);
|
||||
unset($newChunk[$this->getLoaderId()]);
|
||||
|
||||
/** @var Player[] $reload */
|
||||
$reload = [];
|
||||
foreach($this->hasSpawned as $player){
|
||||
if(!isset($newChunk[$player->getLoaderId()])){
|
||||
$this->despawnFrom($player);
|
||||
}else{
|
||||
unset($newChunk[$player->getLoaderId()]);
|
||||
$reload[] = $player;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($newChunk as $player){
|
||||
$this->spawnTo($player);
|
||||
}
|
||||
}
|
||||
|
||||
if($this->chunk === null){
|
||||
return;
|
||||
}
|
||||
|
||||
$this->chunk->addEntity($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -4075,6 +4038,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
* @param Vector3 $pos
|
||||
* @param float|null $yaw
|
||||
* @param float|null $pitch
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function teleportImmediate(Vector3 $pos, float $yaw = null, float $pitch = null) : bool{
|
||||
return $this->teleport($pos, $yaw, $pitch);
|
||||
|
@ -104,7 +104,7 @@ namespace pocketmine {
|
||||
error_reporting(-1);
|
||||
|
||||
set_error_handler(function($severity, $message, $file, $line){
|
||||
if((error_reporting() & $severity)){
|
||||
if(error_reporting() & $severity){
|
||||
throw new \ErrorException($message, 0, $severity, $file, $line);
|
||||
}else{ //stfu operator
|
||||
return true;
|
||||
@ -395,7 +395,7 @@ namespace pocketmine {
|
||||
return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value))));
|
||||
}, $args));
|
||||
}
|
||||
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
|
||||
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? cleanPath($trace[$i]["file"]) : "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
|
||||
}
|
||||
|
||||
return $messages;
|
||||
|
@ -1170,7 +1170,7 @@ class Server{
|
||||
}
|
||||
}
|
||||
|
||||
return $this->propertyCache[$variable] === null ? $defaultValue : $this->propertyCache[$variable];
|
||||
return $this->propertyCache[$variable] ?? $defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2264,14 +2264,14 @@ class Server{
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_ADD;
|
||||
$pk->entries[] = [$uuid, $entityId, $name, $skinId, $skinData];
|
||||
$this->broadcastPacket($players === null ? $this->playerList : $players, $pk);
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
public function removePlayerListData(UUID $uuid, array $players = null){
|
||||
$pk = new PlayerListPacket();
|
||||
$pk->type = PlayerListPacket::TYPE_REMOVE;
|
||||
$pk->entries[] = [$uuid];
|
||||
$this->broadcastPacket($players === null ? $this->playerList : $players, $pk);
|
||||
$this->broadcastPacket($players ?? $this->playerList, $pk);
|
||||
}
|
||||
|
||||
public function sendFullPlayerListData(Player $p){
|
||||
|
@ -113,7 +113,7 @@ class Bed extends Transparent{
|
||||
3 => 5,
|
||||
];
|
||||
$d = $player instanceof Player ? $player->getDirection() : 0;
|
||||
$next = $this->getSide($faces[(($d + 3) % 4)]);
|
||||
$next = $this->getSide($faces[($d + 3) % 4]);
|
||||
$downNext = $this->getSide(0);
|
||||
if($next->canBeReplaced() === true and $downNext->isTransparent() === false){
|
||||
$meta = (($d + 3) % 4) & 0x03;
|
||||
|
@ -234,7 +234,7 @@ abstract class Door extends Transparent{
|
||||
2 => 2,
|
||||
3 => 5,
|
||||
];
|
||||
$next = $this->getSide($face[(($direction + 2) % 4)]);
|
||||
$next = $this->getSide($face[($direction + 2) % 4]);
|
||||
$next2 = $this->getSide($face[$direction]);
|
||||
$metaUp = 0x08;
|
||||
if($next->getId() === $this->getId() or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
|
||||
|
@ -49,13 +49,12 @@ class Torch extends Flowable{
|
||||
$below = $this->getSide(0);
|
||||
$side = $this->getDamage();
|
||||
$faces = [
|
||||
0 => 0,
|
||||
1 => 4,
|
||||
2 => 5,
|
||||
3 => 2,
|
||||
4 => 3,
|
||||
5 => 0,
|
||||
6 => 0,
|
||||
0 => 0,
|
||||
5 => 0
|
||||
];
|
||||
|
||||
if($this->getSide($faces[$side])->isTransparent() === true and !($side === 0 and ($below->getId() === self::FENCE or $below->getId() === self::COBBLE_WALL))){
|
||||
|
@ -79,7 +79,7 @@ abstract class Command{
|
||||
$this->name = $name;
|
||||
$this->setLabel($name);
|
||||
$this->setDescription($description);
|
||||
$this->usageMessage = $usageMessage === null ? "/" . $name : $usageMessage;
|
||||
$this->usageMessage = $usageMessage ?? ("/" . $name);
|
||||
$this->setAliases($aliases);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class CommandReader extends Thread{
|
||||
$this->buffer = new \Threaded;
|
||||
$opts = getopt("", ["disable-readline"]);
|
||||
|
||||
if((extension_loaded("readline") and !isset($opts["disable-readline"]) and !$this->isPipe(STDIN))){
|
||||
if(extension_loaded("readline") and !isset($opts["disable-readline"]) and !$this->isPipe(STDIN)){
|
||||
$this->type = self::TYPE_READLINE;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ class FormattedCommandAlias extends Command{
|
||||
throw new \InvalidArgumentException("Invalid replacement token");
|
||||
}
|
||||
|
||||
$position = intval(substr($formatString, $argStart, $index));
|
||||
$position = (int) (substr($formatString, $argStart, $index));
|
||||
|
||||
if($position === 0){
|
||||
throw new \InvalidArgumentException("Invalid replacement token");
|
||||
|
@ -52,7 +52,7 @@ class DumpMemoryCommand extends VanillaCommand{
|
||||
|
||||
++self::$executions;
|
||||
|
||||
$sender->getServer()->getMemoryManager()->dumpServerMemory(isset($args[1]) ? $args[1] : $sender->getServer()->getDataPath() . "/memoryDump_$token", 48, 80);
|
||||
$sender->getServer()->getMemoryManager()->dumpServerMemory($args[1] ?? ($sender->getServer()->getDataPath() . "/memoryDump_$token"), 48, 80);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class KickCommand extends VanillaCommand{
|
||||
|
||||
if(($player = $sender->getServer()->getPlayer($name)) instanceof Player){
|
||||
$player->kick($reason);
|
||||
if(strlen($reason) >= 1){
|
||||
if($reason !== ""){
|
||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kick.success.reason", [$player->getName(), $reason]));
|
||||
}else{
|
||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kick.success", [$player->getName()]));
|
||||
|
@ -203,17 +203,17 @@ class ParticleCommand extends VanillaCommand{
|
||||
|
||||
}
|
||||
|
||||
if(substr($name, 0, 10) === "iconcrack_"){
|
||||
if(strpos($name, "iconcrack_") === 0){
|
||||
$d = explode("_", $name);
|
||||
if(count($d) === 3){
|
||||
return new ItemBreakParticle($pos, Item::get((int) $d[1], (int) $d[2]));
|
||||
}
|
||||
}elseif(substr($name, 0, 11) === "blockcrack_"){
|
||||
}elseif(strpos($name, "blockcrack_") === 0){
|
||||
$d = explode("_", $name);
|
||||
if(count($d) === 2){
|
||||
return new TerrainParticle($pos, Block::get($d[1] & 0xff, $d[1] >> 12));
|
||||
}
|
||||
}elseif(substr($name, 0, 10) === "blockdust_"){
|
||||
}elseif(strpos($name, "blockdust_") === 0){
|
||||
$d = explode("_", $name);
|
||||
if(count($d) >= 4){
|
||||
return new DustParticle($pos, $d[1] & 0xff, $d[2] & 0xff, $d[3] & 0xff, isset($d[4]) ? $d[4] & 0xff : 255);
|
||||
|
@ -387,12 +387,12 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if(!isset($this->namedtag->OnGround)){
|
||||
$this->namedtag->OnGround = new ByteTag("OnGround", 0);
|
||||
}
|
||||
$this->onGround = $this->namedtag["OnGround"] > 0 ? true : false;
|
||||
$this->onGround = $this->namedtag["OnGround"] !== 0;
|
||||
|
||||
if(!isset($this->namedtag->Invulnerable)){
|
||||
$this->namedtag->Invulnerable = new ByteTag("Invulnerable", 0);
|
||||
}
|
||||
$this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
|
||||
$this->invulnerable = $this->namedtag["Invulnerable"] !== 0;
|
||||
|
||||
$this->attributeMap = new AttributeMap();
|
||||
$this->addAttributes();
|
||||
@ -640,7 +640,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
public function getEffect($effectId){
|
||||
return isset($this->effects[$effectId]) ? $this->effects[$effectId] : null;
|
||||
return $this->effects[$effectId] ?? null;
|
||||
}
|
||||
|
||||
public function hasEffect($effectId){
|
||||
@ -866,7 +866,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
|
||||
$pk = new SetEntityDataPacket();
|
||||
$pk->entityRuntimeId = $this->getId();
|
||||
$pk->metadata = $data === null ? $this->dataProperties : $data;
|
||||
$pk->metadata = $data ?? $this->dataProperties;
|
||||
|
||||
foreach($player as $p){
|
||||
if($p === $this){
|
||||
@ -1794,8 +1794,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
*/
|
||||
public function teleport(Vector3 $pos, float $yaw = null, float $pitch = null) : bool{
|
||||
if($pos instanceof Location){
|
||||
$yaw = $yaw === null ? $pos->yaw : $yaw;
|
||||
$pitch = $pitch === null ? $pos->pitch : $pitch;
|
||||
$yaw = $yaw ?? $pos->yaw;
|
||||
$pitch = $pitch ?? $pos->pitch;
|
||||
}
|
||||
$from = Position::fromObject($this, $this->level);
|
||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
|
||||
@ -1807,7 +1807,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$pos = $ev->getTo();
|
||||
|
||||
$this->setMotion($this->temporalVector->setComponents(0, 0, 0));
|
||||
if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false){
|
||||
if($this->setPositionAndRotation($pos, $yaw ?? $this->yaw, $pitch ?? $this->pitch) !== false){
|
||||
$this->resetFallDistance();
|
||||
$this->onGround = true;
|
||||
|
||||
|
@ -141,13 +141,16 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
|
||||
$old = $attr->getValue();
|
||||
$attr->setValue($new);
|
||||
|
||||
$reset = false;
|
||||
// ranges: 18-20 (regen), 7-17 (none), 1-6 (no sprint), 0 (health depletion)
|
||||
foreach([17, 6, 0] as $bound){
|
||||
if(($old > $bound) !== ($new > $bound)){
|
||||
$reset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isset($reset)){
|
||||
if($reset){
|
||||
$this->foodTickTimer = 0;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ use pocketmine\network\mcpe\protocol\AddEntityPacket;
|
||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Squid extends WaterAnimal implements Ageable{
|
||||
class Squid extends WaterAnimal{
|
||||
const NETWORK_ID = 17;
|
||||
|
||||
public $width = 0.95;
|
||||
|
@ -45,7 +45,7 @@ abstract class Event{
|
||||
* @return string
|
||||
*/
|
||||
final public function getEventName() : string{
|
||||
return $this->eventName === null ? get_class($this) : $this->eventName;
|
||||
return $this->eventName ?? get_class($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,13 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Cancellable;
|
||||
|
||||
class BlockFormEvent extends BlockGrowEvent implements Cancellable{
|
||||
class BlockFormEvent extends BlockGrowEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
public function __construct(Block $block, Block $newState){
|
||||
parent::__construct($block, $newState);
|
||||
}
|
||||
|
||||
}
|
@ -24,9 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\event\Cancellable;
|
||||
|
||||
class BlockSpreadEvent extends BlockFormEvent implements Cancellable{
|
||||
class BlockSpreadEvent extends BlockFormEvent{
|
||||
public static $handlerList = null;
|
||||
|
||||
/** @var Block */
|
||||
|
@ -256,12 +256,12 @@ class CraftingManager{
|
||||
}
|
||||
|
||||
$hasRecipe = null;
|
||||
foreach($this->recipeLookup[$idx] as $recipe){
|
||||
if($recipe instanceof ShapelessRecipe){
|
||||
if($recipe->getIngredientCount() !== count($ingredients)){
|
||||
foreach($this->recipeLookup[$idx] as $possibleRecipe){
|
||||
if($possibleRecipe instanceof ShapelessRecipe){
|
||||
if($possibleRecipe->getIngredientCount() !== count($ingredients)){
|
||||
continue;
|
||||
}
|
||||
$checkInput = $recipe->getIngredientList();
|
||||
$checkInput = $possibleRecipe->getIngredientList();
|
||||
foreach($ingredients as $item){
|
||||
$amount = $item->getCount();
|
||||
foreach($checkInput as $k => $checkItem){
|
||||
@ -280,7 +280,7 @@ class CraftingManager{
|
||||
}
|
||||
|
||||
if(count($checkInput) === 0){
|
||||
$hasRecipe = $recipe;
|
||||
$hasRecipe = $possibleRecipe;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ class ShapedRecipe implements Recipe{
|
||||
* @return null|Item
|
||||
*/
|
||||
public function getIngredient($x, $y){
|
||||
return isset($this->ingredients[$y][$x]) ? $this->ingredients[$y][$x] : Item::get(Item::AIR);
|
||||
return $this->ingredients[$y][$x] ?? Item::get(Item::AIR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,36 +28,36 @@ interface TransactionGroup{
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
function getCreationTime();
|
||||
public function getCreationTime();
|
||||
|
||||
/**
|
||||
* @return Transaction[]
|
||||
*/
|
||||
function getTransactions();
|
||||
public function getTransactions();
|
||||
|
||||
/**
|
||||
* @return Inventory[]
|
||||
*/
|
||||
function getInventories();
|
||||
public function getInventories();
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*/
|
||||
function addTransaction(Transaction $transaction);
|
||||
public function addTransaction(Transaction $transaction);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function canExecute();
|
||||
public function canExecute();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function execute();
|
||||
public function execute();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
function hasExecuted();
|
||||
public function hasExecuted();
|
||||
|
||||
}
|
@ -49,7 +49,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
private static $cachedParser = null;
|
||||
|
||||
private static function parseCompoundTag(string $tag) : CompoundTag{
|
||||
if(strlen($tag) === 0){
|
||||
if($tag === ""){
|
||||
throw new \InvalidArgumentException("No NBT data found in supplied string");
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ class BaseLang{
|
||||
public function translate(TextContainer $c){
|
||||
if($c instanceof TranslationContainer){
|
||||
$baseText = $this->internalGet($c->getText());
|
||||
$baseText = $this->parseTranslation($baseText !== null ? $baseText : $c->getText());
|
||||
$baseText = $this->parseTranslation($baseText ?? $c->getText());
|
||||
|
||||
foreach($c->getParameters() as $i => $p){
|
||||
$baseText = str_replace("{%$i}", $this->parseTranslation($p), $baseText);
|
||||
|
@ -71,7 +71,7 @@ class Explosion{
|
||||
$vector = new Vector3(0, 0, 0);
|
||||
$vBlock = new Vector3(0, 0, 0);
|
||||
|
||||
$mRays = intval($this->rays - 1);
|
||||
$mRays = (int) ($this->rays - 1);
|
||||
for($i = 0; $i < $this->rays; ++$i){
|
||||
for($j = 0; $j < $this->rays; ++$j){
|
||||
for($k = 0; $k < $this->rays; ++$k){
|
||||
|
@ -819,7 +819,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$pk->z = $z + 0.5;
|
||||
$pk->data = ($data << 8) | $id;
|
||||
|
||||
$this->server->broadcastPacket($targets === null ? $this->getChunkPlayers($x >> 4, $z >> 4) : $targets, $pk);
|
||||
$this->server->broadcastPacket($targets ?? $this->getChunkPlayers($x >> 4, $z >> 4), $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1533,7 +1533,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
* @param int $delay
|
||||
*/
|
||||
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){
|
||||
$motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
|
||||
$motion = $motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1);
|
||||
$itemTag = $item->nbtSerialize();
|
||||
$itemTag->setName("Item");
|
||||
|
||||
@ -1582,7 +1582,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
if($player !== null){
|
||||
$ev = new BlockBreakEvent($player, $target, $item, ($player->isCreative() or $player->allowInstaBreak()));
|
||||
$ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() or $player->allowInstaBreak());
|
||||
|
||||
if(($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) or $player->isSpectator()){
|
||||
$ev->setCancelled();
|
||||
@ -1633,7 +1633,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$breakTime -= 1; //1 tick compensation
|
||||
|
||||
if(!$ev->getInstaBreak() and ((ceil($player->lastBreak * 20)) + $breakTime) > ceil(microtime(true) * 20)){
|
||||
if(!$ev->getInstaBreak() and (ceil($player->lastBreak * 20) + $breakTime) > ceil(microtime(true) * 20)){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2590,7 +2590,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{
|
||||
if(($safe === true and $this->isChunkInUse($x, $z))){
|
||||
if($safe === true and $this->isChunkInUse($x, $z)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,9 @@ class Chunk{
|
||||
* @param CompoundTag[] $tiles
|
||||
* @param string $biomeIds
|
||||
* @param int[] $heightMap
|
||||
* @param int[] $extraData
|
||||
*/
|
||||
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = []){
|
||||
public function __construct(int $chunkX, int $chunkZ, array $subChunks = [], array $entities = [], array $tiles = [], string $biomeIds = "", array $heightMap = [], array $extraData = []){
|
||||
$this->x = $chunkX;
|
||||
$this->z = $chunkZ;
|
||||
|
||||
@ -127,10 +128,12 @@ class Chunk{
|
||||
if(strlen($biomeIds) === 256){
|
||||
$this->biomeIds = $biomeIds;
|
||||
}else{
|
||||
assert(strlen($biomeIds) === 0, "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
|
||||
assert($biomeIds === "", "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
|
||||
$this->biomeIds = str_repeat("\x00", 256);
|
||||
}
|
||||
|
||||
$this->extraData = $extraData;
|
||||
|
||||
$this->NBTtiles = $tiles;
|
||||
$this->NBTentities = $entities;
|
||||
}
|
||||
|
@ -173,19 +173,19 @@ class SubChunk implements SubChunkInterface{
|
||||
}
|
||||
|
||||
public function getBlockIdColumn(int $x, int $z) : string{
|
||||
return substr($this->ids, (($x << 8) | ($z << 4)), 16);
|
||||
return substr($this->ids, ($x << 8) | ($z << 4), 16);
|
||||
}
|
||||
|
||||
public function getBlockDataColumn(int $x, int $z) : string{
|
||||
return substr($this->data, (($x << 7) | ($z << 3)), 8);
|
||||
return substr($this->data, ($x << 7) | ($z << 3), 8);
|
||||
}
|
||||
|
||||
public function getBlockLightColumn(int $x, int $z) : string{
|
||||
return substr($this->blockLight, (($x << 7) | ($z << 3)), 8);
|
||||
return substr($this->blockLight, ($x << 7) | ($z << 3), 8);
|
||||
}
|
||||
|
||||
public function getBlockSkyLightColumn(int $x, int $z) : string{
|
||||
return substr($this->skyLight, (($x << 7) | ($z << 3)), 8);
|
||||
return substr($this->skyLight, ($x << 7) | ($z << 3), 8);
|
||||
}
|
||||
|
||||
public function getBlockIdArray() : string{
|
||||
|
@ -436,7 +436,8 @@ class LevelDB extends BaseLevelProvider{
|
||||
$entities,
|
||||
$tiles,
|
||||
$biomeIds,
|
||||
$heightMap
|
||||
$heightMap,
|
||||
$extraData
|
||||
);
|
||||
|
||||
//TODO: tile ticks, biome states (?)
|
||||
|
@ -134,9 +134,9 @@ class McRegion extends BaseLevelProvider{
|
||||
|
||||
$subChunks = [];
|
||||
$fullIds = isset($chunk->Blocks) ? $chunk->Blocks->getValue() : str_repeat("\x00", 32768);
|
||||
$fullData = isset($chunk->Data) ? $chunk->Data->getValue() : (str_repeat("\x00", 16384));
|
||||
$fullData = isset($chunk->Data) ? $chunk->Data->getValue() : str_repeat("\x00", 16384);
|
||||
$fullSkyLight = isset($chunk->SkyLight) ? $chunk->SkyLight->getValue() : str_repeat("\xff", 16384);
|
||||
$fullBlockLight = isset($chunk->BlockLight) ? $chunk->BlockLight->getValue() : (str_repeat("\x00", 16384));
|
||||
$fullBlockLight = isset($chunk->BlockLight) ? $chunk->BlockLight->getValue() : str_repeat("\x00", 16384);
|
||||
|
||||
for($y = 0; $y < 8; ++$y){
|
||||
$offset = ($y << 4);
|
||||
@ -262,7 +262,7 @@ class McRegion extends BaseLevelProvider{
|
||||
new LongTag("SizeOnDisk", 0),
|
||||
new LongTag("Time", 0),
|
||||
new StringTag("generatorName", Generator::getGeneratorName($generator)),
|
||||
new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
|
||||
new StringTag("generatorOptions", $options["preset"] ?? ""),
|
||||
new StringTag("LevelName", $name),
|
||||
new CompoundTag("GameRules", [])
|
||||
]);
|
||||
|
@ -292,7 +292,7 @@ class RegionLoader{
|
||||
$index = $data[$i + 1];
|
||||
$offset = $index >> 8;
|
||||
if($offset !== 0){
|
||||
fseek($this->filePointer, ($offset << 12));
|
||||
fseek($this->filePointer, $offset << 12);
|
||||
if(fgetc($this->filePointer) === false){ //Try and read from the location
|
||||
throw new CorruptedRegionException("Region file location offset points to invalid location");
|
||||
}elseif(isset($usedOffsets[$offset])){
|
||||
|
@ -90,7 +90,7 @@ class Flat extends Generator{
|
||||
$y = 0;
|
||||
foreach($matches[3] as $i => $b){
|
||||
$b = Item::fromString($b . $matches[4][$i]);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : (int) ($matches[2][$i]);
|
||||
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
|
||||
$result[$cY] = [$b->getId(), $b->getDamage()];
|
||||
}
|
||||
|
@ -55,17 +55,17 @@ class Matrix implements \ArrayAccess{
|
||||
for($r = 0; $r < $this->rows; ++$r){
|
||||
$this->matrix[$r] = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getRows(){
|
||||
return ($this->rows);
|
||||
return $this->rows;
|
||||
}
|
||||
|
||||
public function getColumns(){
|
||||
return ($this->columns);
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
public function setElement($row, $column, $value){
|
||||
|
@ -100,7 +100,7 @@ class Vector2{
|
||||
if($x instanceof Vector2){
|
||||
return $this->distanceSquared($x->x, $x->y);
|
||||
}else{
|
||||
return pow($this->x - $x, 2) + pow($this->y - $y, 2);
|
||||
return (($this->x - $x) ** 2) + (($this->y - $y) ** 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ class Vector3{
|
||||
}
|
||||
|
||||
public function distanceSquared(Vector3 $pos){
|
||||
return pow($this->x - $pos->x, 2) + pow($this->y - $pos->y, 2) + pow($this->z - $pos->z, 2);
|
||||
return (($this->x - $pos->x) ** 2) + (($this->y - $pos->y) ** 2) + (($this->z - $pos->z) ** 2);
|
||||
}
|
||||
|
||||
public function maxPlainDistance($x = 0, $z = 0){
|
||||
|
@ -404,7 +404,7 @@ class NBT{
|
||||
|
||||
public function setArray(array $data, callable $guesser = null){
|
||||
$this->data = new CompoundTag("", []);
|
||||
self::fromArray($this->data, $data, $guesser === null ? [self::class, "fromArrayGuesser"] : $guesser);
|
||||
self::fromArray($this->data, $data, $guesser ?? [self::class, "fromArrayGuesser"]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,6 +30,6 @@ class CachedEncapsulatedPacket extends EncapsulatedPacket{
|
||||
private $internalData = null;
|
||||
|
||||
public function toBinary($internal = false){
|
||||
return $this->internalData === null ? ($this->internalData = parent::toBinary($internal)) : $this->internalData;
|
||||
return $this->internalData ?? ($this->internalData = parent::toBinary($internal));
|
||||
}
|
||||
}
|
@ -85,7 +85,7 @@ class BatchPacket extends DataPacket{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(strlen($str) === 0){
|
||||
if($str === ""){
|
||||
throw new \InvalidStateException("Decoded BatchPacket payload is empty");
|
||||
}
|
||||
|
||||
|
@ -94,8 +94,7 @@ class LoginPacket extends DataPacket{
|
||||
}
|
||||
|
||||
public function decodeToken($token){
|
||||
$tokens = explode(".", $token);
|
||||
list($headB64, $payloadB64, $sigB64) = $tokens;
|
||||
list($headB64, $payloadB64, $sigB64) = explode(".", $token);
|
||||
|
||||
return json_decode(base64_decode($payloadB64), true);
|
||||
}
|
||||
|
@ -37,8 +37,8 @@ class UpdateBlockPacket extends DataPacket{
|
||||
const FLAG_NOGRAPHIC = 0b0100;
|
||||
const FLAG_PRIORITY = 0b1000;
|
||||
|
||||
const FLAG_ALL = (self::FLAG_NEIGHBORS | self::FLAG_NETWORK);
|
||||
const FLAG_ALL_PRIORITY = (self::FLAG_ALL | self::FLAG_PRIORITY);
|
||||
const FLAG_ALL = self::FLAG_NEIGHBORS | self::FLAG_NETWORK;
|
||||
const FLAG_ALL_PRIORITY = self::FLAG_ALL | self::FLAG_PRIORITY;
|
||||
|
||||
public $x;
|
||||
public $z;
|
||||
|
@ -133,7 +133,7 @@ class PermissibleBase implements Permissible{
|
||||
throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled");
|
||||
}
|
||||
|
||||
$result = new PermissionAttachment($plugin, $this->parent !== null ? $this->parent : $this);
|
||||
$result = new PermissionAttachment($plugin, $this->parent ?? $this);
|
||||
$this->attachments[spl_object_hash($result)] = $result;
|
||||
if($name !== null and $value !== null){
|
||||
$result->setPermission($name, $value);
|
||||
@ -165,12 +165,12 @@ class PermissibleBase implements Permissible{
|
||||
|
||||
$this->clearPermissions();
|
||||
$defaults = Server::getInstance()->getPluginManager()->getDefaultPermissions($this->isOp());
|
||||
Server::getInstance()->getPluginManager()->subscribeToDefaultPerms($this->isOp(), $this->parent !== null ? $this->parent : $this);
|
||||
Server::getInstance()->getPluginManager()->subscribeToDefaultPerms($this->isOp(), $this->parent ?? $this);
|
||||
|
||||
foreach($defaults as $perm){
|
||||
$name = $perm->getName();
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, null, true);
|
||||
Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($this->parent ?? $this, $name, null, true);
|
||||
Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent ?? $this);
|
||||
$this->calculateChildPermissions($perm->getChildren(), false, null);
|
||||
}
|
||||
|
||||
@ -202,8 +202,8 @@ class PermissibleBase implements Permissible{
|
||||
foreach($children as $name => $v){
|
||||
$perm = Server::getInstance()->getPluginManager()->getPermission($name);
|
||||
$value = ($v xor $invert);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($this->parent !== null ? $this->parent : $this, $name, $attachment, $value);
|
||||
Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent !== null ? $this->parent : $this);
|
||||
$this->permissions[$name] = new PermissionAttachmentInfo($this->parent ?? $this, $name, $attachment, $value);
|
||||
Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent ?? $this);
|
||||
|
||||
if($perm instanceof Permission){
|
||||
$this->calculateChildPermissions($perm->getChildren(), !$value, $attachment);
|
||||
|
@ -101,8 +101,8 @@ class Permission{
|
||||
*/
|
||||
public function __construct($name, $description = null, $defaultValue = null, array $children = []){
|
||||
$this->name = $name;
|
||||
$this->description = $description !== null ? $description : "";
|
||||
$this->defaultValue = $defaultValue !== null ? $defaultValue : self::$DEFAULT_PERMISSION;
|
||||
$this->description = $description ?? "";
|
||||
$this->defaultValue = $defaultValue ?? self::$DEFAULT_PERMISSION;
|
||||
$this->children = $children;
|
||||
|
||||
$this->recalculatePermissibles();
|
||||
|
@ -168,7 +168,7 @@ abstract class PluginBase implements Plugin{
|
||||
* @return bool
|
||||
*/
|
||||
protected function isPhar(){
|
||||
return substr($this->file, 0, 7) === "phar://";
|
||||
return strpos($this->file, "phar://") === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +145,7 @@ class PluginManager{
|
||||
* @return Plugin|null
|
||||
*/
|
||||
public function loadPlugin($path, $loaders = null){
|
||||
foreach(($loaders === null ? $this->fileAssociations : $loaders) as $loader){
|
||||
foreach($loaders ?? $this->fileAssociations as $loader){
|
||||
if(preg_match($loader->getPluginFilters(), basename($path)) > 0){
|
||||
$description = $loader->getPluginDescription($path);
|
||||
if($description instanceof PluginDescription){
|
||||
|
@ -63,7 +63,7 @@ class TaskHandler{
|
||||
$this->taskId = $taskId;
|
||||
$this->delay = $delay;
|
||||
$this->period = $period;
|
||||
$this->timingName = $timingName === null ? "Unknown" : $timingName;
|
||||
$this->timingName = $timingName ?? "Unknown";
|
||||
$this->timings = Timings::getPluginTaskTimings($this, $period);
|
||||
$this->task->setHandler($this);
|
||||
}
|
||||
|
@ -229,10 +229,10 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
|
||||
if($this->namedtag["BurnTime"] > 0){
|
||||
$this->namedtag->BurnTime = new ShortTag("BurnTime", ((int) $this->namedtag["BurnTime"]) - 1);
|
||||
$this->namedtag->BurnTicks = new ShortTag("BurnTicks", (int) ceil(($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200)));
|
||||
$this->namedtag->BurnTicks = new ShortTag("BurnTicks", (int) ceil($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200));
|
||||
|
||||
if($smelt instanceof FurnaceRecipe and $canSmelt){
|
||||
$this->namedtag->CookTime = new ShortTag("CookTime", (int) ($this->namedtag["CookTime"]) + 1);
|
||||
$this->namedtag->CookTime = new ShortTag("CookTime", ((int) $this->namedtag["CookTime"]) + 1);
|
||||
if($this->namedtag["CookTime"] >= 200){ //10 seconds
|
||||
$product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
|
||||
|
||||
|
@ -179,15 +179,15 @@ class BlockIterator implements \Iterator{
|
||||
}
|
||||
|
||||
private function getXFace(Vector3 $direction){
|
||||
return (($direction->x) > 0) ? Vector3::SIDE_EAST : Vector3::SIDE_WEST;
|
||||
return ($direction->x > 0) ? Vector3::SIDE_EAST : Vector3::SIDE_WEST;
|
||||
}
|
||||
|
||||
private function getYFace(Vector3 $direction){
|
||||
return (($direction->y) > 0) ? Vector3::SIDE_UP : Vector3::SIDE_DOWN;
|
||||
return ($direction->y > 0) ? Vector3::SIDE_UP : Vector3::SIDE_DOWN;
|
||||
}
|
||||
|
||||
private function getZFace(Vector3 $direction){
|
||||
return (($direction->z) > 0) ? Vector3::SIDE_SOUTH : Vector3::SIDE_NORTH;
|
||||
return ($direction->z > 0) ? Vector3::SIDE_SOUTH : Vector3::SIDE_NORTH;
|
||||
}
|
||||
|
||||
private function getXLength(Vector3 $direction){
|
||||
|
@ -92,7 +92,7 @@ class UUID{
|
||||
}
|
||||
|
||||
public function toString(){
|
||||
$hex = bin2hex(self::toBinary());
|
||||
$hex = bin2hex($this->toBinary());
|
||||
|
||||
//xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx 8-4-4-4-12
|
||||
if($this->version !== null){
|
||||
|
@ -461,7 +461,9 @@ class Utils{
|
||||
$headerGroup = [];
|
||||
foreach(explode("\r\n", $rawHeaderGroup) as $line){
|
||||
$nameValue = explode(":", $line, 2);
|
||||
if(isset($nameValue[1])) $headerGroup[trim(strtolower($nameValue[0]))] = trim($nameValue[1]);
|
||||
if(isset($nameValue[1])){
|
||||
$headerGroup[trim(strtolower($nameValue[0]))] = trim($nameValue[1]);
|
||||
}
|
||||
}
|
||||
$headers[] = $headerGroup;
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ class VersionString{
|
||||
$this->generation = isset($version[2]) ? (int) $version[2] : 0; //0-15
|
||||
$this->major = isset($version[3]) ? (int) $version[3] : 0; //0-15
|
||||
$this->minor = isset($version[4]) ? (int) $version[4] : 0; //0-31
|
||||
$this->development = $version[5] === "dev" ? true : false;
|
||||
$this->development = $version[5] === "dev";
|
||||
if($version[6] !== ""){
|
||||
$this->build = intval(substr($version[6], 1));
|
||||
$this->build = (int) (substr($version[6], 1));
|
||||
}else{
|
||||
$this->build = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user