use of com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester 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.requestsystem.requesters.BuildingBasedRequester in project minecolonies by Minecolonies.
the class BuildingBasedRequesterFactory method getNewInstance.
@NotNull
@Override
public BuildingBasedRequester getNewInstance(@NotNull final IFactoryController factoryController, @NotNull final AbstractBuilding building, @NotNull final Object... context) throws IllegalArgumentException {
if (context.length != 0) {
throw new IllegalArgumentException("To many context elements. Only 0 supported.");
}
final ILocation location = factoryController.getNewInstance(TypeConstants.ILOCATION, building.getLocation(), building.getColony().getWorld().provider.getDimension());
final IToken token = factoryController.getNewInstance(TypeConstants.ITOKEN);
return new BuildingBasedRequester(location, token);
}
use of com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester in project minecolonies by Minecolonies.
the class AbstractBuildingDependentRequestResolver method getBuilding.
@Override
@Nullable
public Optional<IRequester> getBuilding(@NotNull final IRequestManager manager, @NotNull final IToken<?> token) {
final IRequest request = manager.getRequestForToken(token);
if (request.getRequester() instanceof BuildingBasedRequester) {
final BuildingBasedRequester requester = (BuildingBasedRequester) request.getRequester();
final ILocation requesterLocation = requester.getRequesterLocation();
if (requesterLocation.equals(getRequesterLocation())) {
return requester.getBuilding(manager, token);
}
}
return Optional.empty();
}
Aggregations