Solved Check when a static ArrayList<Player> gets a new entry

Discussion in 'Plugin Development' started by stimoze, Jul 27, 2016.

Thread Status:
Not open for further replies.
  1. So what I mean?
    I'm developing a HUGE chat control/options plugin (called ChatManagerPlus) and I'm creating "Incognito mode" in it.
    Incognito mode is a hidden chat mode (You can't see chat texts here if you aren't in the mode).
    And I want to tell the incognito users when a player joins to the mode, tell them too. What would be the best solution?

    I have a :
    Code:
    static ArrayList<Player> accessplayer = new ArrayList<Player>();
    And my listener from my Events.class:
    Code:
            if (Commands.incognito.contains(e.getPlayer()))
            {
                e.setCancelled(true);
                for (Player iplayers : Commands.incognito)
                {
                    iplayers.sendMessage(color("§b[§3Incognito Chat§b] " + e.getPlayer().getDisplayName() + " §b»§f " + e.getMessage()));
                }
            }    
     
  2. instead of directly adding something to the list, create a method that will add it to the list and tell the other players smth
     
  3. That's a good idea! Thank you :)

    One question: How do I get the "Player player = (Player) sender" from the onCommand boolean?

    EDIT: I solved it! Thanks for help :)
     
    Last edited: Jul 27, 2016
  4. Offline

    ArsenArsen

    Don't blind cast.
    if(sender instanceof Player) { Player player =...
     
  5. @stimoze And why is it static? Why not pass or staticly get the instance, OOP is good.
     
    ArsenArsen likes this.
  6. I think you forgot that I cant get a variable of another class if it isn't static.
     
  7. @stimoze I haven't forgotten at all but, your code is using static and getting variables staticly.
     
    ArsenArsen likes this.
  8. Offline

    ArsenArsen

    Google Object Oriented Programming. Java is an OOP language. Why have you defied it?
     
  9. Anyways, I've already solved the problem. And again thanks for everyone :)
     
Thread Status:
Not open for further replies.

Share This Page