Farmland

Discussion in 'Plugin Development' started by BukkitPlaysMC, Jun 17, 2017.

  1. BukkitPlaysMC

    BukkitPlaysMC New Member

    Apr 26, 2017
    3
    0
    1
    Male
    How can I cancel the breaking of farmland if a player jumps on it? I already tried it with BlockBreakEvent. But it's not called
     
  2. xISRAPILx

    xISRAPILx New Member

    PlayerInteractEvent
    Action: PHYSICAL
     
  3. Eater

    Eater Member

    Aug 14, 2017
    37
    1
    8
    As xISRAPILx said, you can use a playerinteractevent with action PHYSICAL. Here's some full code:

    Code:
    public class Farmland extends PluginBase implements Listener{
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(this, this);
        }
      
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            if (event.getAction() == Action.PHYSICAL) {
               event.setCanceled(true);
            }
        }
    }