Help! Player-Invisible GUI

Discussion in 'Plugin Development' started by Deltateamsoldier, Oct 7, 2015.

Thread Status:
Not open for further replies.
  1. Hey Bukkit.org Community,
    i have a problem with my GUI that makes other players visible or hides them for you. If i use this code, the players dont get visible again after i press the limewool-visible block and i get all 2 messages everytime. The message that all players are now hidden and that all players are now visible
    Code:
    @EventHandler
        public void on(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            ItemStack redwool = new ItemStack(Material.WOOL, 1, DyeColor.RED.getData());
            ItemStack limewool = new ItemStack(Material.WOOL, 1, DyeColor.LIME.getData());
          
            if(e.getInventory().getName().equalsIgnoreCase("§e§lSpieler verstecken")) {
              
                try {
                  
                for(Player players : Bukkit.getOnlinePlayers()) {
                  
                    if(redwool.getDurability() == (short) 14 & !hidden.contains(p.getName())) {
                        hidden.add(p.getName());
                        p.hidePlayer(players);
                        e.getView().close();
                        p.sendMessage("§3§l» §4All players hidden");
                      
              
                    } else
                      
                    if(limewool.getDurability() == (short) 5 & hidden.contains(p.getName())) {
                        hidden.remove(p.getName());
                        p.showPlayer(players);
                        e.getView().close();
                        p.sendMessage("§3§l» §aAll players visible");
                              
                          
                }
                          
                }
      
                  
                }  catch (Exception ex) {               
                       
                }
          
                }
                  
                }
     
  2. Offline

    FabeGabeMC

  3. Offline

    Irantwomiles

    I have had the same problem, havent really found a solution to it yet.
     
  4. Okay : / nice to hear that im not the only one with that problem ^^
     
  5. Offline

    Zombie_Striker

    Don't cast without checking

    If you need to use a try catch and you do not specify what that exeption is, than most likely you're doing something wrong. Also, only put the try/catch clauses around the lines that actually throw exceptions.

    [edit] It might be a good idea to actually PRINT OUT the error?

    Please use one or the other. If you use DyeColor for the itemstack, then use it for the if statement (Be Consistant)

    Use UUIDs instead of player names. This may not be such a huge problem, but its better to get this out of the way.
     
  6. Offline

    RoboticPlayer

    If it's only for temporary data, you can use the player's name. You can even use the player object, but it is discouraged and you have to be careful with it.
     
  7. Offline

    Zombie_Striker

    No. Not at all.

    Well, technically you can But you should never have to store a whole player class.
     
  8. Offline

    RoboticPlayer

  9. Offline

    boomboompower

    This is how I use things.
    Code:
    public static Inventory gui = Bukkit.createInventory(null, 9, ChatColor.DARK_GRAY + "This is a GUI");
    Then you can do
    Code:
    if (e.getInventory().getName() == gui.getName()) {
    // Do something 
     
  10. Offline

    Zombie_Striker

    @boomboompower
    1. Why do you have the static modifier?
    2. If you're just using gui for the name, why not change the field to a string and save memory?
     
  11. Offline

    boomboompower

    @Zombie_Striker because I put it at the start, so it can be used in any part of the code.
     
  12. Offline

    Xerox262

    You do not need static to access it anywhere, it's works but it's the lazy and wrong way
     
  13. Offline

    boomboompower

    @Xerox262 ._. better than writing the same method over and over.
     
  14. Offline

    Xerox262

    Which method would that be? If you have it public and static it means anyone can just go and change it on you do you not know what public static means?
     
    Last edited: Oct 8, 2015
  15. Offline

    DoggyCode™

    Static isn't always bad:
    Code:
    @RunWith(value = Parameterized.class)
    public class JunitTest6 {
    
    private String str;
    
    public JunitTest6(String region, String coverageKind,
    String majorClass, Integer vehicleAge, BigDecimal factor) {
    this.str = region;
    }
    
    @Parameters
    public static Collection<Object[]> data1() {
    Object[][] data = {{some data}}
    
    return Arrays.asList(data);
    }
    
    @Test
    public void pushTest() {
    System.out.println("Parameterized str is : " + str);
    str = null;
    }
    
    @Parameters
    public static Collection<Object[]> data() {
    Object[][] data = {{some other data}}
    return Arrays.asList(data);
    }
    
    @Test
    public void pullTest() {
    System.out.println("Parameterized new str is : " + str);
    str = null;
    }
    }
     
  16. Offline

    boomboompower

    What. I have it public and static so that any of my plugins can use it.
     
  17. Offline

    Xerox262

    Again, you do not need public and static method to do that. It is just the lazy way. And you're seconding what I said, any plugin can just hook in and change it on you
     
  18. Offline

    boomboompower

    @Xerox262 I took that code from one of my private plugins which gets hooked into by more of my others.
     
  19. Offline

    Xerox262

    But you're telling other people to do that in their plugins too, you don't know if his plugin is private or public. And you haven't provided a reason why It's better to have it public and static rather that just private with a getter

    Edit: Apart from being too lazy to do it
     
    Last edited: Oct 9, 2015
  20. Offline

    Scimiguy

    Calm down..

    The OP is looking for help; not arguments.
     
    boomboompower likes this.
Thread Status:
Not open for further replies.

Share This Page