-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Player can no longer interact with anything during spectator mode #854
Conversation
src/pocketmine/Player.php
Outdated
if($this->inventory->getItemInHand()->getId() === Item::BOW){ | ||
$bow = $this->inventory->getItemInHand(); | ||
if($this->inventory->getItemInHand()->getId() === Item::BOW | ||
and !$this->isSpectator()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't quite sure whether to put the and !$this->isSpectator()
onto a new line or not because it would have made the header of the if statement longer, but I also realize that some people don't like long headers, so I put it on the next line and then inserted another line after for readability's sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same line. Look at the statement just before it, its on the same line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
src/pocketmine/Player.php
Outdated
if($this->inventory->getItemInHand()->getId() === Item::BOW){ | ||
$bow = $this->inventory->getItemInHand(); | ||
if($this->inventory->getItemInHand()->getId() === Item::BOW and !$this->isSpectator()){ | ||
$bow = $this->inventory->getItemInHand(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You see the spaces ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh this should be the last time I have this problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a general issue which does not just apply to bows. A specific check for bows is more of a hack.
How about you just...
|
There you go @dktapps |
I think it would look cleaner to check $this->spawned === true first, to match up with the rest of the file.
|
@madecode15 That's a great idea. Didn't think of it when I was changing stuff |
Oh god no. All that boilerplate code. >_< |
@dktapps same, not a fan of that. |
#blameshoghip. Should I make a method to check for all those? |
This is ugly. I don't consider boilerplating this up to be an effective solution to the problem. This will also conflict with changes made on the api3/network branch. api3/network should for the time being be considered the primary branch. |
Should spectator players even be considered alive? If not, this will be unneeded. |
@Muqsit There not dead, so yes, they should be considered alive. Should the server have to tick them, probably not. Though making them "dead" would be a hack. |
@madecode15 I'm pretty sure that the server already doesn't check for collisions on them as spectator mode players have no-clip on. Also, I think that setting a spectator mode player to be dead would be correct because it is more of a "ghost" mode where they should have no effect on anything in the world just as dead players. |
@madecode15 for most intents and purposes, they are dead. They are essentially ghosts. |
@Smarticles101 Can you give examples of confusions that could happen? I think it's okay for the most part. This would also eliminate other isSpectator() checks. |
@Muqsit Well, at first, I was thinking it could confuse plugin developers, but after more consideration, I don't think there are any cases in which it would matter, so I'll go ahead and make the changes. |
Wait a second. So I tried setting health to 0, which just kills the player. So then I tried making an isAlive method in the Player class that adds an extra check to always return false if the player is a spectator. Then I found out that that doesn't even let you move. Then I looked around and found places where it causes problems in the Player class: |
Hope this is a better fix 😀 I updated the original post with new details under changes. |
src/pocketmine/Player.php
Outdated
@@ -2310,7 +2321,7 @@ public function handleDataPacket(DataPacket $packet){ | |||
break; | |||
|
|||
case ProtocolInfo::REMOVE_BLOCK_PACKET: | |||
if($this->spawned === false or !$this->isAlive()){ | |||
if($this->spawned === false or !$this->isAlive()()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I thought that those weren't mine but it turns out they were. I searched and replaced the method without parenthesis and so it left them
@@ -1378,7 +1385,7 @@ protected function checkNearEntities($tickDiff){ | |||
} | |||
|
|||
protected function processMovement($tickDiff){ | |||
if(!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null or $this->isSleeping()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I contest the decision that this is not needed. This will allow hacked clients to move around while dead. It also doesn't make sense to allow this regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be considered anticheat?
If there is a better way to implement this PR, I would be glad to. I tried implementing what was previously suggested. I might need someone to give me a push in the right direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also doesn't make sense to allow this regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be considered anticheat?
It's a basic sanity check. There's no valid context in which dead players will move.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That project is targeted at removing the irritating parts of the anti-cheat and placing them in plugins. However it makes zero sense to have a plugin for the sake of stopping dead players moving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no valid context in which dead players will move.
for most intents and purposes, they are dead. They are essentially ghosts.
Spectator mode players need to be able to move
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for most intents and purposes
That does not mean that they are literally dead.
Spectators share many behavioural characteristics with dead players. Movement is not one of them.
src/pocketmine/Player.php
Outdated
@@ -1385,7 +1385,7 @@ protected function checkNearEntities($tickDiff){ | |||
} | |||
|
|||
protected function processMovement($tickDiff){ | |||
if(!$this->spawned or $this->newPosition === null or $this->teleportPosition !== null or $this->isSleeping()){ | |||
if(!$this->isAlive() and !$this->isSpectator() or !$this->spawned or $this->newPosition === null or $this->teleportPosition !== null or $this->isSleeping()){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dktapps Better?
This is not an effective solution and will cause more problems than it solves. |
Introduction
Fixes problems with spectator mode functionality.
Relevant issues
Changes
Added custom isAlive() function to Player that returns false if the player is in spectator mode. Removed some places where that causes issues that were not needed in the first place, found one or two calls to isAlive that had two pairs of parentheses and removed the extra pairs.