本文整理汇总了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);
}
}
}
示例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");
}
}
}