Solved When right click item do /buy help.

Discussion in 'Plugin Development' started by BeastCraft3, May 9, 2014.

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

    BeastCraft3

    Greetings me again, I've tried to find a tutorial on how to make a item do /buy when you press it, but I cant find any tutorials or forums post on how to do it. I've tried to do find this out for ages but now I've given up. Please anyone help me. And if people are wondering why I posted to threads within a hour its only because I got tired of trying to find out those problems. But please help me with this one.
    Code so far:
    Code:java
    1. package me.BeastCraft3.inventorygui;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerDropItemEvent;
    12. import org.bukkit.event.player.PlayerInteractEvent;
    13. import org.bukkit.event.player.PlayerJoinEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16.  
    17. public class donate implements Listener {
    18.  
    19. public Main plugin;
    20.  
    21.  
    22. ItemStack diamond = new ItemStack(Material.DIAMOND);{
    23. ItemMeta diamondmeta = diamond.getItemMeta();
    24. ArrayList<String> cc = new ArrayList<String>();
    25. diamondmeta.setDisplayName(ChatColor.YELLOW + "Donation Ranks");
    26. cc.add(ChatColor.GRAY + "View our donator packages");
    27. diamondmeta.setLore(cc);
    28. diamond.setItemMeta(diamondmeta);
    29. }
    30.  
    31. @EventHandler
    32. public void onPd(PlayerDropItemEvent e) {
    33. Player p = e.getPlayer();
    34.  
    35. if (e.getItemDrop().getItemStack().getType().equals(Material.DIAMOND)) {
    36. p.sendMessage(String.format("%sError: %sYou are not Allowed to drop that item!", ChatColor.RED, ChatColor.DARK_RED));
    37. e.setCancelled(true);
    38. }
    39.  
    40.  
    41. }
    42.  
    43. @EventHandler
    44. public void OnPlayerJoin(PlayerJoinEvent e){
    45.  
    46. if(!(e.getPlayer().hasPlayedBefore())){
    47. e.getPlayer().getInventory().addItem(new ItemStack(diamond));
    48. }
    49. }
    50.  
    51.  
    52. @EventHandler
    53. public void onPlayerInteract(PlayerInteractEvent event) {
    54. Action a = event.getAction();
    55. ItemStack is = event.getItem();
    56.  
    57. if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
    58. return;
    59. }
    60.  
    61. }
    62.  
     
  2. Offline

    OrangeGuy

    Not sure you means this.. Meh.. Hope this help!
    Code:java
    1. private void playerRunCommand(Player p, String cmd)
    2. {
    3. p.chat(cmd);
    4. }
     
  3. Offline

    BeastCraft3

    This is what Im trying to explain: When you right click the diamond it will execute the command /buy from buycraft
    Hope my english isnt that bad :p
     
  4. Offline

    OrangeGuy

    And you should do this:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Action a = event.getAction();
    4. ItemStack is = event.getItem();
    5.  
    6. if (a == Action.RIGHT_CLICK_AIR && is != null && is.getType() != Material.AIR)
    7. p.chat("/buy")
    8. }


    EDIT: Oh it should be /buy Meh..
     
  5. Offline

    Konkz

    BeastCraft3 He told you the answer.
    PHP:
    p.chat("/help");
    EDIT: Wow, ninja'd again. ;L
     
  6. Offline

    SainttX

    BeastCraft3 Would look something like this:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. Action a = event.getAction();
    4. ItemStack is = event.getItem();
    5. if (a != Action.PHYSICAL && is != null) {
    6. if (is.getType() == Material.ARROW) { // Whatever material/criteria you have for the item
    7. Bukkit.dispatchCommand(event.getPlayer(), "buy");
    8. }
    9. }
    10. }


    Edit: the ninja is real
     
  7. Offline

    ChunkMe

    It is really really simple to do!
    Try this thing:
    Code:java
    1. @EventHandler
    2. public void interact1(PlayerInteractEvent e){
    3. if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;
    4. if (!(e.getItem().getType() == Material.DIAMOND)) return;
    5. Player p = e.getPlayer;
    6. p.performCommand("buy");
    7. }
     
Thread Status:
Not open for further replies.

Share This Page