Running command as op

Discussion in 'Spigot Plugin Development' started by minecrafters, Jun 25, 2016.

  1. Hello i got a comamnd here for the bukkitr. disptact
    Bukkit.dispatchCommand(p2, "warp spawn2");
    It runs the player
    So example
    Bukkit.dispatchCommand(p2, "warp spawn2");
    I dont want the players side to exicute it i want the server to do it that possible?
     
  2. Replace p2 with the Server's ConsoleCommandSender, is that what you want?
     
  3. Code (Text):
    Bukkit.dispatchCommand(getServer().getConsoleSender(), "your command");
     
  4. You could use a slightly bad workaround of giving the player the permission then making them run the command then removing the permission (likely via vault)

    Or

    You can use the ConsoleSender to either side the command as a player or execute the command with the player name in the arguments (if warping supports warping other players)
     
  5. I think essentials warping support warping players with their names in the args, so you could use dispatchCommand with console, and just have the command as 'warp spawn2 playername'
     
  6. It does support player names after the warp.
     
  7. Ignore everything else and listen to this. The above snippet will execute the command AS console, and console has all permissions.
     
    • Like Like x 1
  8. Congrats you just reposted an answer .-.

    *Tick emoji* (couldn't find one)

    And on that note I would say a solved prefix is well deserved
     
    • Like Like x 1
    • Funny Funny x 1
  9. I did that because of your horrible suggestion of giving the player the permission temporarily. I wanted to clarify what the user asked.
     
  10. I also suggested what you reposted... I swear some people don't read answers anymore
     
    • Like Like x 1
  11. But i needs to target the player that joined?
     
  12. Try-finally it, give the player op in the try, and deop in finally. Commands are run synchronously anyway (or rather, they should be)