Solved is player in List<>

Discussion in 'Spigot Plugin Development' started by Rob.pizza, May 31, 2017.

  1. So I ran into a little problem,

    In my "Vanish" class I have the following
    Code (Text):
    public List<String> vanish = new ArrayList<String>();
    Putting players into the list and getting them out no problem but when I try to check if a player is in the list from another class it always returns 'null'

    *cut*


    Anyone knows what I do wrong? :3
    Thank you!
     
    #1 Rob.pizza, May 31, 2017
    Last edited: Jun 2, 2017
  2. Gianluca

    Gianluca Retired Resource Staff
    Retired Patron

    Change the List type to Player then, or add them by their name... If you're storing per restarts, I'd recommend using UUID

    Also, you can shorten the code to:

    Code (Text):
    public boolean isVanish(Player p) {
        return Vanish.getInstance().getVanish().contains(p));
    }
     
    • Informative Informative x 1
  3. Null? You return true or false, it won't be null. Did you mean you got a NullPointerException?

    Also, use a Set rather than List, it's faster. And static is not an access modifier, so you shouldn't use it to access the vanish collection.
     
    • Agree Agree x 1
    • Informative Informative x 1
  4. Thank you for your reply! :D

    I'll change it to UUID and test your way Ty! :D
     
  5. Didn't work @Gianluca

    This is in my current 'Vanish' class

    *cut*

    But it isn't blocking the command at all :p
     
    #5 Rob.pizza, May 31, 2017
    Last edited: Jun 2, 2017
  6. You have to check the first word of the event's command/message only, and I don't think the message includes a '/'.
     
  7. And also make it final, cause why tf not.
     
  8. Choco

    Moderator

    And also make it private, cause why tf not.
    (I like this game)
     
  9. You can also make it transient, cause why tf not.
     
    • Friendly Friendly x 1
  10. You can also make it an object, cause why tf not.

    (Clearly have not understood this game, second thoughts have gone into this reply)
     
    • Like Like x 2
  11. Make it volatile, because why not :D
     
    • Funny Funny x 2
    • Like Like x 1
    • Agree Agree x 1
  12. Then its settled....
    private final transient volatile Set<UUID>

    Good work guys!

    EDIT: I forgot one, lol...
     
    • Winner Winner x 2
    • Like Like x 1
    • Optimistic Optimistic x 1
  13. I ment the Boolean method I created always returned false. so the command isn't blocked at all.
    But since nothing is working I'm interested in Set.
    I'll search it up Ty
     
  14. Choco

    Moderator

    Jeez... it's almost like we're on Reddit or something
     
    • Funny Funny x 1
  15. Reddit wishes it was this good
     
    • Like Like x 1
    • Agree Agree x 1
    • Winner Winner x 1
  16. if supported by your java level, then infer arguments in the set, (generics)

    cause why tf not

    Code (Java):

    Set<UUID> uuids = new HashSet<UUID>();
    ->
    Set<UUID> uuids = new HashSet<>();
     
    • Like Like x 1
    • Agree Agree x 1
  17. FrostedSnowman

    Resource Staff


    LOL. i was actually dying laughing with all the latest comments.
     
    • Like Like x 1
  18. What about static?
     
    • Optimistic Optimistic x 2
  19. Leave...
     
    • Agree Agree x 1
  20. Why tf not?