1.12.2 Remove collisions between players and entities

Discussion in 'Spigot Plugin Development' started by Lolok, Jun 6, 2020.

  1. How can I remove collisions between players and entities?

    I tried
    Code (Java):
    player.setCollidable(false);
    entity.setCollidable(false);
    Code (Java):
    player.spigot().setCollidesWithEntities(false);
    Code (Java):
    ScoreboardManager sm = Bukkit.getScoreboardManager();
    Scoreboard scoreboard = sm.getNewScoreboard();
    Team team = scoreboard.registerNewTeam("noCollision");
    team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
    team.addEntry(player.getName());
    Code (Java):
    @EventHandler
    public void onCollision(VehicleEntityCollisionEvent e) {
      e.setCancelled(true);
    }
    None of these methods work
     
  2. I ran into the same issue with a plugin I'm making. The LivingEntity.setCollidable() doesn't seem to be working and I don't know in which version it stopped working. The scoreboard was the option that worked for me, but to work for you all you have to do is, as far as I know, set the scoreboard to at least one player. On my plugin I'm simply doing this

    Code (Java):
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            e.getPlayer().setScoreboard(plugin.NoCollisionScoreboard);
        }
     
  3. Thanks for the reply but this doesn't work for me

    That's the code:
    Code (Java):
    @EventHandler
    public void onJoin(PlayerJoinEvent e) {
       Player player = e.getPlayer();

       ScoreboardManager sm = Bukkit.getScoreboardManager();
       Scoreboard scoreboard = sm.getNewScoreboard();
       Team team = scoreboard.registerNewTeam("noCollision");
       team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
       team.addEntry(player.getName());

       player.setScoreboard(scoreboard);
    }
     
  4. You cannot create a new scoreboard everytime a player joins the server...

    Code (Java):
    ScoreboardManager sm = Bukkit.getScoreboardManager();
       Scoreboard scoreboard = sm.getNewScoreboard();
       Team team = scoreboard.registerNewTeam("noCollision");
       team.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
    this has to go in your main class on the onEnable method. Make sure to save the team and the scoreboard in a variable.

    Then onJoin:
    Code (Java):
    team.addEntry(player.getName());
       player.setScoreboard(scoreboard);
     
  5. Nothing. Should I also add the entity to the team?
     
  6. Nope it doesn't work anyway
     
  7. Here is how mine is working:
    Code (Java):
    this.TEAM = plugin.getServerScoreboard().registerNewTeam(alphabet[permissionLevel] + name);
                this.TEAM.setAllowFriendlyFire(true);
                this.TEAM.setDisplayName(getPrefix());
                this.TEAM.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
                this.TEAM.setCanSeeFriendlyInvisibles((permissionLevel >= 21));
                this.TEAM.setColor(chatColor);
    Code (Java):
    onJoin:
    getRank().getTeam().addEntry(getName())
    You don't even have to set the scoreboard to the player