How to check if a player has done this?

Discussion in 'Plugin Development' started by Ty Cleere, Mar 1, 2014.

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

    Ty Cleere

    I'm wondering how i can check to see if a player has typed a certain command since they logged on.

    I need like a counter also to make sure they can only use this command one time when they log on.

    Also how i can block them from using that command until they re log and it resets like a counter.
     
  2. Offline

    Ironraptor3

    Code:java
    1. public static ArrayList<String> usedCommand = new ArrayList<String>();
    2.  
    3. //in onCommand
    4. if (sender instanceof Player) {
    5. Player p = (Player) sender;
    6. if (commandLabel.equalsIgnoreCase("Command") && !usedCommand.contains(p.getName()) {
    7. //do stuff
    8. usedCommand.add(p.getName());
    9. }
    10. }
    11.  
    12. // Listener
    13.  
    14. @EventHandler
    15. public void onPlayerQuit(PlayerQuitEvent e) { //or login event, they would need to relog either way
    16. if (usedCommand.contains(e.getPlayer().getName()) usedCommand.remove(e.getPlayer().getName());
    17. }


    Tahg me if you don't understand any of this ^
     
  3. Use a hashset instead of an arraylist here for better performance.
     
    regaw_leinad likes this.
Thread Status:
Not open for further replies.

Share This Page