Solved Toggle Players

Discussion in 'Plugin Development' started by PreFiXAUT, Aug 15, 2013.

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

    PreFiXAUT

    Hi, I'm trying to create a Command, which allowes the Player to only see himself.
    Im using the Command "/hide"
    This is what I got now:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender cs, Command cmd, String label,String[] args) {
    3.  
    4. if (cs instanceof Player)
    5. {
    6. Player p = (Player) cs;
    7. if (args.length == 0)
    8. {
    9. p.sendMessage("You have to use a Command!");
    10. return true;
    11. }
    12. else if (args.length == 1)
    13. {
    14. for (Player invis : Bukkit.getOnlinePlayers())
    15. {
    16. if (!invis.getPlayer().equals(p.getName()))
    17. {
    18. p.hidePlayer(invis);
    19. return true;
    20. }
    21. }
    22. }
    23. else if (args.length == 2)
    24. {
    25.  
    26. }
    27. return true;
    28. }
    29. else
    30. {
    31. cs.sendMessage("You have to be a Player to use this Command!");
    32. return true;
    33. }
    34. }


    But now, I don't know how to toggle this, that the Player is able to see all again. Because it's a bit pointless if you can't see anyone anymore when you're playing an PVP Game.
     
  2. PreFiXAUT Use the same stuff you used to hide them, I thing there's a method called: setVisible() or setHidden() which allows you to pass a boolean.
     
  3. Offline

    PreFiXAUT

    CaptainBern
    How can I call the .setVisible/setHidden Method? Because p.setVisible() won't exist.
     
  4. Offline

    tommycake50

    Have a look at this code from a plugin i wrote to hide all players when you click an item, it's for a minigame server me and my friend are creating but it can be adapted.
    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerClickEvent(PlayerInteractEvent e){
    4. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if(e.getPlayer().getItemInHand().getType().equals(Material.BLAZE_POWDER)){
    6. if(!inst.players.contains(e.getPlayer().getName())){
    7. for(Player p : inst.getServer().getOnlinePlayers()){
    8. e.getPlayer().hidePlayer(p);
    9. }
    10. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 6F, 1F);
    11. inst.players.add(e.getPlayer().getName());
    12. }else{
    13. for(Player p : inst.getServer().getOnlinePlayers()){
    14. e.getPlayer().showPlayer(p);
    15. }
    16. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 6F, 1F);
    17. inst.players.remove(e.getPlayer().getName());
    18. }
    19. }
    20. }
    21. }
    22.  

    btw inst is an instance of the plugin and players is an arraylist that holds playernames.
     
Thread Status:
Not open for further replies.

Share This Page