Fix this?

Discussion in 'Plugin Development' started by draypvp, Apr 26, 2014.

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

    draypvp

    Code:java
    1. package me.pogostick29.vanish;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.event.player.PlayerQuitEvent;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class vanish extends JavaPlugin implements Listener {
    17.  
    18. public void onEnable() {
    19. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    20. }
    21.  
    22. private ArrayList<Player> vanished = new ArrayList<Player>();
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    25.  
    26. if (!(sender instanceof Player)) {
    27. sender.sendMessage(ChatColor.RED + "You cannot vanish!");
    28. return true;
    29. }
    30.  
    31. Player p = (Player) sender;
    32.  
    33. if (cmd.getName().equalsIgnoreCase("vanish")) {
    34. // Check perms
    35.  
    36. if (!vanished.contains(p)) {
    37. for (Player pl : Bukkit.getServer().getOnlinePlayers()) {
    38. pl.hidePlayer(p);
    39. }
    40. vanished.add(p);
    41. p.sendMessage(ChatColor.GREEN + "You have been vanished!");
    42. return true;
    43. }
    44. else {
    45. for (Player pl : Bukkit.getServer().getOnlinePlayers()) {
    46. pl.showPlayer(p);
    47. }
    48. vanished.remove(p);
    49. p.sendMessage(ChatColor.GREEN + "You have been unvanished!");
    50. return true;
    51. }
    52. }
    53. return true;
    54. }
    55.  
    56. @EventHandler
    57. public void onPlayerJoin(PlayerJoinEvent e) {
    58. for (Player p : vanished) {
    59. e.getPlayer().hidePlayer(p);
    60. }
    61. }
    62.  
    63. @EventHandler
    64. public void onPlayerLeave(PlayerQuitEvent e) {
    65. vanished.remove(e.getPlayer());
    66. }
    67. }


    How would I make it so that when the user is vanished, they cannot pick up items?
     
  2. Offline

    Gigabyte_Giant

    Code:java
    1. if (ply.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
    2.  
    3. ply.setCanPickupItems(false);
    4.  
    5. }


    Super simple. Replace "ply" with you player instance. :)

    Simple as that.
     
  3. Offline

    Jade

    Moved to a more appropriate section.
     
  4. Offline

    MayoDwarf


    draypvp
    if(vanished.contains(player.getName()) { player.setCanPickupItems(false); } Use string ArrayLists unless you know how to handle Player ArrayLists. I suggest String ones as they are far more easier to work with.
     
Thread Status:
Not open for further replies.

Share This Page