Solved PlayerCommandPreprocessEvent question

Discussion in 'Plugin Development' started by Smartloser, Feb 4, 2014.

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

    Smartloser

    Hey guys. So, I basically want that if a player executes a command while being in a hashmap, it'll remove him. Simple as that.

    So, I came up with this code:
    Code:java
    1.  
    2. if (e.getMessage().equalsIgnoreCase("/warp"))
    3. {
    4. if (InventoryHandler.hash.containsKey(p))
    5. {
    6. p.sendMessage("Hi");
    7. InventoryHandler.hash.remove(p);
    8. Bukkit.getScheduler().cancelTask(InventoryHandler.Task);
    9. }
    10.  
    11. if (ScoreHandler.levelscore.containsKey(p))
    12. {
    13. ScoreHandler.levelscore.remove(p);
    14. Bukkit.getScheduler().cancelTask(InventoryHandler.Task);
    15. p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).unregister();
    16. }
    17. }
    18.  

    Now, this code executes only if I type /warp with no arguments. I would like it to also execute when there is 1 arguments, (ex. Works when I type /warp, doesn't if I type /warp C). How can I make it execute when there are arguments too?

    Thanks for all the help.

    -Smartloser
     
  2. Offline

    ThePlayerPaul

    You have to split
     
  3. Offline

    Henzz

    Smartloser
    Try this in your if statement. This will split the message using spaces to an array, so here we're checking if the command is used and there are 1 or more arguments.
    Code:
    if (event.getMessage().startsWith("/warp") ||
                    event.getMessage().startsWith("/warp") && event.getMessage().split(" ").length >= 1) {
     
  4. Offline

    Smartloser

    Henzz
    Thank you sir, that solved it!.
     
Thread Status:
Not open for further replies.

Share This Page