org.bukkit.event.entity.EntityTameEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityTameEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TamingTaskType.java    From Quests with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTame(EntityTameEvent event) {
    if (!(event.getOwner() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getOwner();

    QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

    for (Quest quest : super.getRegisteredQuests()) {
        if (questProgressFile.hasStartedQuest(quest)) {
            QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

            for (Task task : quest.getTasksOfType(super.getType())) {
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                if (taskProgress.isCompleted()) {
                    continue;
                }

                int tamesNeeded = (int) task.getConfigValue("amount");

                int progressTamed;
                if (taskProgress.getProgress() == null) {
                    progressTamed = 0;
                } else {
                    progressTamed = (int) taskProgress.getProgress();
                }

                taskProgress.setProgress(progressTamed + 1);

                if (((int) taskProgress.getProgress()) >= tamesNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
 
Example #2
Source File: TameEvent.java    From StackMob-3 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onTame(EntityTameEvent event) {
    Entity entity = event.getEntity();
    if(StackTools.hasValidStackData(entity)){
        int stackSize = StackTools.getSize(entity);
        if(stackSize > 1){
            Entity dupe = sm.getTools().duplicate(entity);
            StackTools.setSize(dupe, stackSize - 1);
        }
        StackTools.removeSize(entity);
    }
}
 
Example #3
Source File: ExprTamer.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	if (!ScriptLoader.isCurrentEvent(EntityTameEvent.class)) {
		Skript.error("the expression 'tamer' may only be used in the entity tame event.");
		return false;
	}
	return true;
}
 
Example #4
Source File: TameObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onTaming(EntityTameEvent event) {
    if (event.getOwner() instanceof Player) {
        String playerID = PlayerConverter.getID((Player) event.getOwner());
        if (!dataMap.containsKey(playerID)) {
            return;
        }
        LivingEntity entity = event.getEntity();
        TameData playerData = (TameData) dataMap.get(playerID);
        switch (type) {
            case WOLF:
                if (entity.getType().equals(EntityType.WOLF) && checkConditions(playerID)) {
                    playerData.subtract();
                }
                break;
            case OCELOT:
                if (entity.getType().equals(EntityType.OCELOT) && checkConditions(playerID)) {
                    playerData.subtract();
                }
                break;
            case HORSE:
                if (entity.getType().equals(EntityType.HORSE) && checkConditions(playerID)) {
                    playerData.subtract();
                }
                break;
            default:
                break;
        }
        if (playerData.isZero()) {
            completeObjective(playerID);
        }
    }
}
 
Example #5
Source File: ExprTamer.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Player[] get(final Event e) {
	return new Player[] {((EntityTameEvent) e).getOwner() instanceof Player ? (Player) ((EntityTameEvent) e).getOwner() : null};
}