Command that runs another command.

Discussion in 'Spigot Plugin Development' started by Redblock6, Aug 5, 2018.

  1. Hello!
    I was wondering if in eclipse there was a way to add a command so that when you execute that command it will execute another command. Like a give command, for example. Also how would I add support for 1.8-1.13?

    Thanks and Best regards,
  2. You can execute commands from plugin code, if that's what you're asking. It's Bukkit#dispatchCommand. The first argument is who sent it, the second is the command, without the leading slash. So, for example.
    Code (Text):
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "give Redblock6 diamond");
  3. Wait, I would put it in the parenthesis so I would put /nnick in the parenthesis and then in the quote the give command?
  4. Bukkit.getConsoleSender() just gets the server command sender, so it executes the command as if sent from the console. If you want a player to send the command, use a Player object, or if you're working in an onCommand() method, then the CommandSender argument can be used regardless of if it's Player or console that activated it. Possibly even command blocks, not sure about that one.

    So in short, first argument is any any Player or CommandSender you want to execute the command, the second argument is the command.
    • Agree Agree x 1
  5. Hi, Just to make sure...
    would this work: "Bukkit.dispatchCommand(Bukkit.getConsoleSender(player), "/give <player> written_book 1 0 {pages:["[\"\",{\"text\":\"Lets get you setup with your nickname!\\nFirst, you will need to chose wich \"},{\"text\":\"RANK \",\"bold\":true},{\"text\":\"\\nyou would like to be\\nshown as when nicked.\\n\\n\\u27a4 \",\"color\":\"reset\"},{\"text\":\"DEFAULT\",\"color\":\"gray\",\"clickEvent\":{\"action\":\"change_page\",\"value\":2},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click here to be shown as DEFAULT\"}},{\"text\":\"\\n\\n\\u27a4 \",\"color\":\"reset\"},{\"text\":\"VIP\",\"color\":\"green\",\"clickEvent\":{\"action\":\"change_page\",\"value\":2},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click to be shown as VIP\"}},{\"text\":\"\\n\\n\\u27a4 \",\"color\":\"reset\"},{\"text\":\"REDBLOCKS\",\"color\":\"red\",\"clickEvent\":{\"action\":\"change_page\",\"value\":2},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click to be shown as REDBLOCKS\"}}]","[\"\",{\"text\":\"Awesome! Now, wich \\n\"},{\"text\":\"SKIN\",\"bold\":true},{\"text\":\" would you like to have while nicked?\\n\\n\",\"color\":\"reset\"},{\"text\":\"\\u27a4 My normal skin\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"3\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click here to use your normal skin\"}},{\"text\":\"\\n\\n\"},{\"text\":\"\\u27a4 Steve/Alex skin\",\"clickEvent\":{\"action\":\"change_page\",\"value\":3},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click here to use a steve/alex skin\"}},{\"text\":\"\\n\\n\"},{\"text\":\"\\u27a4 Random skin\",\"clickEvent\":{\"action\":\"change_page\",\"value\":3},\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Click here to use a random present skin\"}}]","[\"\",{\"text\":\"Alright, Now you will need to choose a \"},{\"text\":\"NAME\",\"bold\":true},{\"text\":\" you would like to choose.\\n\\n\",\"color\":\"reset\"},{\"text\":\"\\u27a4 Enter a name\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"You cant do this, it is currently in development. Sorry.\"}},{\"text\":\"\\n\\n\\u27a4 Use random name\"}]"],title:Nick,author:"The MCREDBLOCK team"}");"
  6. Im just kinda new to this stuff. How would I make it so when a player does the command /nnick it will give then a book or a book will pop up
  7. Bukkit.getConsoleSender() does not accept any arguments. If you want to send it to a player, just replace that with the player variable. Otherwise it looks like you've more or less got it, assuming that mess of JSON is valid, but you can check that online elsewhere.
  8. Would I put this below my command I made in eclipse
  9. I'm not entirely sure what you're asking. Bukkit.DispatchCommand() can be placed anywhere in the logic where you need to execute the command. It's up to you where that is. If you're not sure, then try to get more familiar with logic flow in Java.
  10. ok thanks. How would I allow 1.8-1.13 be able to use my plugin?
  11. Also I would put Bukkit.DispatchCommand(%player%) a varuble where is says a varuble? Would that work?
  12. Best advice I can give since you're not grasping what we're trying to tell you is to stop and get a better grasp of Java first. I don't like telling people that generally, but I can't help you with your current understanding of things. I'm more patient than a lot of people here, but I don't know what else to tell you.
  13. you would have to do .replace("%player%", player.getname())

    just add all libraries for 1.8-1.13
  14. Thanks!!!
  15. also if you are trying to give a player a book, I would recomend creating an itemstack, then doing player.getinventory.additem(itemstack), it makes editing easier as you will find it hard to edit the command above
  16. oh
  17. tysm
  18. Not quite how that works. It largely depends on the code and where there have been changes between major API versions. When there are issues, you have to adapt as necessary :T
  19. So then how do I do it?
  20. Again, as I mentioned, it depends on the code. Usually for small things specific to the version, it could be as simple as an if statement to get the server's version and run a specific method.

    Really, if it's just running a certain command when a player does something, then it shouldn't give any issues. I'd recommend, if in question, at least testing on the earliest and latest major versions you should be supporting, like 1.8, 1.12, 1.13. I know that can be a pain, though..
    You should always compile against the latest version, though. If the latest version is 1.13, use that API version and try to support what's lacking in older API versions.