#Getting the player who issued a command

8 messages · Page 1 of 1 (latest)

chilly lava
#

Is it possible to fetch the player who issued a command? I've been trying to through ServerEvents.command but there don't appear to be any player options.
For context, I want to disable certain, preexisting commands when a player possesses an item or has an active effect.

hollow currentBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

vocal cave
#

not all commands are ran by players

#

entities, command blocks and datapacks can also run commands

#

i believe you should be able to get the context/source from the command, and there are methods on that to check what executed it

icy stag
#

i took a look at the forge event earlier today and apparently its no better than the kubejs command event

chilly lava
#
ServerEvents.command( event => {

   let commandList = [
      'spawn'
   ]

   let effectList = [
      'minecraft:speed'
   ]

   
   let command = event.getCommandName()

   if (!commandList.some(list => {
      return command == list
      })) return

   let player = event.getParseResults().getContext().getSource().getEntity()
   if (!player.isPlayer()) return

   if (!effectList.some(list => {
      return player.hasEffect(list)
      })) return

    event.cancel();
   
})