use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CommandCitizenInfo method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizenData.getId(), citizenData.getName()), true);
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
final BlockPos citizenPosition = entityCitizen.blockPosition();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ()), true);
final BlockPos homePosition = entityCitizen.getRestrictCenter();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.homepos", homePosition.getX(), homePosition.getY(), homePosition.getZ()), true);
if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.workposnull"), true);
} else {
final BlockPos workingPosition = entityCitizen.getCitizenColonyHandler().getWorkBuilding().getPosition();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.workpos", workingPosition.getX(), workingPosition.getY(), workingPosition.getZ()), true);
}
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.health", entityCitizen.getHealth(), entityCitizen.getMaxHealth()), true);
Object[] skills = new Object[] { citizenData.getCitizenSkillHandler().getSkills().get(Skill.Athletics).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Dexterity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Strength).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Agility).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Stamina).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Mana).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Adaptability).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Focus).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Creativity).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Knowledge).getA(), citizenData.getCitizenSkillHandler().getSkills().get(Skill.Intelligence).getA() };
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.skills", skills), true);
if (entityCitizen.getCitizenJobHandler().getColonyJob() == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.jobnull"), true);
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.noactivity"), true);
} else if (entityCitizen.getCitizenColonyHandler().getWorkBuilding() != null && entityCitizen.getCitizenColonyHandler().getWorkBuilding().hasModule(WorkerBuildingModule.class)) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.job", entityCitizen.getCitizenColonyHandler().getWorkBuilding().getFirstModuleOccurance(WorkerBuildingModule.class).getJobEntry().getTranslationKey()), true);
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.activity", entityCitizen.getDesiredActivity(), entityCitizen.getCitizenJobHandler().getColonyJob().getNameTagDescription(), entityCitizen.goalSelector.getRunningGoals().findFirst().get().getGoal().toString()), true);
}
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CommandCitizenKill method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
if (!context.getSource().hasPermission(OP_PERM_LEVEL) && !MineColonies.getConfig().getServer().canPlayerUseKillCitizensCommand.get()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.notenabledinconfig"), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizenData.getId(), citizenData.getName()), true);
final BlockPos position = optionalEntityCitizen.get().blockPosition();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", position.getX(), position.getY(), position.getZ()), true);
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizenkill.success", position.getX(), position.getY(), position.getZ()), true);
optionalEntityCitizen.get().die(CONSOLE_DAMAGE_SOURCE);
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CommandCitizenTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
}
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class CommandCitizenTriggerWalkTo method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
final ILocationArgument targetLocation = Vec3Argument.getCoordinates(context, POS_ARG);
final BlockPos targetPos = targetLocation.getBlockPos(context.getSource());
if (context.getSource().getLevel() == entityCitizen.level) {
if (entityCitizen instanceof EntityCitizen && entityCitizen.getCitizenJobHandler().getColonyJob() != null) {
final AbstractEntityAIBasic basic = ((AbstractEntityAIBasic) entityCitizen.getCitizenJobHandler().getColonyJob().getWorkerAI());
basic.setWalkTo(targetPos);
basic.registerTarget(new AIOneTimeEventTarget(AIWorkerState.WALK_TO));
} else {
entityCitizen.getNavigation().moveTo(targetPos.getX(), targetPos.getY(), targetPos.getZ(), 1f);
}
}
return 1;
}
use of com.minecolonies.api.entity.citizen.AbstractEntityCitizen in project minecolonies by ldtteam.
the class RecallCitizenHutMessage method onExecute.
@Override
protected void onExecute(@NotNull final NetworkEvent.Context ctxIn, final boolean isLogicalServer, @NotNull final IColony colony, @NotNull final IBuilding building) {
final BlockPos location = building.getPosition();
final World world = colony.getWorld();
for (final ICitizenData citizenData : building.getAllAssignedCitizen()) {
Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
citizenData.setNextRespawnPosition(EntityUtils.getSpawnPoint(world, location));
citizenData.updateEntityIfNecessary();
optionalEntityCitizen = citizenData.getEntity();
}
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), world, location)) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
}
}
}
Aggregations