RIGHT_CLICK_BLOCK Event

Discussion in 'Plugin Development' started by thatdubstepgamer, Sep 15, 2013.

Thread Status:
Not open for further replies.
  1. I came on here because I cant figure out how to when I right click a chest it instead of in the top left corner of the chest be "Chest" I want to change it to "Shop" heres my code.
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract1(PlayerInteractEvent event){
    3.  
    4. Player player = event.getPlayer();
    5. if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    6.  
    7. }
    8. }
     
  2. thatdubstepgamer
    Code:
    if(event.getClickedBlock().getType() == Material.CHEST)
        event.getPlayer().openInventory(Bukkit.createInventory(null, 45, "Shop"));
     
  3. It did not work for me

    Heres my code
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract1(PlayerInteractEvent event){
    3.  
    4. if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    5.  
    6. if(event.getClickedBlock().getType() == Material.CHEST)
    7. event.getPlayer().openInventory(Bukkit.createInventory(null, 45, "Shop"));
    8. }}


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. thatdubstepgamer
    cancel the event with event.setCancelled(true), then use the openInventory method. Also make sure you've registered your events.
     
  5. Thanks btw how do I make it so I can add material to the shop?

    Also do you have skype???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. thatdubstepgamer
    1. Make a new Inventory variable, then add items in it, and use the openInventory method.
    Code:
    Inventory inv = Bukkit.createInventory(null, 45, "Shop");
    inv.addItem(new ItemStack(Material.COOKIE));
    event.getPlayer().openInventory(inv);
    2. Yes, pm me your username if you want.
     
  7. Offline

    JPG2000

    Assist Instead of adding items, I like inv.setItem, because you can choose the slot #.
     
  8. Offline

    WauloK

    JPG2000 Why does your sig have two } ? :)
     
Thread Status:
Not open for further replies.

Share This Page