mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Added extra Exceptions
This commit is contained in:
parent
b6f7ee20fc
commit
8c4faa8622
@ -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();
|
||||
|
@ -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)){
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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()]);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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)])){
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"];
|
||||
|
@ -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);
|
||||
|
@ -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()){
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
26
src/pocketmine/utils/ChunkException.php
Normal file
26
src/pocketmine/utils/ChunkException.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\utils;
|
||||
|
||||
class ChunkException extends \RuntimeException{
|
||||
|
||||
}
|
26
src/pocketmine/utils/LevelException.php
Normal file
26
src/pocketmine/utils/LevelException.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\utils;
|
||||
|
||||
class LevelException extends ServerException{
|
||||
|
||||
}
|
26
src/pocketmine/utils/PluginException.php
Normal file
26
src/pocketmine/utils/PluginException.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\utils;
|
||||
|
||||
class PluginException extends ServerException{
|
||||
|
||||
}
|
26
src/pocketmine/utils/ServerException.php
Normal file
26
src/pocketmine/utils/ServerException.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\utils;
|
||||
|
||||
class ServerException extends \RuntimeException{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user