[SPIGOT-2069] Disable collisions between players Created: 27/Mar/16  Updated: 10/May/16  Resolved: 27/Mar/16

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: FreeWall Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.9, entities, spigot


 Description   

I can not figure out how to disable collides between players in spigot 1.9.

These methods doesn't work:

player.spigot().setCollidesWithEntities(false);
((CraftPlayer)player).getHandle().collides = false;
((LivingEntity)player).setCollidable(false);


 Comments   
Comment by pgmann [ 10/May/16 ]

I have no idea how to make this work now... I am the author of https://github.com/pgmann/SpectatorPlus, which makes use of spigot's setCollidesWithEntities method to stop spectators pushing players who aren't spectating as well as mobs. This used to work in the earlier versions of 1.8 - I'm not quite sure when it stopped working. Why was it removed? The new alternative will not work for me as obviously I don't want to mark non-spectators as not collidable in order to stop spectators bumping into them. Neither can I start messing about with the scoreboards of non-spectators, as they may already have a scoreboard for their own game.

It would be more useful to have some way to stop entities colliding with certain entities - for example, setCollides(spectator, player, false). Or certain types of entities (not quite sure how this could be implemented).

Comment by FreeWall [ 05/May/16 ]

@totemo, thank's for your reply. I will try your solution and let you know.

@Sean Anderson, if setCollidesWithEntities method worked, it would be useless in spigot.yml

Comment by Sean Anderson [ 05/May/16 ]

Can we just get a toggle in spigot.yml, for the love of all that is good in the world?

Comment by totemo [ 05/May/16 ]

@FreeWall:

On Spigot build 765, this code is working fine:

Make sure that each player's scoreboard is set to the scoreboard that your code controls in PlayerJoinEvent (https://github.com/NerdNu/ModMode/blob/master/src/nu/nerd/modmode/ModModeListener.java#L54 - I've used the main scoreboard because it can be queried with the /scoreboard command for debugging) and be sure to add all players to some team on that scoreboard.

If it doesn't work for you, it could be because another plugin has set the Player's scoreboard to something else.

Comment by FreeWall [ 03/May/16 ]

@totemo, thank's for your interest. I've already tried to fix this using scoreboards, but setOption(Option.COLLISION_RULE, OptionStatus.NEVER) does not work for me neither.

Comment by totemo [ 24/Apr/16 ]

@FreeWall, it's my understanding that although this bug has been marked RESOLVED, it is still waiting for you to confirm the fix or alternatively get it reopened. Can you take a look?

Comment by totemo [ 23/Apr/16 ]

Fourthly, if I add players to the same team and set the collision rule as follows:

team.setOption(Option.COLLISION_RULE, OptionStatus.FOR_OWN_TEAM);

the players on the same team don't actually collide. They have been set collidable (setCollidable(true)).

The are collidable with each other if I set:

team.setOption(Option.COLLISION_RULE, OptionStatus.ALWAYS);
Comment by totemo [ 22/Apr/16 ]

For the record, I have read the documenation for [LivingEntity.setCollidable()](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/LivingEntity.html#setCollidable(boolean)).

There are a few problems here.

Firstly, if the Scoreboard has an impact on the collision behaviour, and the documentation for setCollidable() does not state that, then it is unhelpful and arguably incomplete and therefore defective. If people waste their time googling, or having to test the API behaviour with running code to resolve ambiguities or omissions, then the documentation has failed in its only task.

Secondly, the API is arguably non-sensical. If a player is "non-collidable" that should mean that he does not collide with things, irrespective of whether those things have been marked non-collidable or not. The API should not require that I first find all of the things that the player might collide with in order to mark them non-collidable as well. That would be repeating the work that the collision testing code will do. In my use case, I want a vanished staff member to be able to pass through other players like a ghost, irrespective of whether those other, regular players can collide with each other. I don't don't want to have to mess with their collidability for the couple of ticks that the staff member is passing through. But I have a solution to that, which as md5 mentions is to set up the scoreboard team.

Thirdly, in my testing on the current build (#765), the API does not function as documented. I have all players in my test marked as non-collidable; isCollidable() returns false for all of them. Despite this, they can push each other around. All players are assigned to the main scoreboard (which uses teams to colour name tags for vanished staff that can see each other) but in the test case, the players are not members of any teams - something I can readily verify with /scoreboard teams list. If I switch a staff member to their vanished staff team, and if that team is configured as: .setOption(Option.COLLISION_RULE, OptionStatus.NEVER);, then the staff member can indeed pass through the other player like a ghost. However, the point is that setCollidable() does absolutely nothing at all.

Comment by Jörn D. [ 28/Mar/16 ]

Yeah it's not working for me too!

Comment by FreeWall [ 28/Mar/16 ]

I'm setting LivingEntity.setCollidable for both players (actually for all players) and I'm not using scoreboard at all.
Still doesn't work for me.

BTW: I know several developers which have the same problem, also similar issue was reported here: https://hub.spigotmc.org/jira/browse/SPIGOT-2070

Comment by md_5 [ 28/Mar/16 ]

You need to set it for both players. Also unless using in conjunction with a scoreboard there will still be push back, but no movement.

Comment by FreeWall [ 28/Mar/16 ]

Documentation about setCollidesWithEntities says:

Deprecated. LivingEntity.setCollidable(boolean)

But LivingEntity.setCollidable(boolean) also doesn't work.

I'm not sure what should I read in the documentation.
Can you explain more? Thank's a lot.

Comment by md_5 [ 27/Mar/16 ]

Read the documentation.

Generated at Mon Dec 15 03:42:04 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.