Skip to content
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

Closed
wants to merge 10 commits into from
Closed

Player can no longer interact with anything during spectator mode #854

wants to merge 10 commits into from

Conversation

Smarticles101
Copy link
Contributor

@Smarticles101 Smarticles101 commented Apr 19, 2017

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.

if($this->inventory->getItemInHand()->getId() === Item::BOW){
$bow = $this->inventory->getItemInHand();
if($this->inventory->getItemInHand()->getId() === Item::BOW
and !$this->isSpectator()){
Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You see the spaces ;)

Copy link
Contributor Author

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

@dktapps dktapps added Category: Gameplay Related to Minecraft gameplay experience Type: Fix Bug fix, typo fix, or any other fix labels Apr 20, 2017
Copy link
Member

@dktapps dktapps left a 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.

@Muqsit
Copy link
Contributor

Muqsit commented Apr 20, 2017

How about you just...

if($this->isSpectator()){
    return;
}

@Smarticles101 Smarticles101 changed the title Fix #852 Player can no longer interact with anything during spectator mode Apr 20, 2017
@Smarticles101
Copy link
Contributor Author

There you go @dktapps

@ghost
Copy link

ghost commented Apr 21, 2017

I think it would look cleaner to check $this->spawned === true first, to match up with the rest of the file.

$this->spawned and !$this->isSpectator()

@Smarticles101
Copy link
Contributor Author

@madecode15 That's a great idea. Didn't think of it when I was changing stuff

@dktapps
Copy link
Member

dktapps commented Apr 21, 2017

Oh god no. All that boilerplate code. >_<

@Muqsit
Copy link
Contributor

Muqsit commented Apr 21, 2017

@dktapps same, not a fan of that.

@Smarticles101
Copy link
Contributor Author

Smarticles101 commented Apr 21, 2017

#blameshoghip. Should I make a method to check for all those?

@dktapps
Copy link
Member

dktapps commented Apr 21, 2017

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.

@Muqsit
Copy link
Contributor

Muqsit commented Apr 21, 2017

Should spectator players even be considered alive? If not, this will be unneeded.
IMO, they shouldn't be considered alive as it's not even a question. Spectators cannot die..

@ghost
Copy link

ghost commented Apr 21, 2017

@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.

@Smarticles101
Copy link
Contributor Author

Smarticles101 commented Apr 21, 2017

@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.

@dktapps
Copy link
Member

dktapps commented Apr 21, 2017

@madecode15 for most intents and purposes, they are dead. They are essentially ghosts.

@Smarticles101
Copy link
Contributor Author

@Muqsit @dktapps Making a spectator mode player dead would call for less changes, but I think it also might cause some confusion.

@Muqsit
Copy link
Contributor

Muqsit commented Apr 21, 2017

@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.
Plus, spectator mode players are ghosts, as you and @dktapps had said.

PC treats spectators as ghosts..
minecraft-spectators

@Smarticles101
Copy link
Contributor Author

@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.

@Smarticles101
Copy link
Contributor Author

Smarticles101 commented Apr 21, 2017

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:

@Smarticles101
Copy link
Contributor Author

Hope this is a better fix 😀 I updated the original post with new details under changes.

@@ -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()()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Copy link
Contributor Author

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()){
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

@tnytown tnytown May 5, 2017

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@dktapps dktapps May 5, 2017

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.

@@ -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()){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dktapps Better?

@dktapps
Copy link
Member

dktapps commented May 6, 2017

This is not an effective solution and will cause more problems than it solves.

@dktapps dktapps closed this May 6, 2017
@dktapps dktapps added the Resolution: Declined PR has been declined by maintainers label May 6, 2017
@Smarticles101 Smarticles101 deleted the Patch-852 branch May 6, 2017 21:12
@matcracker matcracker mentioned this pull request May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Gameplay Related to Minecraft gameplay experience Resolution: Declined PR has been declined by maintainers Type: Fix Bug fix, typo fix, or any other fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants