use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CitizenData method generateName.
/**
* Generates a random name considering both parent names.
*
* @param rand Random object.
*/
public void generateName(@NotNull final Random rand, final String firstParentName, final String secondParentName) {
String nameA = firstParentName;
String nameB = secondParentName;
String citizenName;
final String firstName;
final String middleInitial;
final String lastName;
if (firstParentName == null || firstParentName.isEmpty()) {
nameA = generateName(rand, rand.nextBoolean(), colony);
}
if (secondParentName == null || secondParentName.isEmpty()) {
nameB = generateName(rand, rand.nextBoolean(), colony);
}
final String[] firstParentNameSplit = nameA.split(" ");
final String[] secondParentNameSplit = nameB.split(" ");
int lastNameIndex = 1;
if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
lastNameIndex = 0;
} else if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
lastNameIndex = 2;
}
if (random.nextBoolean()) {
middleInitial = firstParentNameSplit[lastNameIndex].substring(0, 1);
lastName = secondParentNameSplit[lastNameIndex];
} else {
middleInitial = secondParentNameSplit[lastNameIndex].substring(0, 1);
lastName = firstParentNameSplit[lastNameIndex];
}
if (female) {
firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
} else {
firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
}
if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
// For now, don't include middle names, as their rules (and presence) vary heavily by region.
citizenName = String.format("%s %s", lastName, firstName);
} else {
if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
} else {
citizenName = String.format("%s %s", firstName, lastName);
}
}
// Check whether there's already a citizen with this name
for (final ICitizenData citizen : this.getColony().getCitizenManager().getCitizens()) {
if (citizen != null && citizen.getName().equals(citizenName)) {
// Oops - recurse this function and try again
generateName(rand, firstParentName, secondParentName);
return;
}
}
this.name = citizenName;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CitizenData method generateName.
/**
* Generates a random name from a set of names.
*
* @param rand Random object.
* @param female the gender
* @param colony the colony.
* @return Name of the citizen.
*/
public static String generateName(@NotNull final Random rand, final boolean female, final IColony colony) {
String citizenName;
final String firstName;
final String middleInitial;
final String lastName;
if (female) {
firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
} else {
firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
}
middleInitial = String.valueOf(getRandomLetter(rand));
lastName = getRandomElement(rand, MineColonies.getConfig().getServer().lastNames.get().toArray(new String[0]));
if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
// For now, don't include middle names, as their rules (and presence) vary heavily by region.
citizenName = String.format("%s %s", lastName, firstName);
} else {
if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
} else {
citizenName = String.format("%s %s", firstName, lastName);
}
}
// Check whether there's already a citizen with this name
for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
if (citizen != null && citizen.getName().equals(citizenName)) {
// Oops - recurse this function and try again
citizenName = generateName(rand, female, colony);
break;
}
}
return citizenName;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractBuilding method getRequesterDisplayName.
@NotNull
@Override
public IFormattableTextComponent getRequesterDisplayName(@NotNull final IRequestManager manager, @NotNull final IRequest<?> request) {
final int citizenId = getCitizensByRequest().get(request.getId());
if (!getCitizensByRequest().containsKey(citizenId)) {
return new StringTextComponent("<UNKNOWN>");
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(citizenId);
if (citizenData.getJob() == null) {
return new StringTextComponent(citizenData.getName());
}
final IFormattableTextComponent jobName = new TranslationTextComponent(citizenData.getJob().getJobRegistryEntry().getTranslationKey().toLowerCase());
return jobName.append(new StringTextComponent(" " + citizenData.getName()));
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractBuilding method overruleNextOpenRequestWithStack.
/**
* Overrule the next open request with a give stack.
* <p>
* We squid:s135 which takes care that there are not too many continue statements in a loop since it makes sense here out of performance reasons.
*
* @param stack the stack.
*/
@Override
@SuppressWarnings("squid:S135")
public void overruleNextOpenRequestWithStack(@NotNull final ItemStack stack) {
if (ItemStackUtils.isEmpty(stack)) {
return;
}
final Collection<IRequestResolver<?>> resolvers = getResolvers();
final List<IToken<?>> playerRequests = colony.getRequestManager().getPlayerResolver().getAllAssignedRequests();
final List<IToken<?>> retryingRequests = colony.getRequestManager().getRetryingRequestResolver().getAllAssignedRequests();
for (final IRequestResolver<?> resolver : resolvers) {
final IStandardRequestManager requestManager = (IStandardRequestManager) colony.getRequestManager();
final List<IRequest<? extends IDeliverable>> deliverableRequests = requestManager.getRequestHandler().getRequestsMadeByRequester(resolver).stream().filter(iRequest -> iRequest.getRequest() instanceof IDeliverable).map(iRequest -> (IRequest<? extends IDeliverable>) iRequest).collect(Collectors.toList());
final IRequest<? extends IDeliverable> target = getFirstOverullingRequestFromInputList(deliverableRequests, stack);
if (target == null || !isRequestStuck(target, playerRequests, retryingRequests)) {
continue;
}
colony.getRequestManager().overruleRequest(target.getId(), stack.copy());
return;
}
final Set<Integer> citizenIdsWithRequests = getOpenRequestsByCitizen().keySet();
for (final int citizenId : citizenIdsWithRequests) {
final ICitizenData data = colony.getCitizenManager().getCivilian(citizenId);
if (data == null) {
continue;
}
final IRequest<? extends IDeliverable> target = getFirstOverullingRequestFromInputList(getOpenRequestsOfType(data.getId(), TypeConstants.DELIVERABLE), stack);
if (target == null || !isRequestStuck(target, playerRequests, retryingRequests)) {
continue;
}
colony.getRequestManager().overruleRequest(target.getId(), stack.copy());
return;
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractBuilding method getHandlers.
@Override
public List<IItemHandler> getHandlers() {
if (this.getAllAssignedCitizen().isEmpty() || colony == null || colony.getWorld() == null) {
return Collections.emptyList();
}
final Set<IItemHandler> handlers = new HashSet<>();
for (final ICitizenData workerEntity : this.getAllAssignedCitizen()) {
handlers.add(workerEntity.getInventory());
}
final TileEntity entity = colony.getWorld().getBlockEntity(getID());
if (entity != null) {
final LazyOptional<IItemHandler> handler = entity.getCapability(ITEM_HANDLER_CAPABILITY, null);
handler.ifPresent(handlers::add);
}
return ImmutableList.copyOf(handlers);
}
Aggregations