diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index f51e4b0e2..b9ffc969d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2355,7 +2355,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ */ public function save(){ if($this->closed){ - throw new \Exception("Tried to save closed player"); + throw new \InvalidStateException("Tried to save closed player"); } parent::saveNBT(); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 579cc5706..fe40c0345 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -99,7 +99,9 @@ use pocketmine\updater\AutoUpdater; use pocketmine\utils\Binary; use pocketmine\utils\Cache; use pocketmine\utils\Config; +use pocketmine\utils\LevelException; use pocketmine\utils\MainLogger; +use pocketmine\utils\ServerException; use pocketmine\utils\TextFormat; use pocketmine\utils\TextWrapper; use pocketmine\utils\Utils; @@ -948,11 +950,11 @@ class Server{ * * @return bool * - * @throws \Exception + * @throws LevelException */ public function loadLevel($name){ if(trim($name) === ""){ - throw new \Exception("Invalid empty level name"); + throw new LevelException("Invalid empty level name"); } if($this->isLevelLoaded($name)){ return true; @@ -1780,7 +1782,7 @@ class Server{ */ public function dispatchCommand(CommandSender $sender, $commandLine){ if(!($sender instanceof CommandSender)){ - throw new \Exception("CommandSender is not valid"); + throw new ServerException("CommandSender is not valid"); } if($this->commandMap->dispatch($sender, $commandLine)){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index c874a8b3d..aa6e575b9 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -59,6 +59,7 @@ use pocketmine\network\protocol\SetTimePacket; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\ChunkException; abstract class Entity extends Location implements Metadatable{ @@ -158,7 +159,7 @@ abstract class Entity extends Location implements Metadatable{ public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ - throw new \Exception("Invalid garbage Chunk given to Entity"); + throw new ChunkException("Invalid garbage Chunk given to Entity"); } $this->timings = Timings::getEntityTimings($this); diff --git a/src/pocketmine/event/HandlerList.php b/src/pocketmine/event/HandlerList.php index 67fb3efac..cc4d680fe 100644 --- a/src/pocketmine/event/HandlerList.php +++ b/src/pocketmine/event/HandlerList.php @@ -90,7 +90,7 @@ class HandlerList{ return; } if(isset($this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)])){ - throw new \Exception("This listener is already registered to priority " . $listener->getPriority()); + throw new \InvalidStateException("This listener is already registered to priority " . $listener->getPriority()); } $this->handlers = null; $this->handlerSlots[$listener->getPriority()][spl_object_hash($listener)] = $listener; diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index eb397b84c..7467a569c 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -76,7 +76,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ $this->originals = $this->modifiers; if(!isset($this->modifiers[self::MODIFIER_BASE])){ - throw new \Exception("BASE Damage modifier missing"); + throw new \InvalidArgumentException("BASE Damage modifier missing"); } } diff --git a/src/pocketmine/inventory/CraftingInventory.php b/src/pocketmine/inventory/CraftingInventory.php index 2a6d650a6..503287a3a 100644 --- a/src/pocketmine/inventory/CraftingInventory.php +++ b/src/pocketmine/inventory/CraftingInventory.php @@ -41,7 +41,7 @@ class CraftingInventory extends BaseInventory{ */ public function __construct(InventoryHolder $holder, Inventory $resultInventory, InventoryType $inventoryType){ if($inventoryType->getDefaultTitle() !== "Crafting"){ - throw new \Exception("Invalid Inventory type, expected CRAFTING or WORKBENCH"); + throw new \InvalidStateException("Invalid Inventory type, expected CRAFTING or WORKBENCH"); } $this->resultInventory = $resultInventory; parent::__construct($holder, $inventoryType); diff --git a/src/pocketmine/inventory/ShapedRecipe.php b/src/pocketmine/inventory/ShapedRecipe.php index bed1e0d25..6371a68d8 100644 --- a/src/pocketmine/inventory/ShapedRecipe.php +++ b/src/pocketmine/inventory/ShapedRecipe.php @@ -42,14 +42,14 @@ class ShapedRecipe implements Recipe{ */ public function __construct(Item $result, array $shape = []){ if(count($shape) === 0){ - throw new \Exception("Must provide a shape"); + throw new \InvalidArgumentException("Must provide a shape"); } if(count($shape) > 3){ - throw new \Exception("Crafting recipes should be 1, 2, 3 rows, not " . count($shape)); + throw new \InvalidStateException("Crafting recipes should be 1, 2, 3 rows, not " . count($shape)); } foreach($shape as $row){ if(strlen($row) === 0 or strlen($row) > 3){ - throw new \Exception("Crafting rows should be 1, 2, 3 characters, not " . count($row)); + throw new \InvalidStateException("Crafting rows should be 1, 2, 3 characters, not " . count($row)); } $this->rows[] = $row; $len = strlen($row); diff --git a/src/pocketmine/inventory/ShapelessRecipe.php b/src/pocketmine/inventory/ShapelessRecipe.php index 68d4d02c5..be87c8006 100644 --- a/src/pocketmine/inventory/ShapelessRecipe.php +++ b/src/pocketmine/inventory/ShapelessRecipe.php @@ -44,11 +44,11 @@ class ShapelessRecipe implements Recipe{ * * @returns ShapelessRecipe * - * @throws \Exception + * @throws \InvalidArgumentException */ public function addIngredient(Item $item){ if(count($this->ingredients) >= 9){ - throw new \Exception("Shapeless recipes cannot have more than 9 ingredients"); + throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients"); } $it = clone $item; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index c3ae3eb04..b8aac2888 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -92,6 +92,7 @@ use pocketmine\tile\Chest; use pocketmine\tile\Sign; use pocketmine\tile\Tile; use pocketmine\utils\Cache; +use pocketmine\utils\LevelException; use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\TextFormat; @@ -250,7 +251,7 @@ class Level implements ChunkManager, Metadatable{ if(is_subclass_of($provider, LevelProvider::class, true)){ $this->provider = new $provider($this, $path); }else{ - throw new \Exception("Provider is not a subclass of LevelProvider"); + throw new LevelException("Provider is not a subclass of LevelProvider"); } $this->server->getLogger()->info("Preparing level \"" . $this->provider->getName() . "\""); $this->generator = Generator::getGenerator($this->provider->getGenerator()); @@ -1736,11 +1737,11 @@ class Level implements ChunkManager, Metadatable{ * * @param Entity $entity * - * @throws \RuntimeException + * @throws LevelException */ public function removeEntity(Entity $entity){ if($entity->getLevel() !== $this){ - throw new \RuntimeException("Invalid Entity level"); + throw new LevelException("Invalid Entity level"); } if($entity instanceof Player){ @@ -1757,11 +1758,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Entity $entity * - * @throws \RuntimeException + * @throws LevelException */ public function addEntity(Entity $entity){ if($entity->getLevel() !== $this){ - throw new \RuntimeException("Invalid Entity level"); + throw new LevelException("Invalid Entity level"); } if($entity instanceof Player){ $this->players[$entity->getID()] = $entity; @@ -1772,11 +1773,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Tile $tile * - * @throws \RuntimeException + * @throws LevelException */ public function addTile(Tile $tile){ if($tile->getLevel() !== $this){ - throw new \RuntimeException("Invalid Tile level"); + throw new LevelException("Invalid Tile level"); } $this->tiles[$tile->getID()] = $tile; } @@ -1784,11 +1785,11 @@ class Level implements ChunkManager, Metadatable{ /** * @param Tile $tile * - * @throws \RuntimeException + * @throws LevelException */ public function removeTile(Tile $tile){ if($tile->getLevel() !== $this){ - throw new \RuntimeException("Invalid Tile level"); + throw new LevelException("Invalid Tile level"); } unset($this->tiles[$tile->getID()]); diff --git a/src/pocketmine/level/Position.php b/src/pocketmine/level/Position.php index 8b04aa4dc..a5c5d0249 100644 --- a/src/pocketmine/level/Position.php +++ b/src/pocketmine/level/Position.php @@ -22,6 +22,7 @@ namespace pocketmine\level; use pocketmine\math\Vector3; +use pocketmine\utils\LevelException; class Position extends Vector3{ @@ -139,11 +140,11 @@ class Position extends Vector3{ * * @return Position * - * @throws \RuntimeException + * @throws LevelException */ public function getSide($side, $step = 1){ if(!$this->isValid()){ - throw new \RuntimeException("Undefined Level reference"); + throw new LevelException("Undefined Level reference"); } return Position::fromObject(parent::getSide($side, $step), $this->level); diff --git a/src/pocketmine/level/format/LevelProviderManager.php b/src/pocketmine/level/format/LevelProviderManager.php index ec0ed87aa..bf89ca439 100644 --- a/src/pocketmine/level/format/LevelProviderManager.php +++ b/src/pocketmine/level/format/LevelProviderManager.php @@ -22,6 +22,7 @@ namespace pocketmine\level\format; use pocketmine\Server; +use pocketmine\utils\LevelException; abstract class LevelProviderManager{ protected static $providers = []; @@ -30,11 +31,11 @@ abstract class LevelProviderManager{ * @param Server $server * @param string $class * - * @throws \Exception + * @throws LevelException */ public static function addProvider(Server $server, $class){ if(!is_subclass_of($class, LevelProvider::class)){ - throw new \Exception("Class is not a subclass of LevelProvider"); + throw new LevelException("Class is not a subclass of LevelProvider"); } self::$providers[strtolower($class::getProviderName())] = $class; } diff --git a/src/pocketmine/level/format/anvil/Anvil.php b/src/pocketmine/level/format/anvil/Anvil.php index 6cf3d435d..ffcb37f00 100644 --- a/src/pocketmine/level/format/anvil/Anvil.php +++ b/src/pocketmine/level/format/anvil/Anvil.php @@ -27,6 +27,7 @@ use pocketmine\level\Level; use pocketmine\nbt\tag\Byte; use pocketmine\nbt\tag\ByteArray; use pocketmine\nbt\tag\Compound; +use pocketmine\utils\ChunkException; class Anvil extends McRegion{ @@ -93,7 +94,7 @@ class Anvil extends McRegion{ public function setChunk($chunkX, $chunkZ, FullChunk $chunk){ if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk class"); + throw new ChunkException("Invalid Chunk class"); } $chunk->setProvider($this); diff --git a/src/pocketmine/level/format/anvil/ChunkRequestTask.php b/src/pocketmine/level/format/anvil/ChunkRequestTask.php index 9fa648009..964e36f18 100644 --- a/src/pocketmine/level/format/anvil/ChunkRequestTask.php +++ b/src/pocketmine/level/format/anvil/ChunkRequestTask.php @@ -27,6 +27,7 @@ use pocketmine\scheduler\AsyncTask; use pocketmine\Server; use pocketmine\tile\Spawnable; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class ChunkRequestTask extends AsyncTask{ @@ -50,7 +51,7 @@ class ChunkRequestTask extends AsyncTask{ $this->chunkZ = $chunkZ; $chunk = $level->getChunk($chunkX, $chunkZ, false); if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk sent"); + throw new ChunkException("Invalid Chunk sent"); } $this->biomeIds = $chunk->getBiomeIdArray(); $this->biomeColors = $chunk->getBiomeColorArray(); diff --git a/src/pocketmine/level/format/generic/BaseChunk.php b/src/pocketmine/level/format/generic/BaseChunk.php index 71d0fb0f8..6f8ccadb8 100644 --- a/src/pocketmine/level/format/generic/BaseChunk.php +++ b/src/pocketmine/level/format/generic/BaseChunk.php @@ -28,6 +28,7 @@ use pocketmine\level\format\LevelProvider; use pocketmine\nbt\tag\Compound; use pocketmine\tile\Tile; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; abstract class BaseChunk extends BaseFullChunk implements Chunk{ @@ -62,7 +63,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ * @param Compound[] $entities * @param Compound[] $tiles * - * @throws \Exception + * @throws ChunkException */ protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){ $this->provider = $provider; @@ -72,12 +73,11 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ if($section instanceof ChunkSection){ $this->sections[$Y] = $section; }else{ - trigger_error("Received invalid ChunkSection instance", E_USER_ERROR); - throw new \Exception("Received invalid ChunkSection instance"); + throw new ChunkException("Received invalid ChunkSection instance"); } if($Y >= self::SECTION_COUNT){ - throw new \Exception("Invalid amount of chunks"); + throw new ChunkException("Invalid amount of chunks"); } } @@ -105,7 +105,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->hasChanged = true; return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f); - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); return $this->sections[$y >> 4]->setBlock($x, $y & 0x0f, $z, $blockId & 0xff, $meta & 0x0f); @@ -120,7 +120,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->setBlockId($x, $y & 0x0f, $z, $id); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockId($x, $y, $z, $id); @@ -135,7 +135,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->setBlockData($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockData($x, $y, $z, $data); @@ -150,7 +150,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockSkyLight($x, $y, $z, $data); @@ -165,7 +165,7 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{ try{ $this->sections[$y >> 4]->getBlockSkyLight($x, $y & 0x0f, $z, $data); $this->hasChanged = true; - }catch(\Exception $e){ + }catch(ChunkException $e){ $level = $this->getProvider(); $this->setInternalSection($Y = $y >> 4, $level::createChunkSection($Y)); $this->setBlockLight($x, $y, $z, $data); diff --git a/src/pocketmine/level/format/generic/BaseFullChunk.php b/src/pocketmine/level/format/generic/BaseFullChunk.php index b315736d6..f6396a3bd 100644 --- a/src/pocketmine/level/format/generic/BaseFullChunk.php +++ b/src/pocketmine/level/format/generic/BaseFullChunk.php @@ -78,8 +78,6 @@ abstract class BaseFullChunk implements FullChunk{ * @param int[] $biomeColors * @param Compound[] $entities * @param Compound[] $tiles - * - * @throws \Exception */ protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){ $this->provider = $provider; diff --git a/src/pocketmine/level/format/generic/BaseLevelProvider.php b/src/pocketmine/level/format/generic/BaseLevelProvider.php index b393c26c6..003a5f2b5 100644 --- a/src/pocketmine/level/format/generic/BaseLevelProvider.php +++ b/src/pocketmine/level/format/generic/BaseLevelProvider.php @@ -27,6 +27,7 @@ use pocketmine\math\Vector3; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; +use pocketmine\utils\LevelException; abstract class BaseLevelProvider implements LevelProvider{ /** @var Level */ @@ -46,7 +47,7 @@ abstract class BaseLevelProvider implements LevelProvider{ if($levelData->Data instanceof Compound){ $this->levelData = $levelData->Data; }else{ - throw new \Exception("Invalid level.dat"); + throw new LevelException("Invalid level.dat"); } } diff --git a/src/pocketmine/level/format/generic/EmptyChunkSection.php b/src/pocketmine/level/format/generic/EmptyChunkSection.php index ec8ab9790..11fc28f0f 100644 --- a/src/pocketmine/level/format/generic/EmptyChunkSection.php +++ b/src/pocketmine/level/format/generic/EmptyChunkSection.php @@ -22,6 +22,7 @@ namespace pocketmine\level\format\generic; use pocketmine\level\format\ChunkSection; +use pocketmine\utils\ChunkException; /** * Stub used to detect empty chunks @@ -64,7 +65,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlock($x, $y, $z, $id = null, $meta = null){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } public function getIdArray(){ @@ -84,7 +85,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockId($x, $y, $z, $id){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockData($x, $y, $z){ @@ -92,7 +93,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockData($x, $y, $z, $data){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockLight($x, $y, $z){ @@ -100,7 +101,7 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockLight($x, $y, $z, $level){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } final public function getBlockSkyLight($x, $y, $z){ @@ -108,6 +109,6 @@ class EmptyChunkSection implements ChunkSection{ } final public function setBlockSkyLight($x, $y, $z, $level){ - throw new \Exception("Tried to modify an empty Chunk"); + throw new ChunkException("Tried to modify an empty Chunk"); } } \ No newline at end of file diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 4b6f5c09f..236000341 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -33,6 +33,7 @@ use pocketmine\nbt\tag\Long; use pocketmine\nbt\tag\String; use pocketmine\tile\Spawnable; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class McRegion extends BaseLevelProvider{ @@ -109,7 +110,7 @@ class McRegion extends BaseLevelProvider{ public function requestChunkTask($x, $z){ $chunk = $this->getChunk($x, $z, false); if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk sent"); + throw new ChunkException("Invalid Chunk sent"); } $tiles = ""; @@ -239,7 +240,7 @@ class McRegion extends BaseLevelProvider{ public function setChunk($chunkX, $chunkZ, FullChunk $chunk){ if(!($chunk instanceof Chunk)){ - throw new \Exception("Invalid Chunk class"); + throw new ChunkException("Invalid Chunk class"); } $chunk->setProvider($this); diff --git a/src/pocketmine/level/generator/GenerationChunkManager.php b/src/pocketmine/level/generator/GenerationChunkManager.php index 21db6b20c..2d50857e8 100644 --- a/src/pocketmine/level/generator/GenerationChunkManager.php +++ b/src/pocketmine/level/generator/GenerationChunkManager.php @@ -24,6 +24,7 @@ namespace pocketmine\level\generator; use pocketmine\level\ChunkManager; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; +use pocketmine\utils\ChunkException; use pocketmine\utils\Random; class GenerationChunkManager implements ChunkManager{ @@ -45,7 +46,7 @@ class GenerationChunkManager implements ChunkManager{ public function __construct(GenerationManager $manager, $levelID, $seed, $class, array $options){ if(!class_exists($class, true) or !is_subclass_of($class, Generator::class)){ - throw new \Exception("Class $class does not exists or is not a subclass of Generator"); + throw new \InvalidStateException("Class $class does not exists or is not a subclass of Generator"); } $this->levelID = $levelID; @@ -75,13 +76,13 @@ class GenerationChunkManager implements ChunkManager{ * * @return FullChunk * - * @throws \Exception + * @throws ChunkException */ public function getChunk($chunkX, $chunkZ){ $index = Level::chunkHash($chunkX, $chunkZ); $chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index]; if($chunk === null){ - throw new \Exception("null Chunk received"); + throw new ChunkException("null Chunk received"); } return $chunk; diff --git a/src/pocketmine/level/generator/GenerationInstanceManager.php b/src/pocketmine/level/generator/GenerationInstanceManager.php index 0761ff60e..bae2c511c 100644 --- a/src/pocketmine/level/generator/GenerationInstanceManager.php +++ b/src/pocketmine/level/generator/GenerationInstanceManager.php @@ -24,6 +24,7 @@ namespace pocketmine\level\generator; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\Server; +use pocketmine\utils\ChunkException; class GenerationInstanceManager extends GenerationRequestManager{ @@ -78,7 +79,7 @@ class GenerationInstanceManager extends GenerationRequestManager{ if($chunk instanceof FullChunk){ return $chunk; }else{ - throw new \Exception("Invalid Chunk given"); + throw new ChunkException("Invalid Chunk given"); } }else{ $this->generationManager->closeLevel($levelID); diff --git a/src/pocketmine/level/generator/GenerationRequestManager.php b/src/pocketmine/level/generator/GenerationRequestManager.php index b8f4b00bd..820622d8a 100644 --- a/src/pocketmine/level/generator/GenerationRequestManager.php +++ b/src/pocketmine/level/generator/GenerationRequestManager.php @@ -25,6 +25,7 @@ use pocketmine\level\format\FullChunk; use pocketmine\level\Level; use pocketmine\Server; use pocketmine\utils\Binary; +use pocketmine\utils\ChunkException; class GenerationRequestManager{ @@ -87,7 +88,7 @@ class GenerationRequestManager{ if($chunk instanceof FullChunk){ $this->sendChunk($levelID, $chunk); }else{ - throw new \Exception("Invalid Chunk given"); + throw new ChunkException("Invalid Chunk given"); } }else{ $buffer = chr(GenerationManager::PACKET_CLOSE_LEVEL) . Binary::writeInt($levelID); diff --git a/src/pocketmine/metadata/BlockMetadataStore.php b/src/pocketmine/metadata/BlockMetadataStore.php index f4d03c387..093824768 100644 --- a/src/pocketmine/metadata/BlockMetadataStore.php +++ b/src/pocketmine/metadata/BlockMetadataStore.php @@ -43,45 +43,45 @@ class BlockMetadataStore extends MetadataStore{ public function getMetadata($block, $metadataKey){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ return parent::getMetadata($block, $metadataKey); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function hasMetadata($block, $metadataKey){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ return parent::hasMetadata($block, $metadataKey); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function removeMetadata($block, $metadataKey, Plugin $owningPlugin){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ parent::hasMetadata($block, $metadataKey, $owningPlugin); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue){ if($block instanceof Block){ - throw new \Exception("Object must be a Block"); + throw new \InvalidArgumentException("Object must be a Block"); } if($block->getLevel() === $this->owningLevel){ parent::setMetadata($block, $metadataKey, $newMetadatavalue); }else{ - throw new \Exception("Block does not belong to world " . $this->owningLevel->getName()); + throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } } \ No newline at end of file diff --git a/src/pocketmine/metadata/MetadataStore.php b/src/pocketmine/metadata/MetadataStore.php index d980f276e..77e4ef03c 100644 --- a/src/pocketmine/metadata/MetadataStore.php +++ b/src/pocketmine/metadata/MetadataStore.php @@ -25,6 +25,7 @@ namespace pocketmine\metadata; use pocketmine\plugin\Plugin; +use pocketmine\utils\PluginException; abstract class MetadataStore{ /** @var \WeakMap[] */ @@ -42,7 +43,7 @@ abstract class MetadataStore{ public function setMetadata($subject, $metadataKey, MetadataValue $newMetadataValue){ $owningPlugin = $newMetadataValue->getOwningPlugin(); if($owningPlugin === null){ - throw new \Exception("Plugin cannot be null"); + throw new PluginException("Plugin cannot be null"); } $key = $this->disambiguate($subject, $metadataKey); diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index 9c7705a76..bb394bde3 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -24,6 +24,7 @@ namespace pocketmine\permission; use pocketmine\event\Timings; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\PluginException; class PermissibleBase implements Permissible{ /** @var ServerOperator */ @@ -72,7 +73,7 @@ class PermissibleBase implements Permissible{ */ public function setOp($value){ if($this->opable === null){ - throw new \Exception("Cannot change op value as no ServerOperator is set"); + throw new \LogicException("Cannot change op value as no ServerOperator is set"); }else{ $this->opable->setOp($value); } @@ -120,13 +121,13 @@ class PermissibleBase implements Permissible{ * * @return PermissionAttachment * - * @throws \Exception + * @throws PluginException */ public function addAttachment(Plugin $plugin, $name = null, $value = null){ if($plugin === null){ - throw new \Exception("Plugin cannot be null"); + throw new PluginException("Plugin cannot be null"); }elseif(!$plugin->isEnabled()){ - throw new \Exception("Plugin " . $plugin->getDescription()->getName() . " is disabled"); + throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $result = new PermissionAttachment($plugin, $this->parent); @@ -147,7 +148,7 @@ class PermissibleBase implements Permissible{ */ public function removeAttachment(PermissionAttachment $attachment){ if($attachment === null){ - throw new \Exception("Attachment cannot be null"); + throw new \InvalidStateException("Attachment cannot be null"); } if(isset($this->attachments[spl_object_hash($attachment)])){ diff --git a/src/pocketmine/permission/Permission.php b/src/pocketmine/permission/Permission.php index 23977abea..3220f9a74 100644 --- a/src/pocketmine/permission/Permission.php +++ b/src/pocketmine/permission/Permission.php @@ -225,7 +225,7 @@ class Permission{ if($value !== null){ $default = $value; }else{ - throw new \Exception("'default' key contained unknown value"); + throw new \InvalidStateException("'default' key contained unknown value"); } } @@ -240,7 +240,7 @@ class Permission{ $children[$k] = true; } }else{ - throw new \Exception("'children' key is of wrong type"); + throw new \InvalidStateException("'children' key is of wrong type"); } } diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index 75a8daba2..f87ebc000 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -22,6 +22,7 @@ namespace pocketmine\permission; use pocketmine\plugin\Plugin; +use pocketmine\utils\PluginException; class PermissionAttachment{ /** @var PermissionRemovedExecutor */ @@ -42,11 +43,11 @@ class PermissionAttachment{ * @param Plugin $plugin * @param Permissible $permissible * - * @throws \Exception + * @throws PluginException */ public function __construct(Plugin $plugin, Permissible $permissible){ if(!$plugin->isEnabled()){ - throw new \Exception("Plugin " . $plugin->getDescription()->getName() . " is disabled"); + throw new PluginException("Plugin " . $plugin->getDescription()->getName() . " is disabled"); } $this->permissible = $permissible; diff --git a/src/pocketmine/permission/PermissionAttachmentInfo.php b/src/pocketmine/permission/PermissionAttachmentInfo.php index ecb66c1c2..78f5f8650 100644 --- a/src/pocketmine/permission/PermissionAttachmentInfo.php +++ b/src/pocketmine/permission/PermissionAttachmentInfo.php @@ -41,11 +41,11 @@ class PermissionAttachmentInfo{ * @param PermissionAttachment $attachment * @param bool $value * - * @throws \Exception + * @throws \InvalidStateException */ public function __construct(Permissible $permissible, $permission, $attachment, $value){ if($permission === null){ - throw new \Exception("Permission may not be null"); + throw new \InvalidStateException("Permission may not be null"); } $this->permissible = $permissible; diff --git a/src/pocketmine/plugin/PharPluginLoader.php b/src/pocketmine/plugin/PharPluginLoader.php index abfda8c91..4aa020be2 100644 --- a/src/pocketmine/plugin/PharPluginLoader.php +++ b/src/pocketmine/plugin/PharPluginLoader.php @@ -24,6 +24,7 @@ namespace pocketmine\plugin; use pocketmine\event\plugin\PluginDisableEvent; use pocketmine\event\plugin\PluginEnableEvent; use pocketmine\Server; +use pocketmine\utils\PluginException; /** * Handles different types of plugins @@ -54,7 +55,7 @@ class PharPluginLoader implements PluginLoader{ $this->server->getLogger()->info("Loading " . $description->getFullName()); $dataFolder = dirname($file) . DIRECTORY_SEPARATOR . $description->getName(); if(file_exists($dataFolder) and !is_dir($dataFolder)){ - throw new \Exception("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory"); + throw new \InvalidStateException("Projected dataFolder '" . $dataFolder . "' for " . $description->getName() . " exists and is not a directory"); } $file = "phar://$file"; $className = $description->getMain(); @@ -66,7 +67,7 @@ class PharPluginLoader implements PluginLoader{ return $plugin; }else{ - throw new \Exception("Couldn't load plugin " . $description->getName() . ": main class not found"); + throw new PluginException("Couldn't load plugin " . $description->getName() . ": main class not found"); } } diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 28f24948b..634e417fa 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -22,6 +22,7 @@ namespace pocketmine\plugin; use pocketmine\permission\Permission; +use pocketmine\utils\PluginException; class PluginDescription{ private $name; @@ -53,12 +54,12 @@ class PluginDescription{ /** * @param array $plugin * - * @throws \Exception + * @throws PluginException */ private function loadMap(array $plugin){ $this->name = preg_replace("[^A-Za-z0-9 _.-]", "", $plugin["name"]); if($this->name === ""){ - throw new \Exception("Invalid PluginDescription name"); + throw new PluginException("Invalid PluginDescription name"); } $this->name = str_replace(" ", "_", $this->name); $this->version = $plugin["version"]; diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index b3a82027c..9701713e8 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -34,6 +34,7 @@ use pocketmine\permission\Permissible; use pocketmine\permission\Permission; use pocketmine\Server; use pocketmine\utils\MainLogger; +use pocketmine\utils\PluginException; /** * Manages all the plugins, Permissions and Permissibles @@ -675,11 +676,11 @@ class PluginManager{ * @param Listener $listener * @param Plugin $plugin * - * @throws \Exception + * @throws PluginException */ public function registerEvents(Listener $listener, Plugin $plugin){ if(!$plugin->isEnabled()){ - throw new \Exception("Plugin attempted to register " . get_class($listener) . " while not enabled"); + throw new PluginException("Plugin attempted to register " . get_class($listener) . " while not enabled"); } $reflection = new \ReflectionClass(get_class($listener)); @@ -723,15 +724,15 @@ class PluginManager{ * @param Plugin $plugin * @param bool $ignoreCancelled * - * @throws \Exception + * @throws PluginException */ public function registerEvent($event, Listener $listener, $priority, EventExecutor $executor, Plugin $plugin, $ignoreCancelled = false){ if(!is_subclass_of($event, Event::class) or (new \ReflectionClass($event))->isAbstract()){ - throw new \Exception($event . " is not a valid Event"); + throw new PluginException($event . " is not a valid Event"); } if(!$plugin->isEnabled()){ - throw new \Exception("Plugin attempted to register " . $event . " while not enabled"); + throw new PluginException("Plugin attempted to register " . $event . " while not enabled"); } $timings = new TimingsHandler("Plugin: " . $plugin->getDescription()->getFullName() . " Event: " . get_class($listener) . "::" . ($executor instanceof MethodEventExecutor ? $executor->getMethod() : "???") . "(" . (new \ReflectionClass($event))->getShortName() . ")", self::$pluginParentTimer); diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index f64d39f83..835e647f8 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -26,6 +26,7 @@ namespace pocketmine\scheduler; use pocketmine\plugin\Plugin; use pocketmine\Server; +use pocketmine\utils\PluginException; use pocketmine\utils\ReversePriorityQueue; class ServerScheduler{ @@ -165,14 +166,14 @@ class ServerScheduler{ * * @return null|TaskHandler * - * @throws \Exception + * @throws PluginException */ private function addTask(Task $task, $delay, $period){ if($task instanceof PluginTask){ if(!($task->getOwner() instanceof Plugin)){ - throw new \Exception("Invalid owner of PluginTask " . get_class($task)); + throw new PluginException("Invalid owner of PluginTask " . get_class($task)); }elseif(!$task->getOwner()->isEnabled()){ - throw new \Exception("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled"); + throw new PluginException("Plugin '" . $task->getOwner()->getName() . "' attempted to register a task while disabled"); } } @@ -231,7 +232,11 @@ class ServerScheduler{ continue; }else{ $task->timings->startTiming(); - $task->run($this->currentTick); + try{ + $task->run($this->currentTick); + }catch (\Exception $e){ + Server::getInstance()->getLogger()->critical("Could not execute task ". $task->getTaskName() .": ".$e->getMessage()); + } $task->timings->stopTiming(); } if($task->isRepeating()){ diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index d22bebe38..7acf9307f 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -32,6 +32,7 @@ use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\nbt\tag\Compound; use pocketmine\nbt\tag\Int; +use pocketmine\utils\ChunkException; abstract class Tile extends Position{ const SIGN = "Sign"; @@ -95,7 +96,7 @@ abstract class Tile extends Position{ public function __construct(FullChunk $chunk, Compound $nbt){ if($chunk === null or $chunk->getProvider() === null){ - throw new \Exception("Invalid garbage Chunk given to Tile"); + throw new ChunkException("Invalid garbage Chunk given to Tile"); } $this->timings = Timings::getTileEntityTimings($this); diff --git a/src/pocketmine/utils/BlockIterator.php b/src/pocketmine/utils/BlockIterator.php index 31eee943b..c11a168dd 100644 --- a/src/pocketmine/utils/BlockIterator.php +++ b/src/pocketmine/utils/BlockIterator.php @@ -162,7 +162,7 @@ class BlockIterator implements \Iterator{ } if(!$startBlockFound){ - throw new \Exception("Start block missed in BlockIterator"); + throw new \RuntimeException("Start block missed in BlockIterator"); } $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection)); diff --git a/src/pocketmine/utils/ChunkException.php b/src/pocketmine/utils/ChunkException.php new file mode 100644 index 000000000..201033109 --- /dev/null +++ b/src/pocketmine/utils/ChunkException.php @@ -0,0 +1,26 @@ +