Solved Config Command Executor?

Discussion in 'Spigot Plugin Development' started by Nosmakos, May 26, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys i want in my gui to add in the config a command executor for example i want in:

    Code (Text):
    Slot1:
    ItemSlot: "Diamond_Pickaxe"
    Cost: 4000
    Command:                        <========  for example if he do Command: "spawn" this will teleport him to spawn
    (this is an example i don't want to do a spawn command) any ideas how to do that? i want in every slot in this gui to add a command executor.
     
  2. Dispatchcommand? A bit unsure though I don't have direct access to my PC for another 12 hours
     
  3. Are you wanting to know how to make a player run a command? If so just use the performCommand method in the player class.
     
  4. i want to make in a config to add what command he wants to run when buying slot 1 for example if he do for Command in the gui
    Command: weather clear
    this will execute it if he buy the item slot 1 from the gui
    what is Dispatchcommand exactly ?
     
  5. Wouldn't dispatchcommand be a bit better though you can send commands through console as well? Like if the user does not have direct access to specified command. i.e. to give a crate key.

    Dispatchcommand lets you send commands from any user or console and isn't restricted to just the user in executing the event or certain command or whatever.
     
  6. oh this sounds better i guess but he will have access to everything right? i want to make the players to add in the config for command to take from crackshot weapons for example doing Command: crackshot get flamethrower but the thing is if he has permission of the crackshot the player he can do /crackshot get flamethrower and not paying and he can take every weapon he want like this so i think execute it by a console it's better. so i just have to do Dispatchcommand to config in the gui?
     
  7. You will be able to run any command through any user, console for example. Since console doesn't need any permissions it can do "crackshot give (player) flamethrower" instead of having to give the user a permission node to be able to do "crackshot get flamethrower" which can easily be abused
     
  8. Running a command though the player respects permissions, using Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Command"); does not.
     
    • Agree Agree x 1
  9. oh so how i can add this to the config? to choose his command from config?
     
  10. I know, and by the looks of what he is trying to do, he wants to setup a shop of some sort that can execute commands. By giving players permission nodes to execute specified command, why not use console as a sender, or even better, hook into some plugins and be able to give players weapons, alternate currency or whatever.
     
    • Winner Winner x 1
  11. So you would store the command as a string, and would read it from the config like this.
    Code (Text):
    FileConfiguration config = Main.plugin.getConfig();
    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), config.getString("Slot1.Command"));
     
    • Winner Winner x 1
  12. EXACTLY!!!! this is what i want to do than setting a weapon API for no reason to do this!
    so this will work? :D
     
  13. If I understand your question yes. You will just have to change how you are getting your File Configuration. I forgot to remove the Main.plugin.getConfig() thing.
     
  14. You could also make the config editor specify if he wants to make the command run through console or not by adding a variable and replacing it in the code.

    To add it to config just add a dispatchcommand and set the player to a part in the config where he or she specifies who will run the command. then just #replace it with the event#getPlayer or whatever it is, getConsoleSender, whatever.

    Sorry for the delays, on my phone.
     
  15. don't worry i made it like this.getConfig();
    so yeah i just want to execute commands from the config so people can get weapons without permission because if they do they can take all the weapons by the plugin commands
     
    • Agree Agree x 1
  16. oh also important but i can do a permission right? i can do in the config to add a perm if they have this perm they can get the weapon
     
  17. If your plugin handles it yes, I don't fully understand what you are asking about permissions.
     
  18. Like "manuaddp %player% (permission.node)" or?
     
  19. about permissions i can set in the config to add the permission he want so the player can buy the weapon from the gui and if he don't have the permission it will send him a message
     
  20. nono just a permission to contineue the slot to make the player to buy this slot because u were saying about player send the command or console and i could just make permissions for it.
     
Thread Status:
Not open for further replies.