Quick question

Discussion in 'Plugin Development' started by Niknea, Jan 11, 2014.

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

    Niknea

    Hey guy, so I am making a class to check if a player is in an array list, then execute a public void run. However I can't do it as I don't know what to set player as. I would usaully set player as " Player player = event.getPlayer();" however I don't know what event to use. Any help would be great!
     
  2. Offline

    Maurdekye

    Please be more specific.
     
  3. Offline

    Niknea

    Maurdekye I was wondering what event I should use, as I am making a class PURELY for checking if a player is in a array list then executing a event.
     
  4. Offline

    xTigerRebornx

    Niknea Try using a scheduled repeating task, or Bukkit runnable.
     
  5. Offline

    newboyhun

    Niknea
    OMG, it depends when you want to check...
    Event is an event, it is called when it's happening/happened.
     
  6. Offline

    Niknea

    newboyhun Well I want it to check if they are in a array list, then if they a public void run would execute, which is what I said on my main post.

    xTigerRebornx Mind showing me an example?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    xTigerRebornx

    Niknea Depends on what you want to do. Mind explaining a little of what you want to do to me?
     
  8. Offline

    newboyhun

    Niknea
    No, you asked for AN EVENT to use.
    But we don't have any information about when do you want to check.....
    Nonsense
     
  9. Offline

    Niknea

    xTigerRebornx So I want to check if a player is on a array list. and if they are the code will run. Pretty much what will happen is after 10 seconds they will be removed ( so it is like a cooldown ).
     
  10. Offline

    Maurdekye

    Ohhhh, I think I might be having a similar problem. I'm pretty sure the ArrayList.contains() method doesn't work for this case, though, so you have to loop through the list and compare player names;
    Code:java
    1. public boolean checkPlayerInArrayList(ArrayList<Player> chweckIn, Player checkFor) {
    2. for (Player p : checkIn) {
    3. if (p.getName().equals(checkFor.getName())) return true;
    4. }
    5. return false;
    6. }

    As far as I know, this is the most reliable way to compare players.
     
  11. Offline

    Niknea

    Maurdekye Also what would I register it as? A listener or a command? Also would I then need to add @EventHandler?
     
  12. Offline

    Maurdekye

    I have no idea what you mean until you describe what you want in full. All you asked for was a way of checking if a player was within an arraylist. When and where do you want to check for this player? How often, and for what purpose?
     
    Garris0n likes this.
Thread Status:
Not open for further replies.

Share This Page