Java源码示例:org.bukkit.event.entity.EntityInteractEvent

示例1
@EventHandler
public void onEntityInteract(EntityInteractEvent event) {
  if (!(event.getEntity() instanceof Player)) {
    return;
  }

  if (event.getBlock().getType() != Material.SOIL
      && event.getBlock().getType() != Material.WHEAT) {
    return;
  }

  Player player = (Player) event.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() == GameState.WAITING) {
    event.setCancelled(true);
  }
}
 
示例2
@EventHandler
public void entityInteract(EntityInteractEvent event) {
    Block block = event.getBlock();

    Protection protection = plugin.getLWC().findProtection(block.getLocation());

    if (protection != null) {
        boolean allowEntityInteract = Boolean
                .parseBoolean(plugin.getLWC().resolveProtectionConfiguration(block, "allowEntityInteract"));

        if (!allowEntityInteract) {
            event.setCancelled(true);
        }
    }
}
 
示例3
@EventHandler(priority = EventPriority.NORMAL)
public void OnEntityInteractEvent(EntityInteractEvent event) {
	if (event.getBlock() != null) {			
		if (CivSettings.switchItems.contains(event.getBlock().getType())) {
			coord.setFromLocation(event.getBlock().getLocation());
			TownChunk tc = CivGlobal.getTownChunk(coord);

			if (tc == null) {
				return;
			}

			/* A non-player entity is trying to trigger something, if interact permission is
			 * off for others then disallow it.
			 */
			if (tc.perms.interact.isPermitOthers()) {
				return;
			}

			if (event.getEntity() instanceof Player) {
				CivMessage.sendErrorNoRepeat((Player)event.getEntity(), "You do not have permission to interact here...");
			}

			event.setCancelled(true);
		}
	}

}
 
示例4
@Test
public void shouldHandleSimpleEvents() {
    withServiceMock(listenerService)
        .check(listener::onFoodLevelChange, FoodLevelChangeEvent.class)
        .check(listener::onShoot, EntityShootBowEvent.class)
        .check(listener::onEntityInteract, EntityInteractEvent.class)
        .check(listener::onLowestEntityInteract, EntityInteractEvent.class);
}
 
示例5
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityInteractEvent(EntityInteractEvent event) {
}
 
示例6
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onProjectileHit(EntityInteractEvent e) {
    if (e.getEntity() == null || !(e.getEntity() instanceof Projectile)) {
        return;
    }
    Projectile p = (Projectile)e.getEntity();
    if (p.getShooter() != null && p.getShooter() instanceof Player && e.getBlock() != null) {
        Player player = (Player)p.getShooter();
        if (!inWorld(player)
                || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")
                || plugin.getGrid().playerIsOnIsland(player)) {
            return;
        }
        Island island = plugin.getGrid().getProtectedIslandAt(e.getBlock().getLocation());
        switch(e.getBlock().getType()) {
        case WOOD_BUTTON:
        case STONE_BUTTON:
            if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.LEVER_BUTTON))) {
                return;
            }
            if (island != null && island.getIgsFlag(SettingsFlag.LEVER_BUTTON)) {
                return;
            }
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandProtected);
            e.setCancelled(true);
            break;
        case WOOD_PLATE:
        case STONE_PLATE:
        case GOLD_PLATE:
        case IRON_PLATE:
            // Pressure plates
            if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PRESSURE_PLATE))) {
                return;
            }
            if (island != null && island.getIgsFlag(SettingsFlag.PRESSURE_PLATE)) {
                return;
            }
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandProtected);
            e.setCancelled(true);
            break;
        default:
            break;
        }
    }
}
 
示例7
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onEntityInteract(EntityInteractEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}
 
示例8
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onLowestEntityInteract(EntityInteractEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}