// Path: src/main/java/com/nisovin/shopkeepers/compat/NMSManager.java
// public final class NMSManager {
// 
// 	private static NMSCallProvider provider;
// 
// 	public static NMSCallProvider getProvider() {
// 		return NMSManager.provider;
// 	}
// 
// 	public static void load(Plugin plugin) {
// 		final String packageName = plugin.getServer().getClass().getPackage().getName();
// 		String cbversion = packageName.substring(packageName.lastIndexOf('.') + 1);
// 		try {
// 			final Class<?> clazz = Class.forName("com.nisovin.shopkeepers.compat." + cbversion + ".NMSHandler");
// 			if (NMSCallProvider.class.isAssignableFrom(clazz)) {
// 				NMSManager.provider = (NMSCallProvider) clazz.getConstructor().newInstance();
// 			} else {
// 				throw new Exception("Nope");
// 			}
// 		} catch (final Exception e) {
// 			Log.severe("Potentially incompatible server version: " + cbversion);
// 			Log.severe("Shopkeepers is trying to run in 'compatibility mode'.");
// 			Log.info("Check for updates at: " + plugin.getDescription().getWebsite());
// 
// 			try {
// 				NMSManager.provider = new FailedHandler();
// 			} catch (Exception e_u) {
// 				// uncomment for debugging:
// 				// e_u.printStackTrace();
// 			}
// 		}
// 	}
// }


import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.nisovin.shopkeepers.compat.NMSManager;
package com.nisovin.shopkeepers;




class VillagerInteractionListener implements Listener {

	private final ShopkeepersPlugin plugin;

	VillagerInteractionListener(ShopkeepersPlugin plugin) {
		this.plugin = plugin;
	}

	@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:
// Path: src/main/java/com/nisovin/shopkeepers/compat/NMSManager.java
// public final class NMSManager {
// 
// 	private static NMSCallProvider provider;
// 
// 	public static NMSCallProvider getProvider() {
// 		return NMSManager.provider;
// 	}
// 
// 	public static void load(Plugin plugin) {
// 		final String packageName = plugin.getServer().getClass().getPackage().getName();
// 		String cbversion = packageName.substring(packageName.lastIndexOf('.') + 1);
// 		try {
// 			final Class<?> clazz = Class.forName("com.nisovin.shopkeepers.compat." + cbversion + ".NMSHandler");
// 			if (NMSCallProvider.class.isAssignableFrom(clazz)) {
// 				NMSManager.provider = (NMSCallProvider) clazz.getConstructor().newInstance();
// 			} else {
// 				throw new Exception("Nope");
// 			}
// 		} catch (final Exception e) {
// 			Log.severe("Potentially incompatible server version: " + cbversion);
// 			Log.severe("Shopkeepers is trying to run in 'compatibility mode'.");
// 			Log.info("Check for updates at: " + plugin.getDescription().getWebsite());
// 
// 			try {
// 				NMSManager.provider = new FailedHandler();
// 			} catch (Exception e_u) {
// 				// uncomment for debugging:
// 				// e_u.printStackTrace();
// 			}
// 		}
// 	}
// }


// Path: src/main/java/com/nisovin/shopkeepers/VillagerInteractionListener.java
import java.util.Map;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.nisovin.shopkeepers.compat.NMSManager;

package com.nisovin.shopkeepers;




class VillagerInteractionListener implements Listener {

	private final ShopkeepersPlugin plugin;

	VillagerInteractionListener(ShopkeepersPlugin plugin) {
		this.plugin = plugin;
	}

	@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;