Solved Overriding base /f command from factions but not those with arguments

Discussion in 'Spigot Plugin Development' started by myokan, Apr 21, 2017.

Thread Status:
Not open for further replies.
  1. Hi everyone,

    I'm trying to write a plugin that executes code when the base command /f is run by a player but only when it has 0 arguments (e.g /f who should still pass through to FactionsUUID). Right now I'm using the following (with PlayerCommandPreprocessEvent:

    public void onPreCommand(PlayerCommandPreprocessEvent event) {
    if (event.getMessage().split("\\s+")[0].equalsIgnoreCase("/f") || event.getMessage().split("\\s+")[0].equalsIgnoreCase("/factions")) {

    Currently, this calls it whenever /f or /factions is run, but it also calls it when there are arguments.

    What can I do to prevent it from executing whenever there is more than 0 arguments?
     
  2. Can't you just check whether the command is exactly "/f" or "/factions"? (Also, splitting is expensive, rather use substring with indexOf)
     
  3. If you're splitting it anyways assign the split to a variable. If the split message 's length is > 1 it has arguments


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page