[Unsolved] Creating ghost players not working.

Discussion in 'Plugin Development' started by leimekiller, Mar 31, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    leimekiller

    Hello, I am trying to create ghost players for spectating (Half invisible players). But it doesn't work.

    Main class:
    Code:java
    1. package com.me.emiel.gom.drunken;
    2.  
    3. import com.me.emiel.gom.drunken.Listeners.JoinQuit;
    4. import com.me.emiel.gom.drunken.Users.DrunkenUser;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.PluginManager;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.scheduler.BukkitRunnable;
    10. import org.bukkit.scoreboard.Scoreboard;
    11. import org.bukkit.scoreboard.ScoreboardManager;
    12. import org.bukkit.scoreboard.Team;
    13.  
    14. import java.util.HashMap;
    15.  
    16. public class GOM_Drunken extends JavaPlugin
    17. {
    18. public static GOM_Drunken instance;
    19.  
    20. public PluginManager pm = Bukkit.getPluginManager();
    21.  
    22. public ScoreboardManager sm;
    23. public Scoreboard board;
    24. public Team ghosts;
    25.  
    26. public HashMap<String, DrunkenUser> players = new HashMap<String, DrunkenUser>();
    27.  
    28. public void onEnable()
    29. {
    30. enable();
    31.  
    32. System.out.println("[GOM_Drunken] Enabled!");
    33. }
    34.  
    35. public void onDisable()
    36. {
    37. System.out.println("[GOM_Drunken] Disabled!");
    38. }
    39.  
    40. private void enable()
    41. {
    42. instance = this;
    43. sm = Bukkit.getScoreboardManager();
    44. board = sm.getNewScoreboard();
    45. ghosts = board.registerNewTeam("ghosts");
    46. ghosts.setAllowFriendlyFire(false);
    47. ghosts.setCanSeeFriendlyInvisibles(true);
    48.  
    49. registerListeners();
    50. setupConfig();
    51.  
    52. for(Player player : Bukkit.getOnlinePlayers())
    53. players.put(player.getName(), new DrunkenUser(player));
    54.  
    55. for(DrunkenUser user : players.values())
    56. user.makeSpectator();
    57. }
    58.  
    59. private void registerListeners()
    60. {
    61. pm.registerEvents(new JoinQuit(), this);
    62. }
    63.  
    64. private void setupConfig()
    65. {
    66.  
    67. }
    68.  
    69. public static GOM_Drunken getInstance()
    70. {
    71. return instance;
    72. }
    73. }
    74.  


    DrunkenUser class:
    Code:java
    1. package com.me.emiel.gom.drunken.Users;
    2.  
    3. import com.me.emiel.gom.drunken.GOM_Drunken;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.potion.PotionEffect;
    7. import org.bukkit.potion.PotionEffectType;
    8. import org.bukkit.scoreboard.ScoreboardManager;
    9.  
    10. public class DrunkenUser
    11. {
    12. private GOM_Drunken plugin = GOM_Drunken.getInstance();
    13.  
    14. private Player player;
    15.  
    16. private String name;
    17.  
    18. private boolean spectator;
    19.  
    20. public DrunkenUser(Player player)
    21. {
    22. this.player = player;
    23. this.name = player.getName();
    24. }
    25.  
    26. public Player getPlayer()
    27. {
    28. return player;
    29. }
    30.  
    31. public void makeSpectator()
    32. {
    33. spectator = true;
    34.  
    35. plugin.ghosts.addPlayer(player);
    36. player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 15));
    37. }
    38.  
    39. public boolean isSpectator()
    40. {
    41. return spectator;
    42. }
    43.  
    44. @Override
    45. public String toString()
    46. {
    47. return name;
    48. }
    49. }
    50.  


    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    leimekiller

    WeeziMonkey Thank you! But that did not solve my problem since they use packets which is not needed anymore.
     
  3. Offline

    Funergy

  4. Offline

    leimekiller

    Funergy Thanks but I prefer not using that since I had issues with that before, it doesn't seem to work very well.
     
  5. Offline

    BlazingBroGamer

    I think doing this solves your problem:
    Player p2 = e.getPlayer();
    for(Players p : Bukkit.getOnlinePlayers){
    p.hidePlayer(p2)
    }

    Also if you want to show the player, do the same, but p.showPlayer();
     
Thread Status:
Not open for further replies.

Share This Page