use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method onRequestCancelled.
@Nullable
@Override
public IRequest<?> onRequestCancelled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
if (!manager.getColony().getWorld().isRemote) {
final Colony colony = (Colony) manager.getColony();
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof JobDeliveryman && ((JobDeliveryman) c.getJob()).getTaskQueue().contains(request.getToken())).findFirst().orElse(null);
if (freeDeliveryMan == null) {
MineColonies.getLogger().error("Parent cancellation failed! Unknown request: " + request.getToken());
} else {
final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
job.onTaskDeletion(request.getToken());
}
}
return null;
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class CitizenInfoCommand method executeSpecializedCode.
@Override
public void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
final CitizenData citizenData = colony.getCitizenManager().getCitizen(citizenId);
sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
final Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
if (!optionalEntityCitizen.isPresent()) {
sender.sendMessage(new TextComponentTranslation(CITIZEN_NOT_LOADED));
return;
}
final EntityCitizen entityCitizen = optionalEntityCitizen.get();
final BlockPos citizenPosition = entityCitizen.getPosition();
sender.sendMessage(new TextComponentString(String.format(CITIZEN_POSITION, citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ())));
final BlockPos homePosition = entityCitizen.getHomePosition();
sender.sendMessage(new TextComponentString(String.format(CITIZEN_HOME_POSITION, homePosition.getX(), homePosition.getY(), homePosition.getZ())));
if (entityCitizen.getWorkBuilding() == null) {
sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION_NULL)));
} else {
final BlockPos workingPosition = entityCitizen.getWorkBuilding().getLocation();
sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION, workingPosition.getX(), workingPosition.getY(), workingPosition.getZ())));
}
sender.sendMessage(new TextComponentString(String.format(CITIZEN_HEALTH, entityCitizen.getHealth(), entityCitizen.getMaxHealth())));
sender.sendMessage(new TextComponentString(String.format(CITIZEN_LEVEL_AND_AGE, entityCitizen.getLevel(), entityCitizen.getGrowingAge(), citizenData.getLevel())));
sender.sendMessage(new TextComponentString(String.format(CITIZEN_SKILLS, citizenData.getCharisma(), citizenData.getDexterity(), citizenData.getEndurance(), citizenData.getIntelligence(), citizenData.getStrength())));
if (entityCitizen.getColonyJob() == null) {
sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB_NULL)));
sender.sendMessage(new TextComponentString(String.format(CITIZEN_NO_ACTIVITY)));
} else if (entityCitizen.getWorkBuilding() != null) {
sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB, entityCitizen.getWorkBuilding().getJobName())));
sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESIRED_ACTIVITY, entityCitizen.getDesiredActivity(), entityCitizen.getColonyJob().getNameTagDescription())));
}
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class RespawnCitizenCommand method executeSpecializedCode.
@Override
public void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
final CitizenData citizenData = colony.getCitizenManager().getCitizen(citizenId);
final Optional<EntityCitizen> optionalEntityCitizen = citizenData.getCitizenEntity();
sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
if (!optionalEntityCitizen.isPresent()) {
citizenData.updateCitizenEntityIfNecessary();
}
final EntityCitizen entityCitizen = citizenData.getCitizenEntity().get();
final BlockPos position = entityCitizen.getPosition();
sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
sender.sendMessage(new TextComponentString(REMOVED_MESSAGE));
Log.getLogger().info("client? " + sender.getEntityWorld().isRemote);
server.addScheduledTask(entityCitizen::setDead);
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class CommandEntryPointTest method setUp.
@Before
public void setUp() {
final Colony colony1 = mock(Colony.class);
when(colony1.getID()).thenReturn(1);
final Colony colony2 = mock(Colony.class);
when(colony2.getID()).thenReturn(2);
@SuppressWarnings("unchecked") final List<Colony> colonyList = Arrays.asList(new Colony[] { colony1, colony2 });
final ICitizenManager citizenManager1 = mock(ICitizenManager.class);
when(colony1.getCitizenManager()).thenReturn(citizenManager1);
final ICitizenManager citizenManager2 = mock(ICitizenManager.class);
when(colony2.getCitizenManager()).thenReturn(citizenManager2);
final List<CitizenData> citizenDataList1 = new ArrayList<>();
when(citizenManager1.getCitizens()).thenReturn(citizenDataList1);
final CitizenData citizenJohnSSmith = mock(CitizenData.class);
when(citizenJohnSSmith.getId()).thenReturn(1);
when(citizenJohnSSmith.getName()).thenReturn("John S. Smith");
citizenDataList1.add(citizenJohnSSmith);
when(citizenManager1.getCitizen(1)).thenReturn(citizenJohnSSmith);
final CitizenData citizenJohnSJones = mock(CitizenData.class);
when(citizenJohnSJones.getId()).thenReturn(4);
when(citizenJohnSJones.getName()).thenReturn("John S. Jones");
citizenDataList1.add(citizenJohnSJones);
when(citizenManager1.getCitizen(4)).thenReturn(citizenJohnSJones);
final CitizenData citizenJohnAJones = mock(CitizenData.class);
when(citizenJohnAJones.getId()).thenReturn(2);
when(citizenJohnAJones.getName()).thenReturn("John A. Jones");
citizenDataList1.add(citizenJohnAJones);
when(citizenManager1.getCitizen(2)).thenReturn(citizenJohnAJones);
final CitizenData citizenJennaQBar = mock(CitizenData.class);
when(citizenJennaQBar.getId()).thenReturn(3);
when(citizenJennaQBar.getName()).thenReturn("Jenna Q. Bar");
citizenDataList1.add(citizenJennaQBar);
when(citizenManager1.getCitizen(3)).thenReturn(citizenJennaQBar);
PowerMockito.mockStatic(ColonyManager.class);
BDDMockito.given(ColonyManager.getColonies()).willReturn(colonyList);
BDDMockito.given(ColonyManager.getColony(1)).willReturn(colony1);
BDDMockito.given(ColonyManager.getColony(2)).willReturn(colony2);
PowerMockito.mockStatic(PermissionAPI.class);
BDDMockito.given(PermissionAPI.hasPermission(any(), any())).willReturn(true);
final EntityPlayerMP playerBob = mock(EntityPlayerMP.class);
when(playerBob.getName()).thenReturn("Bob");
final EntityPlayerMP playerSally = mock(EntityPlayerMP.class);
when(playerSally.getName()).thenReturn("Sally");
final PlayerList serverPlayerList = mock(PlayerList.class);
when(serverPlayerList.getPlayerByUsername("Bob")).thenReturn(playerBob);
when(serverPlayerList.getPlayerByUsername("Sally")).thenReturn(playerSally);
server = mock(MinecraftServer.class);
when(server.getOnlinePlayerNames()).thenReturn(new String[] { "Bob", "Sally" });
when(server.getPlayerList()).thenReturn(serverPlayerList);
sender = mock(MinecraftServer.class);
instance = new CommandEntryPointNew();
pos = new BlockPos(1, 2, 3);
}
Aggregations