mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
Added some asserts
This commit is contained in:
parent
eaef40618b
commit
cf3d8f449e
@ -2487,7 +2487,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
$pk = new EntityEventPacket();
|
$pk = new EntityEventPacket();
|
||||||
$pk->eid = $this->getId();
|
$pk->eid = $this->getId();
|
||||||
$pk->event = EntityEventPacket::USE_ITEM;
|
$pk->event = EntityEventPacket::USE_ITEM;
|
||||||
$pk;
|
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
Server::broadcastPacket($this->getViewers(), $pk);
|
Server::broadcastPacket($this->getViewers(), $pk);
|
||||||
|
|
||||||
|
@ -1518,6 +1518,9 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
define('pocketmine\DEBUG', (int) $this->getProperty("debug.level", 1));
|
define('pocketmine\DEBUG', (int) $this->getProperty("debug.level", 1));
|
||||||
|
|
||||||
|
ini_set('assert.exception', 1);
|
||||||
|
|
||||||
if($this->logger instanceof MainLogger){
|
if($this->logger instanceof MainLogger){
|
||||||
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
||||||
}
|
}
|
||||||
@ -1867,10 +1870,6 @@ class Server{
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function dispatchCommand(CommandSender $sender, $commandLine){
|
public function dispatchCommand(CommandSender $sender, $commandLine){
|
||||||
if(!($sender instanceof CommandSender)){
|
|
||||||
throw new ServerException("CommandSender is not valid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->commandMap->dispatch($sender, $commandLine)){
|
if($this->commandMap->dispatch($sender, $commandLine)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -206,9 +206,8 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
|
|
||||||
public function __construct(FullChunk $chunk, CompoundTag $nbt){
|
public function __construct(FullChunk $chunk, CompoundTag $nbt){
|
||||||
if($chunk === null or $chunk->getProvider() === null){
|
|
||||||
throw new ChunkException("Invalid garbage Chunk given to Entity");
|
assert($chunk !== null and $chunk->getProvider() !== null);
|
||||||
}
|
|
||||||
|
|
||||||
$this->timings = Timings::getEntityTimings($this);
|
$this->timings = Timings::getEntityTimings($this);
|
||||||
|
|
||||||
@ -240,6 +239,8 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
);
|
);
|
||||||
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
|
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
|
||||||
|
|
||||||
|
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
|
||||||
|
|
||||||
if(!isset($this->namedtag->FallDistance)){
|
if(!isset($this->namedtag->FallDistance)){
|
||||||
$this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
|
$this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
|
||||||
}
|
}
|
||||||
@ -501,6 +502,8 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
|
assert($this->namedtag instanceof CompoundTag);
|
||||||
|
|
||||||
if(isset($this->namedtag->ActiveEffects)){
|
if(isset($this->namedtag->ActiveEffects)){
|
||||||
foreach($this->namedtag->ActiveEffects->getValue() as $e){
|
foreach($this->namedtag->ActiveEffects->getValue() as $e){
|
||||||
$effect = Effect::getEffect($e["Id"]);
|
$effect = Effect::getEffect($e["Id"]);
|
||||||
|
@ -30,6 +30,7 @@ use pocketmine\item\Item as ItemItem;
|
|||||||
use pocketmine\nbt\NBT;
|
use pocketmine\nbt\NBT;
|
||||||
|
|
||||||
|
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\ShortTag;
|
use pocketmine\nbt\tag\ShortTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\Network;
|
use pocketmine\network\Network;
|
||||||
@ -70,6 +71,9 @@ class Item extends Entity{
|
|||||||
if(isset($this->namedtag->Thrower)){
|
if(isset($this->namedtag->Thrower)){
|
||||||
$this->thrower = $this->namedtag["Thrower"];
|
$this->thrower = $this->namedtag["Thrower"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert($this->namedtag->Item instanceof CompoundTag);
|
||||||
|
|
||||||
if(!isset($this->namedtag->Item)){
|
if(!isset($this->namedtag->Item)){
|
||||||
$this->close();
|
$this->close();
|
||||||
return;
|
return;
|
||||||
|
@ -78,9 +78,7 @@ class Position extends Vector3{
|
|||||||
* @throws LevelException
|
* @throws LevelException
|
||||||
*/
|
*/
|
||||||
public function getSide($side, $step = 1){
|
public function getSide($side, $step = 1){
|
||||||
if(!$this->isValid()){
|
assert($this->isValid());
|
||||||
throw new LevelException("Undefined Level reference");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
||||||
}
|
}
|
||||||
|
@ -118,15 +118,10 @@ abstract class Generator{
|
|||||||
* @return \SplFixedArray
|
* @return \SplFixedArray
|
||||||
*/
|
*/
|
||||||
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){
|
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){
|
||||||
if($samplingRate === 0){
|
assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0"));
|
||||||
throw new \InvalidArgumentException("samplingRate cannot be 0");
|
|
||||||
}
|
assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0"));
|
||||||
if ($xSize % $samplingRate !== 0) {
|
assert($zSize % $samplingRate === 0, new \InvalidArgumentCountException("zSize % samplingRate must return 0"));
|
||||||
throw new \InvalidArgumentCountException("xSize % samplingRate must return 0");
|
|
||||||
}
|
|
||||||
if ($zSize % $samplingRate !== 0) {
|
|
||||||
throw new \InvalidArgumentCountException("zSize % samplingRate must return 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
$noiseArray = new \SplFixedArray($xSize + 1);
|
$noiseArray = new \SplFixedArray($xSize + 1);
|
||||||
|
|
||||||
@ -173,24 +168,14 @@ abstract class Generator{
|
|||||||
* @return \SplFixedArray
|
* @return \SplFixedArray
|
||||||
*/
|
*/
|
||||||
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){
|
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){
|
||||||
if($xSamplingRate === 0){
|
|
||||||
throw new \InvalidArgumentException("xSamplingRate cannot be 0");
|
assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0"));
|
||||||
}
|
assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0"));
|
||||||
if($zSamplingRate === 0){
|
assert($ySamplingRate !== 0, new \InvalidArgumentException("ySamplingRate cannot be 0"));
|
||||||
throw new \InvalidArgumentException("zSamplingRate cannot be 0");
|
|
||||||
}
|
assert($xSize % $xSamplingRate === 0, new \InvalidArgumentCountException("xSize % xSamplingRate must return 0"));
|
||||||
if($ySamplingRate === 0){
|
assert($zSize % $zSamplingRate === 0, new \InvalidArgumentCountException("zSize % zSamplingRate must return 0"));
|
||||||
throw new \InvalidArgumentException("ySamplingRate cannot be 0");
|
assert($ySize % $ySamplingRate === 0, new \InvalidArgumentCountException("ySize % ySamplingRate must return 0"));
|
||||||
}
|
|
||||||
if ($xSize % $xSamplingRate !== 0) {
|
|
||||||
throw new \InvalidArgumentCountException("xSize % xSamplingRate must return 0");
|
|
||||||
}
|
|
||||||
if ($zSize % $zSamplingRate !== 0) {
|
|
||||||
throw new \InvalidArgumentCountException("zSize % zSamplingRate must return 0");
|
|
||||||
}
|
|
||||||
if ($ySize % $ySamplingRate !== 0) {
|
|
||||||
throw new \InvalidArgumentCountException("ySize % ySamplingRate must return 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
$noiseArray = array_fill(0, $xSize + 1, array_fill(0, $zSize + 1, []));
|
$noiseArray = array_fill(0, $xSize + 1, array_fill(0, $zSize + 1, []));
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(false, "Offset $offset not found");
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,7 @@ network:
|
|||||||
upnp-forwarding: false
|
upnp-forwarding: false
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
|
#To enable assertion execution, set zend.assertions in your php.ini to 1
|
||||||
#If > 1, it will show debug messages in the console
|
#If > 1, it will show debug messages in the console
|
||||||
level: 1
|
level: 1
|
||||||
#Enables /status, /gc
|
#Enables /status, /gc
|
||||||
|
@ -111,9 +111,7 @@ abstract class Tile extends Position{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(FullChunk $chunk, CompoundTag $nbt){
|
public function __construct(FullChunk $chunk, CompoundTag $nbt){
|
||||||
if($chunk === null or $chunk->getProvider() === null){
|
assert($chunk !== null and $chunk->getProvider() !== null);
|
||||||
throw new ChunkException("Invalid garbage Chunk given to Tile");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->timings = Timings::getTileEntityTimings($this);
|
$this->timings = Timings::getTileEntityTimings($this);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user