On Right Clicks

Discussion in 'Plugin Development' started by KeybordPiano459, Jul 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    KeybordPiano459

    Is there a way to make it so that when I right click on an item in my hotbar, it performs a command?
     
  2. Offline

    sayaad

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event){
    3. if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR){
    4. Player player = event.getPlayer();
    5. if(player.getItemInHand() == YourItemStack){
    6. player.getServer().dispatchCommand(player.getServer().getConsoleSender(), "command");
    7. //awdhuahdaoifhaifos
    8. }
    9. }
    10. }else{
    11. if(event.getAction() == Action.PHYSICAL){
    12. /*
    13. Ass-pressure
    14. */
    15. }
     
  3. Offline

    ZachBora

    No unless you use Spout. Nothing is sent to the server when you right-click items on your client with the normal client.
     
  4. Offline

    Firefly

  5. Offline

    KeybordPiano459

    Sorry, I just started java two days ago, what would the code be like to make this perform a command?
     
  6. Offline

    Firefly

    Are you looking to execute code when someone right clicks with an item in hand, or when they physically take their mouse cursor and click their hotbar?
     
  7. Offline

    sayaad

    Code:java
    1. player.getServer().dispatchCommand(player.getServer().getConsoleSender(), "command");

    Look at the full code I gave you >.>
     
  8. Offline

    ZachBora

  9. Offline

    Adben

    I tried using this code, but I got some errors.
     
  10. Offline

    pd9937

    I feel like it's not clear what you want. Firefly thinks you want to perform a command when you right click an item while the inventory is opened, Sayaad thinks you want to perform the command when you right click a block in the environment (without having the inventory opened).

    So what did you mean exactly?
     
  11. Offline

    KeybordPiano459

    I team with him for developing, he was saying that he got three errors when he used this code, it may have been where we put it.
     
  12. Offline

    pd9937

  13. Offline

    Adben

  14. Offline

    Firefly

    You copy and pasted the code. I bet the variable "YourItemstack" doesn't exist in your code. If you're going to copy/paste code, at least do it intelligently and change variable names, etc to suit what you already have. Also /command isn't a command. You need to change that to whatever the command you need to be executed is.
     
    kroltan likes this.
  15. Offline

    Father Of Time

    Am I the only one who feels that one question is being asked, yet the answer to a different question is being given?

    Question: Hey... What direction should we go?
    Answer: Purple!

    As pointed out by Firefly (absolutely love the name btw, best series ever), cutting and pasting is a horrible habbit to form because you gain no understanding of the functionality of the code you are being provided.

    Even when I recieve code samples by other users I always make sure to re-type it into my project, evaluating each like that I type with "why is this in here, what is it adding to the project", and if at any point the answer to that question is "I don't know" you need to inquire; because either it's necessary and you need to know what it does, or it's unecessary and you can cut out some additional overhead.

    I don't think anyone expects you to know everything as a novice programmer, but a lot of us do expect you to ask questions when you don't know the answers; otherwise we are just programming your plug-ins for you, and you leave the conversation with nothing other than a half completed plugin that you are incapible of supporting.

    [​IMG]
     
    ZachBora, GRPGamer, kroltan and 6 others like this.
  16. Offline

    Firefly

    Father Of Time likes this.
  17. Offline

    ItsHarry

    My advise would simply be learn Java first THEN code plugins.
     
    kroltan and ZachBora like this.
  18. Offline

    ZachBora

    Exactly.
    One does not simply make a bukkit plugin.
     
    Icyene, kroltan, sayaad and 4 others like this.
  19. Well said, but I learned java by making very easy plugins. I also made non-minecraft projects, but I learned most from making easy to make plugins.
     
Thread Status:
Not open for further replies.

Share This Page