use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class HireFireMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final HireFireMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony != null) {
//Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
if (message.hire) {
final CitizenData citizen = colony.getCitizen(message.citizenID);
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
} else {
((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
}
}
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method attemptResolve.
@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
if (manager.getColony().getWorld().isRemote) {
return null;
}
final Colony colony = (Colony) manager.getColony();
// We can do an instant get here, since we are already filtering on anything that has no entity.
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
// We can do an instant get here, since we are already filtering on anything that has no entity.
BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
}))).orElse(null);
if (freeDeliveryMan == null) {
return null;
}
final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
job.addRequest(request.getToken());
return Lists.newArrayList();
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class DeliveryRequestResolver method canResolve.
@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends Delivery> requestToCheck) {
if (manager.getColony().getWorld().isRemote) {
return false;
}
final Colony colony = (Colony) manager.getColony();
final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> requestToCheck.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).findFirst().orElse(null);
return freeDeliveryMan != null;
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class StandardPlayerRequestResolver method resolve.
@Nullable
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest request) throws RuntimeException {
final IColony colony = manager.getColony();
if (colony instanceof Colony) {
if (Configurations.requestSystem.creativeResolve && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get() instanceof AbstractBuilding) {
final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get();
final Optional<CitizenData> citizenDataOptional = building.getCitizenForRequest(request.getToken());
final List<ItemStack> resolvablestacks = request.getDisplayStacks();
if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
final ItemStack resolveStack = resolvablestacks.get(0);
resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizenDataOptional.get().getInventory()), resolveStack);
if (ItemStackUtils.isEmpty(remainingItemStack)) {
manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
return;
}
}
}
final List<EntityPlayer> players = new ArrayList<>(((Colony) colony).getMessageEntityPlayers());
final EntityPlayer owner = ServerUtils.getPlayerFromUUID(colony.getWorld(), ((Colony) colony).getPermissions().getOwner());
final TextComponentString colonyDescription = new TextComponentString(colony.getName() + ":");
if (manager.getColony().getWorld().isDaytime()) {
if (owner != null) {
players.remove(owner);
LanguageHandler.sendPlayerMessage(owner, "com.minecolonies.requestsystem.playerresolver", request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
}
LanguageHandler.sendPlayersMessage(players, "com.minecolonies.requestsystem.playerresolver", colonyDescription.getFormattedText() + " " + request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
}
}
assignedRequests.add(request.getToken());
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class CitizenManager method deserializeCitizen.
private CitizenData deserializeCitizen(@NotNull final NBTTagCompound compound) {
final CitizenData data = CitizenData.createFromNBT(compound, colony);
topCitizenId = Math.max(topCitizenId, data.getId());
return data;
}
Aggregations