Command Item Click

Discussion in 'Archived: Plugin Requests' started by ifraaank, Aug 30, 2013.

  1. Offline

    ifraaank

    Another plugin request!

    Plugin category: Mechanics

    Suggested name: ItemCommander

    What I want: I would like a plugin, which makes it possible to execute commands with items. (configurable). Like if you had a clock, and you right-clicked it, it would do the command /time set day. Or tp. Or other commands.

    A config like:
    itemnumber: command

    Ideas for commands: None, this is to get rid of commands :p

    Ideas for permissions: itemcommand.use

    When I'd like it by: As soon as possible. :)

    I know there's a plugin like this, but it isn't updated, and I can't get it to work! :)
     
  2. Offline

    bartboy8

    I'll make this for ya :) it should be fairly easy
     
  3. Offline

    ifraaank

    Epic! Thank you very much :)
     
  4. Offline

    Me4502

    CraftBook can already do this with its CommandItems feature

    Edit: plus, you can even create them ingame if the config is too daunting.

    For more info you can check the craftbook wiki.
     
  5. Offline

    ifraaank

    I'll try that. But a standalone plugin would be nice, so I hope bartboy8 will make this for me anyways. :)
     
  6. Offline

    Chaositic

    Just so you're aware, Craftbook can have almost all features disabled if you wanted and it's also a lightweight plugin even with everything left on. I understand wanting a standalone plugin but also be aware that there are also other plugins that have your feature with additions such as cooldowns, costs and bind to any item. If you wanted, you could use custom crafting in craftbook and craft a custom named item that is bound with the command you want.

    In addition, other plugins do this exact function too. Magicspells, Skript and VariableTriggers can all bind a command to an item and apply a cooldown. I recommend you look at those plugins because they're all lightweight and easy to use.

    Aside from that though, not trying to stop bartboy8 from coding the plugin.

    Good luck.
     
  7. Offline

    ifraaank

    I'll take a look. Thank you for letting me know! :)
     
  8. Offline

    thomasoo

    Threw together something quick. Up to you if you use it or not
    https://dl.dropboxusercontent.com/u/13819323/cmd.jar
    Bug : you can't use it in the air, only on blocks.
    code is pretty messy if you can even call hardcoding "coding".
    never actually read a java book before, only learnt from my mistakes
    Code:java
    1. import org.bukkit.Material;
    2. import org.bukkit.configuration.file.FileConfiguration;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.block.Action;
    7. import org.bukkit.event.player.PlayerInteractEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10.  
    11. public class CMD extends JavaPlugin implements Listener{
    12.  
    13.  
    14. public void onEnable() {
    15. getServer().getPluginManager().registerEvents(this, this);
    16. FileConfiguration config = getConfig();
    17. /*****************************************************/
    18. config.addDefault("Item1.Boolean", false);
    19. config.addDefault("Item1.Material", "AIR");
    20. config.addDefault("Item1.Permission", "Cmd.1");
    21. config.addDefault("Item1.Command1", "/Command");
    22. /*****************************************************/
    23. config.addDefault("Item2.Boolean", false);
    24. config.addDefault("Item2.Material", "AIR");
    25. config.addDefault("Item2.Permission", "Cmd.1");
    26. config.addDefault("Item2.Command1", "/Command");
    27. /*****************************************************/
    28. config.addDefault("Item3.Boolean", false);
    29. config.addDefault("Item3.Material", "AIR");
    30. config.addDefault("Item3.Permission", "Cmd.1");
    31. config.addDefault("Item3.Command1", "/Command");
    32. /*****************************************************/
    33. config.addDefault("Item4.Boolean", false);
    34. config.addDefault("Item4.Material", "AIR");
    35. config.addDefault("Item4.Permission", "Cmd.1");
    36. config.addDefault("Item4.Command1", "/Command");
    37. /*****************************************************/
    38. config.addDefault("Item5.Boolean", false);
    39. config.addDefault("Item5.Material", "AIR");
    40. config.addDefault("Item5.Permission", "Cmd.1");
    41. config.addDefault("Item5.Command1", "/Command");
    42. /*****************************************************/
    43. config.options().copyDefaults(true);
    44. saveConfig();
    45. }
    46. @EventHandler
    47. public void PlayerInteract(PlayerInteractEvent event) {
    48. FileConfiguration config = getConfig();
    49. final Player p = event.getPlayer();
    50. boolean ClickBlock = event.getAction().equals(Action.RIGHT_CLICK_BLOCK);
    51. boolean ClickAir = event.getAction().equals(Action.RIGHT_CLICK_AIR);
    52. /*****************************************************/
    53. if(p.hasPermission(config.getString("Item1.Permission")) && ClickAir || ClickBlock && config.getBoolean("Item1.Boolean")==true){
    54. if (p.getItemInHand().getType().equals(Material.getMaterial(config.getString("Item1.Material")))){
    55. p.chat(config.getString("Item1.Command1"));
    56. } }
    57. /*****************************************************/
    58. if(p.hasPermission(config.getString("Item2.Permission")) && ClickAir || ClickBlock && config.getBoolean("Item2.Boolean")==true){
    59. if (p.getItemInHand().getType().equals(Material.getMaterial(config.getString("Item2.Material")))){
    60. p.chat(config.getString("Item2.Command1"));
    61. } }
    62. /*****************************************************/
    63. if(p.hasPermission(config.getString("Item3.Permission")) && ClickAir || ClickBlock && config.getBoolean("Item3.Boolean")==true){
    64. if (p.getItemInHand().getType().equals(Material.getMaterial(config.getString("Item3.Material")))){
    65. p.chat(config.getString("Item3.Command1"));
    66. } }
    67. /*****************************************************/
    68. if(p.hasPermission(config.getString("Item4.Permission")) && ClickAir || ClickBlock && config.getBoolean("Item4.Boolean")==true){
    69. if (p.getItemInHand().getType().equals(Material.getMaterial(config.getString("Item4.Material")))){
    70. p.chat(config.getString("Item4.Command1"));
    71. } }
    72. /*****************************************************/
    73. if(p.hasPermission(config.getString("Item5.Permission")) && ClickAir || ClickBlock && config.getBoolean("Item5.Boolean")==true){
    74. if (p.getItemInHand().getType().equals(Material.getMaterial(config.getString("Item5.Material")))){
    75. p.chat(config.getString("Item5.Command1"));
    76. } }
    77. /*****************************************************/
    78. config.options().copyDefaults(true);
    79. saveConfig();
    80. } }

    Item names that can be used are found here http://jd.bukkit.org/rb/apidocs/org/bukkit/Material.html
     
  9. Offline

    ifraaank

    thomasoo Thanks! I'll try it out for sure!
     
  10. Offline

    bartboy8

  11. Offline

    ifraaank

    Thank you for your time bartboy8! :) I appreciate it!
     
  12. Offline

    ifraaank

    Does it not apply for everyone on the server? In this case, what's the permission then? :)
     

Share This Page