mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Replace disallowed operators in src/item/
This commit is contained in:
parent
373880e582
commit
22fb02c4e6
@ -96,7 +96,7 @@ class Armor extends Durable{
|
||||
|
||||
foreach($this->getEnchantments() as $enchantment){
|
||||
$type = $enchantment->getType();
|
||||
if($type instanceof ProtectionEnchantment and $type->isApplicable($event)){
|
||||
if($type instanceof ProtectionEnchantment && $type->isApplicable($event)){
|
||||
$epf += $type->getProtectionFactor($enchantment->getLevel());
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ class Armor extends Durable{
|
||||
|
||||
$chance = 1 / ($unbreakingLevel + 1);
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
if(mt_rand(1, 100) > 60 and lcg_value() > $chance){ //unbreaking only applies to armor 40% of the time at best
|
||||
if(mt_rand(1, 100) > 60 && lcg_value() > $chance){ //unbreaking only applies to armor 40% of the time at best
|
||||
$negated++;
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Bow extends Tool implements Releasable{
|
||||
default => null
|
||||
};
|
||||
|
||||
if($player->hasFiniteResources() and $inventory === null){
|
||||
if($player->hasFiniteResources() && $inventory === null){
|
||||
return ItemUseResult::FAIL();
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ class Bow extends Tool implements Releasable{
|
||||
}
|
||||
$ev = new EntityShootBowEvent($player, $this, $entity, $baseForce * 3);
|
||||
|
||||
if($baseForce < 0.1 or $diff < 5 or $player->isSpectator()){
|
||||
if($baseForce < 0.1 || $diff < 5 || $player->isSpectator()){
|
||||
$ev->cancel();
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class Bucket extends Item{
|
||||
|
||||
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{
|
||||
//TODO: move this to generic placement logic
|
||||
if($blockClicked instanceof Liquid and $blockClicked->isSource()){
|
||||
if($blockClicked instanceof Liquid && $blockClicked->isSource()){
|
||||
$stack = clone $this;
|
||||
$stack->pop();
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ChorusFruit extends Food{
|
||||
$y = mt_rand($minY, $maxY);
|
||||
$z = mt_rand($minZ, $maxZ);
|
||||
|
||||
while($y >= 0 and !$world->getBlockAt($x, $y, $z)->isSolid()){
|
||||
while($y >= 0 && !$world->getBlockAt($x, $y, $z)->isSolid()){
|
||||
$y--;
|
||||
}
|
||||
if($y < 0){
|
||||
@ -70,7 +70,7 @@ class ChorusFruit extends Food{
|
||||
|
||||
$blockUp = $world->getBlockAt($x, $y + 1, $z);
|
||||
$blockUp2 = $world->getBlockAt($x, $y + 2, $z);
|
||||
if($blockUp->isSolid() or $blockUp instanceof Liquid or $blockUp2->isSolid() or $blockUp2 instanceof Liquid){
|
||||
if($blockUp->isSolid() || $blockUp instanceof Liquid || $blockUp2->isSolid() || $blockUp2 instanceof Liquid){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ abstract class Durable extends Item{
|
||||
* @return bool if any damage was applied to the item
|
||||
*/
|
||||
public function applyDamage(int $amount) : bool{
|
||||
if($this->isUnbreakable() or $this->isBroken()){
|
||||
if($this->isUnbreakable() || $this->isBroken()){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ abstract class Durable extends Item{
|
||||
}
|
||||
|
||||
public function setDamage(int $damage) : Item{
|
||||
if($damage < 0 or $damage > $this->getMaxDurability()){
|
||||
if($damage < 0 || $damage > $this->getMaxDurability()){
|
||||
throw new \InvalidArgumentException("Damage must be in range 0 - " . $this->getMaxDurability());
|
||||
}
|
||||
$this->damage = $damage;
|
||||
|
@ -277,7 +277,7 @@ class Item implements \JsonSerializable{
|
||||
if($display !== null){
|
||||
$this->customName = $display->getString(self::TAG_DISPLAY_NAME, $this->customName);
|
||||
$lore = $display->getListTag(self::TAG_DISPLAY_LORE);
|
||||
if($lore !== null and $lore->getTagType() === NBT::TAG_String){
|
||||
if($lore !== null && $lore->getTagType() === NBT::TAG_String){
|
||||
/** @var StringTag $t */
|
||||
foreach($lore as $t){
|
||||
$this->lore[] = $t->getValue();
|
||||
@ -287,7 +287,7 @@ class Item implements \JsonSerializable{
|
||||
|
||||
$this->removeEnchantments();
|
||||
$enchantments = $tag->getListTag(self::TAG_ENCH);
|
||||
if($enchantments !== null and $enchantments->getTagType() === NBT::TAG_Compound){
|
||||
if($enchantments !== null && $enchantments->getTagType() === NBT::TAG_Compound){
|
||||
/** @var CompoundTag $enchantment */
|
||||
foreach($enchantments as $enchantment){
|
||||
$magicNumber = $enchantment->getShort("id", -1);
|
||||
@ -412,7 +412,7 @@ class Item implements \JsonSerializable{
|
||||
}
|
||||
|
||||
public function isNull() : bool{
|
||||
return $this->count <= 0 or $this->getId() === ItemIds::AIR;
|
||||
return $this->count <= 0 || $this->getId() === ItemIds::AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -568,9 +568,9 @@ class Item implements \JsonSerializable{
|
||||
* @param bool $checkCompound Whether to verify that the items' NBT match.
|
||||
*/
|
||||
final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{
|
||||
return $this->getId() === $item->getId() and
|
||||
(!$checkDamage or $this->getMeta() === $item->getMeta()) and
|
||||
(!$checkCompound or $this->getNamedTag()->equals($item->getNamedTag()));
|
||||
return $this->getId() === $item->getId() &&
|
||||
(!$checkDamage || $this->getMeta() === $item->getMeta()) &&
|
||||
(!$checkCompound || $this->getNamedTag()->equals($item->getNamedTag()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -584,7 +584,7 @@ class Item implements \JsonSerializable{
|
||||
* Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
|
||||
*/
|
||||
final public function equalsExact(Item $other) : bool{
|
||||
return $this->equals($other, true, true) and $this->count === $other->count;
|
||||
return $this->equals($other, true, true) && $this->count === $other->count;
|
||||
}
|
||||
|
||||
final public function __toString() : string{
|
||||
@ -676,7 +676,7 @@ class Item implements \JsonSerializable{
|
||||
* @throws SavedDataLoadingException
|
||||
*/
|
||||
public static function nbtDeserialize(CompoundTag $tag) : Item{
|
||||
if($tag->getTag("id") === null or $tag->getTag("Count") === null){
|
||||
if($tag->getTag("id") === null || $tag->getTag("Count") === null){
|
||||
return ItemFactory::getInstance()->get(0);
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ trait ItemEnchantmentHandlingTrait{
|
||||
|
||||
public function hasEnchantment(Enchantment $enchantment, int $level = -1) : bool{
|
||||
$id = spl_object_id($enchantment);
|
||||
return isset($this->enchantments[$id]) and ($level === -1 or $this->enchantments[$id]->getLevel() === $level);
|
||||
return isset($this->enchantments[$id]) && ($level === -1 || $this->enchantments[$id]->getLevel() === $level);
|
||||
}
|
||||
|
||||
public function getEnchantment(Enchantment $enchantment) : ?EnchantmentInstance{
|
||||
@ -54,7 +54,7 @@ trait ItemEnchantmentHandlingTrait{
|
||||
*/
|
||||
public function removeEnchantment(Enchantment $enchantment, int $level = -1) : self{
|
||||
$instance = $this->getEnchantment($enchantment);
|
||||
if($instance !== null and ($level === -1 or $instance->getLevel() === $level)){
|
||||
if($instance !== null && ($level === -1 || $instance->getLevel() === $level)){
|
||||
unset($this->enchantments[spl_object_id($enchantment)]);
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ class ItemFactory{
|
||||
$id = $item->getId();
|
||||
$variant = $item->getMeta();
|
||||
|
||||
if(!$override and $this->isRegistered($id, $variant)){
|
||||
if(!$override && $this->isRegistered($id, $variant)){
|
||||
throw new \RuntimeException("Trying to overwrite an already registered item");
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ class ItemFactory{
|
||||
if($meta !== -1){
|
||||
if(isset($this->list[$offset = self::getListOffset($id, $meta)])){
|
||||
$item = clone $this->list[$offset];
|
||||
}elseif(isset($this->list[$zero = self::getListOffset($id, 0)]) and $this->list[$zero] instanceof Durable){
|
||||
}elseif(isset($this->list[$zero = self::getListOffset($id, 0)]) && $this->list[$zero] instanceof Durable){
|
||||
if($meta <= $this->list[$zero]->getMaxDurability()){
|
||||
$item = clone $this->list[$zero];
|
||||
$item->setDamage($meta);
|
||||
@ -498,7 +498,7 @@ class ItemFactory{
|
||||
}
|
||||
|
||||
private static function getListOffset(int $id, int $variant) : int{
|
||||
if($id < -0x8000 or $id > 0x7fff){
|
||||
if($id < -0x8000 || $id > 0x7fff){
|
||||
throw new \InvalidArgumentException("ID must be in range " . -0x8000 . " - " . 0x7fff);
|
||||
}
|
||||
return (($id & 0xffff) << 16) | ($variant & 0xffff);
|
||||
|
@ -31,7 +31,7 @@ final class ItemIdentifier{
|
||||
private $meta;
|
||||
|
||||
public function __construct(int $id, int $meta){
|
||||
if($id < -0x8000 or $id > 0x7fff){ //signed short range
|
||||
if($id < -0x8000 || $id > 0x7fff){ //signed short range
|
||||
throw new \InvalidArgumentException("ID must be in range " . -0x8000 . " - " . 0x7fff);
|
||||
}
|
||||
$this->id = $id;
|
||||
|
@ -65,7 +65,7 @@ class WrittenBook extends WritableBookBase{
|
||||
* @return $this
|
||||
*/
|
||||
public function setGeneration(int $generation) : self{
|
||||
if($generation < 0 or $generation > 3){
|
||||
if($generation < 0 || $generation > 3){
|
||||
throw new \InvalidArgumentException("Generation \"$generation\" is out of range");
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,6 @@ class ProtectionEnchantment extends Enchantment{
|
||||
* Returns whether this enchantment type offers protection from the specified damage source's cause.
|
||||
*/
|
||||
public function isApplicable(EntityDamageEvent $event) : bool{
|
||||
return $this->applicableDamageTypes === null or isset($this->applicableDamageTypes[$event->getCause()]);
|
||||
return $this->applicableDamageTypes === null || isset($this->applicableDamageTypes[$event->getCause()]);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user