[Guide] How to perform an action right clicking just one side of one block.

Discussion in 'Programming' started by KCVault, Feb 14, 2018.

Thread Status:
Not open for further replies.
  1. Note: This is designed like an annotation, just like a guide for me and for all.
    How to do, when you perform an action in just one face on one block.
    The code is like this:
    Code (Java):
    package com.zjar84;

    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;

    public class PluginListener implements Listener {

        @EventHandler
        public void onBreakBlock(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if(e.getBlockFace()==BlockFace.UP){
                if(e.getAction()==Action.RIGHT_CLICK_BLOCK){
                    if(p.getInventory().getItemInMainHand().getType() == Material.DIAMOND_HOE){
                        p.sendMessage("yop");
                    }
                    else{
                        p.sendMessage("nop");
                    }
                }
            }
            }
        }
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.

Share This Page