1.17.x Args[] param in OnCommand is broken?

Discussion in 'Spigot Plugin Development' started by TBCM, Jul 13, 2021.

  1. ok so i am trying to use a command to create events, and it has attributes inside {}. it goes something like this:

    //CreateEvent EVENT_NAME {EVENTEXEARGS} {EVENTFUNCARGS} {FINALARGS}

    //CreateEvent my_event {PlayerChatEvent} {Player.setHealth(0)} {null}

    in the Player.setHealth(0), i can change the func to whatever i want such as .message(str).

    but there is a problem with spigot when i try Player.message("you just typed something!"). spigot thinks that each space in that string is counted toward the args[] parameter of the command function. so when my script looks for the parameter it just find "you . is there any way to override the Method so that anything that is inside {} (curly brackets) is taken as 1 argument?

     
  2. Did you use sendMessage or sendRawMessage?
     
  3. You will have to join each args using Strings.join(), you will have to remove your last args from the join tho
     
  4. Player.message is just what the player can put in his command, it just runs a function called message and inside that it runs sendMessage
     
  5. i was thinking, could i use the string Command arg? i always use it for command.getName() but is command = to the whole command? String. join is a bit impractical
     
  6. The only way to do this is to join the args. Idk how you see that as impractical, but this is your only way to achieve this. Even the PreprocessCommandEvent has the arguments splitted if I remember correctly. There’s no other way.