*/
private boolean interactWithVillager(Player player, Entity entity) {
boolean cancelEvent = false;
ItemStack stack = player.getItemInHand();
Material material = stack.getType();
Villager villager = (Villager) entity;
UUID id = villager.getUniqueId();
WorkerInfo info = workerStack.get(id);
boolean reassign = true;
if (info != null) {
if (!player.hasPermission("usefulvillagers.give")) {
player.sendMessage(NO_GIVE_PERMISSION_MESSAGE);
return cancelEvent;
}
cancelEvent = give(info, player, stack, material);
reassign = !cancelEvent;
}
if (reassign) {
WorkerCreator creator = PROFESSION_TRIGGER.get(material);
if (creator != null) {
Villager.Profession profession = creator.getProfession();
if ((profession != null)
&& (!(profession.equals(villager.getProfession()) && (info != null)))) {
// It's ok, we can convert it !
if (!player.hasPermission(creator.getPermission())) {
player.sendMessage(NO_JOB_PERMISSION_MESSAGE);
return cancelEvent;
}
villager.setProfession(profession);
info = creator.create();
info.setConfiguration(configurationHandler);
workerStack.put(id, info);
player.sendMessage(creator.getMessage());
cancelEvent = true;