当前位置: 首页>>代码示例>>Java>>正文


Java Villager.hasMetadata方法代码示例

本文整理汇总了Java中org.bukkit.entity.Villager.hasMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java Villager.hasMetadata方法的具体用法?Java Villager.hasMetadata怎么用?Java Villager.hasMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.entity.Villager的用法示例。


在下文中一共展示了Villager.hasMetadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onVillagerInteract

import org.bukkit.entity.Villager; //导入方法依赖的package包/类
@EventHandler
public void onVillagerInteract(PlayerInteractEntityEvent event) { 
	if(event.getRightClicked() instanceof Villager) {
		Villager villager = (Villager) event.getRightClicked();
		if(villager.hasMetadata("cancel")) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:Lilmac12312,项目名称:cNoHacks,代码行数:10,代码来源:ForceField.java

示例2: onEntityInteract

import org.bukkit.entity.Villager; //导入方法依赖的package包/类
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
void onEntityInteract(PlayerInteractEntityEvent event) {
	if (!(event.getRightClicked() instanceof Villager)) return;
	Villager villager = (Villager) event.getRightClicked();

	if (plugin.isShopkeeper(villager)) return; // shopkeeper interaction is handled elsewhere
	Log.debug("Interaction with Non-shopkeeper villager ..");

	if (villager.hasMetadata("NPC")) {
		// ignore any interaction with citizens2 NPCs
		Log.debug("  ignoring (probably citizens2) NPC");
		return;
	}

	if (Settings.disableOtherVillagers) {
		// don't allow trading with other villagers
		event.setCancelled(true);
		Log.debug("  trade prevented");
	}

	// only trigger hiring for main-hand events:
	if (!NMSManager.getProvider().isMainHandInteraction(event)) return;

	if (Settings.hireOtherVillagers) {
		Player player = event.getPlayer();
		// allow hiring of other villagers
		Log.debug("  possible hire ..");
		if (this.handleHireOtherVillager(player, villager)) {
			// hiring was successful -> prevent normal trading
			Log.debug("    ..success (normal trading prevented)");
			event.setCancelled(true);
		} else {
			// hiring was not successful -> no preventing of normal villager trading
			Log.debug("    ..failed");
		}
	}
}
 
开发者ID:nisovin,项目名称:Shopkeepers,代码行数:38,代码来源:VillagerInteractionListener.java


注:本文中的org.bukkit.entity.Villager.hasMetadata方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。