From 60011a5ecfaeff5c973ee97f0dc4760e90077ac9 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 10 Sep 2014 20:05:41 +0200 Subject: [PATCH 1/8] Fixed PermissionAttachment not recalculating its Permissible permissions --- src/pocketmine/permission/PermissionAttachment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index f1a93c309..0f9f03995 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -102,6 +102,7 @@ class PermissionAttachment{ */ public function unsetPermission($name){ unset($this->permissions[$name instanceof Permission ? $name->getName() : $name]); + $this->permissible->recalculatePermissions(); } /** From fba12c6ddfb56eede099b738800ccd88647c6f17 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 10 Sep 2014 20:06:30 +0200 Subject: [PATCH 2/8] Fixed EntityMoveEvent not being cancelled correctly on players --- src/pocketmine/Player.php | 2 +- src/pocketmine/entity/Entity.php | 7 ++++++- src/pocketmine/level/Level.php | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 36f90e127..4463c1056 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1368,7 +1368,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->setRotation($packet->yaw, $packet->pitch); //$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - $this->move($dx, $dy, $dz); + $revert = !$this->move($dx, $dy, $dz); $diffX = $this->x - $newPos->x; $diffZ = $this->z - $newPos->z; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 49f6bd23f..f6520a153 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -715,7 +715,7 @@ abstract class Entity extends Position implements Metadatable{ //$collision = []; //$this->checkBlockCollision($collision); if($dx == 0 and $dz == 0 and $dy == 0){ - return; + return true; } //if($this->inBlock){ //TODO: noclip @@ -887,8 +887,11 @@ abstract class Entity extends Position implements Metadatable{ ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 ); + $result = true; + if(!$this->setPosition($pos)){ $this->boundingBox->setBB($axisalignedbb); + $result = false; }else{ if($this instanceof Player){ @@ -922,6 +925,8 @@ abstract class Entity extends Position implements Metadatable{ //TODO: vehicle collision events (first we need to spawn them!) Timings::$entityMoveTimer->stopTiming(); + + return $result; //} } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 12066e394..af0e66f31 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -913,6 +913,7 @@ class Level implements ChunkManager, Metadatable{ } $this->changedBlocks[$index][$Y][] = clone $block; } + if($update === true){ $this->updateAround($pos, self::BLOCK_UPDATE_NORMAL); $block->onUpdate(self::BLOCK_UPDATE_NORMAL); From 4624dfb472279b01e4df2c77a27006c6d58a15d1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 12:17:03 +0200 Subject: [PATCH 3/8] Fixed Permissible::setPermission() not using the correct order on replacement --- src/pocketmine/permission/PermissibleBase.php | 6 +++--- src/pocketmine/permission/PermissionAttachment.php | 4 +++- src/pocketmine/plugin/PluginManager.php | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/permission/PermissibleBase.php b/src/pocketmine/permission/PermissibleBase.php index 371c1ab8a..ae1218cea 100644 --- a/src/pocketmine/permission/PermissibleBase.php +++ b/src/pocketmine/permission/PermissibleBase.php @@ -194,10 +194,10 @@ class PermissibleBase implements Permissible{ * @param bool $invert * @param PermissionAttachment $attachment */ - public function calculateChildPermissions(array $children, $invert, $attachment){ - foreach(array_keys($children) as $name){ + private function calculateChildPermissions(array $children, $invert, $attachment){ + foreach($children as $name => $v){ $perm = Server::getInstance()->getPluginManager()->getPermission($name); - $value = $invert === true ? !$children[$name] : $children[$name]; + $value = ($v xor $invert); $this->permissions[$name] = new PermissionAttachmentInfo($this->parent, $name, $attachment, $value); Server::getInstance()->getPluginManager()->subscribeToPermission($name, $this->parent); diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index 0f9f03995..492050669 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -93,7 +93,9 @@ class PermissionAttachment{ * @param bool $value */ public function setPermission($name, $value){ - $this->permissions[$name instanceof Permission ? $name->getName() : $name] = $value; + $name = $name instanceof Permission ? $name->getName() : $name; + unset($this->permissions[$name]); //Fixes children getting overwritten + $this->permissions[$name] = $value; $this->permissible->recalculatePermissions(); } diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index 994f1e451..9abe18a98 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -434,6 +434,9 @@ class PluginManager{ public function unsubscribeFromPermission($permission, Permissible $permissible){ if(isset($this->permSubs[$permission])){ unset($this->permSubs[$permission][spl_object_hash($permissible)]); + if(count($this->permSubs[$permission]) === 0){ + unset($this->permSubs[$permission]); + } } } From 0328b4c5f5eb49ecb5f116295482d3d684da2f57 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 12:39:01 +0200 Subject: [PATCH 4/8] Added PermissionAttachment::setPermissions() This allows bulk permission without recalculating the new permissions until all everything is set. Permission plugins that set a big amount of nodes may want to use this method. --- src/pocketmine/permission/PermissionAttachment.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index 492050669..be5eb80e4 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -88,6 +88,17 @@ class PermissionAttachment{ return $this->permissions; } + /** + * @param bool[] $permissions + */ + public function setPermissions(array $permissions){ + $this->permissions = []; + foreach($permissions as $key => $value){ + $this->permissions[$key] = (bool) $value; + } + $this->permissible->recalculatePermissions(); + } + /** * @param string|Permission $name * @param bool $value From 78b42237950b926d20e20735b5cf125e3f71742f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 12:43:53 +0200 Subject: [PATCH 5/8] Added PermissionAttachment::unsetPermissions(), PermissionAttachment::clearPermissions() --- src/pocketmine/permission/Permissible.php | 1 - .../permission/PermissionAttachment.php | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/permission/Permissible.php b/src/pocketmine/permission/Permissible.php index 777337fb8..7b59a2ac0 100644 --- a/src/pocketmine/permission/Permissible.php +++ b/src/pocketmine/permission/Permissible.php @@ -66,7 +66,6 @@ interface Permissible extends ServerOperator{ public function recalculatePermissions(); /** - * TODO: Check this * @return Permission[] */ public function getEffectivePermissions(); diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index be5eb80e4..585afbcda 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -88,17 +88,34 @@ class PermissionAttachment{ return $this->permissions; } + /** + * @return bool[] + */ + public function clearPermissions(){ + $this->permissions = []; + $this->permissible->recalculatePermissions(); + } + /** * @param bool[] $permissions */ public function setPermissions(array $permissions){ - $this->permissions = []; foreach($permissions as $key => $value){ $this->permissions[$key] = (bool) $value; } $this->permissible->recalculatePermissions(); } + /** + * @param string[] $permissions + */ + public function unsetPermissions(array $permissions){ + foreach($permissions as $node){ + unset($this->permissions[$node]); + } + $this->permissible->recalculatePermissions(); + } + /** * @param string|Permission $name * @param bool $value From 7ef2708fca04b68696d0a0eb07cb237eef5899da Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 16:43:11 +0200 Subject: [PATCH 6/8] Permission & interface optimization --- src/pocketmine/network/RakLibInterface.php | 7 ++----- src/pocketmine/permission/PermissionAttachment.php | 14 +++++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index b6ad89bba..89c989aa3 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -97,8 +97,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{ /** @var ServerHandler */ private $interface; - private $tickTask; - private $upload = 0; private $download = 0; @@ -109,7 +107,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $server = new RakLibServer($this->server->getLogger(), $this->server->getLoader(), $this->server->getPort(), $this->server->getIp() === "" ? "0.0.0.0" : $this->server->getIp()); $this->interface = new ServerHandler($server, $this); $this->setName($this->server->getMotd()); - $this->tickTask = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask([$this, "doTick"]), 1); } public function doTick(){ @@ -124,6 +121,8 @@ class RakLibInterface implements ServerInstance, SourceInterface{ } } + $this->doTick(); + return $work; } @@ -147,12 +146,10 @@ class RakLibInterface implements ServerInstance, SourceInterface{ } public function shutdown(){ - $this->tickTask->cancel(); $this->interface->shutdown(); } public function emergencyShutdown(){ - $this->tickTask->cancel(); $this->interface->emergencyShutdown(); } diff --git a/src/pocketmine/permission/PermissionAttachment.php b/src/pocketmine/permission/PermissionAttachment.php index 585afbcda..75a8daba2 100644 --- a/src/pocketmine/permission/PermissionAttachment.php +++ b/src/pocketmine/permission/PermissionAttachment.php @@ -122,7 +122,12 @@ class PermissionAttachment{ */ public function setPermission($name, $value){ $name = $name instanceof Permission ? $name->getName() : $name; - unset($this->permissions[$name]); //Fixes children getting overwritten + if(isset($this->permissions[$name])){ + if($this->permissions[$name] === $value){ + return; + } + unset($this->permissions[$name]); //Fixes children getting overwritten + } $this->permissions[$name] = $value; $this->permissible->recalculatePermissions(); } @@ -131,8 +136,11 @@ class PermissionAttachment{ * @param string|Permission $name */ public function unsetPermission($name){ - unset($this->permissions[$name instanceof Permission ? $name->getName() : $name]); - $this->permissible->recalculatePermissions(); + $name = $name instanceof Permission ? $name->getName() : $name; + if(isset($this->permissions[$name])){ + unset($this->permissions[$name]); + $this->permissible->recalculatePermissions(); + } } /** From 0bd7ab9def9b248c0a388b924fff18baca25f841 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 17:38:17 +0200 Subject: [PATCH 7/8] Added .mailmap file, fixes duplicated commiter names --- .mailmap | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .mailmap diff --git a/.mailmap b/.mailmap new file mode 100644 index 000000000..2141dc400 --- /dev/null +++ b/.mailmap @@ -0,0 +1,5 @@ +Shoghi Cervantes +Shoghi Cervantes Shoghi Cervantes +Brandon V +Michael Yoo Michael Yoo +Michael Yoo Michael Yoo \ No newline at end of file From cfcf515f626343470b6e063aeb620022019f492f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 11 Sep 2014 21:57:56 +0200 Subject: [PATCH 8/8] Added type hint to BlockEvent::getBlock() --- src/pocketmine/event/block/BlockEvent.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pocketmine/event/block/BlockEvent.php b/src/pocketmine/event/block/BlockEvent.php index e40e05f33..c2ac0eb47 100644 --- a/src/pocketmine/event/block/BlockEvent.php +++ b/src/pocketmine/event/block/BlockEvent.php @@ -38,6 +38,9 @@ abstract class BlockEvent extends Event{ $this->block = $block; } + /** + * @return Block + */ public function getBlock(){ return $this->block; }