Solved Ignoring a player's existence?

Discussion in 'Spigot Plugin Development' started by SiderRMC, Oct 14, 2018.

  1. I've been working on a Skywars plugin, and now I need help with this issue.
    As you know, Hypixel's Skywars won't set players to spectator mode after they died, it allows them be in survival mode but they cannot damage players, break/place blocks, or be visible to other players. They seem to be completely invisible because they don't play a role in blocking an alive player's movement.
    So, what event is it? How do I do event.setCancelled(false); if a spectator is really blocking a player?
  2. Anyone can solve this?
  3. I'm assuming this is for 1.9+ where they have player/entity cramming and collision physics. I know there's a way to do it with scoreboard objectives and teams, but have you tried just doing Player#hidePlayer(targetPlayer); ?
  4. hidePlayer would be the best way to do it, I believe they won't be able to push players when hidden either (?). You'll also want to cancel block place, break and interact events if you want them to not be able to do anything.
  5. Firestar311


    If you are doing this for 1.9+ there is a Player#setCollidable() method, this works great as i have used it in the past
    • Agree Agree x 3
  6. I mean, they aren't completely invisible as you claim because other spectators can still see the held items of other spectators.
    should work but I dont think it allows arrows to pass through
  7. My server runs on 1.8.

    I did hidePlayer(player) like this:
    Code (Java):
    for (Player online : Bukkit.getOnlinePlayers()) {
    However, I assume that it is just the same as
    Code (Java):
    new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, true, false)
    It hides a player from another specified player, but not erases them from player list. It doesn't affect any of the server judgments.
  8. Nope, Player#hidePlayer(); is entirely different. You should try it out.
    • Agree Agree x 1
  9. Potion doesn't make armor or items in the players hands invisible so you have to use Player#hidePlayer.

    What you end up doing is

    1. Loop through all online players and set [email protected](target)
    2. Set target collision to false
    3. Cancel all events that would affect the game. Interaction, Damage, exc.
    4. Set their allowFlight to true, and isFlying to true, and make sure you teleport them in the air so they would already be flying.
    5. Set the player to silent.
  10. How do I set the target player's collision to false? What is the exact code?
  11. LivingEntity is a superinterface of Player. It has the #isCollidable and #setCollidable(boolean) methods, so you may need to cast them to LivingEntity.
  12. Thanks. I will try that.
  13. These methods are included in 1.9+, but please notice that
  14. 1.8 is unsupported. I don't know, since I use recent versions, but I imagine that you wouldn't be able to simply totally disable a projectile hitting an invisible player either way.
  15. It's possible, but it requires some hacking & custom patching in NMS and changing the entity collision logic. Making entities invisible won't prevent projectiles from hitting. Shouldn't adventure mode do what you're asking @OP?
  16. Now that's your job to figure out what works on 1.8. I reckon there isn't much difference in the method names so it is just a simple task to look through the Player class to sieve out what's worth and what not. What you can do is this:
    1. Hide the player from all the other players
    2. Disable collision
    3. Handle the player to take no damage(classic "god mode" concept)
  17. I don't know if you're misunderstanding anything, but I'm just telling OP to go find out on his own.
  18. Oh, fuck. I'm sorry, I thought you were quoting someone. My bad!
    • Friendly Friendly x 1
  19. I don't know if this is working...
    Code (Java):
    public void activateSpectatorSettings(GamePlayer gamePlayer) {

            gamePlayerToSpectator.put(gamePlayer, true);
            Player player = gamePlayer.getPlayer();
            for (Player online : Bukkit.getOnlinePlayers()) {
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
                public void run() {
                            new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, true, false));
            }, 1);

            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
                public void run() {
            }, 1L, 1L);

    I'll soon make a quick video to show it.

Share This Page