use of com.minecolonies.coremod.colony.Colony 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.Colony 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.Colony in project minecolonies by Minecolonies.
the class ClaimChunksCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
// See if the player is opped.
if (sender instanceof EntityPlayerMP && isPlayerOpped(sender)) {
final Colony colony = actionMenu.getColonyForArgument("colony");
if (colony == null) {
sender.sendMessage(new TextComponentString(NO_COLONY_MESSAGE));
return;
}
final int range = actionMenu.getIntegerForArgument("range");
final Boolean add = actionMenu.getBooleanForArgument("add");
final Chunk chunk = ((EntityPlayerMP) sender).getServerWorld().getChunkFromBlockCoords(sender.getPosition());
ColonyManager.claimChunksInRange(colony.getID(), colony.getDimension(), add == null ? true : add, chunk.x, chunk.z, range, 0);
return;
} else {
sender.sendMessage(new TextComponentString(NO_PERMISSION_TO_CLAIM_MESSAGE));
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ColonyTeleportCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
Colony colony = actionMenu.getColonyForArgument("colony");
if (null == colony) {
final EntityPlayer player = actionMenu.getPlayerForArgument("player");
if (player != null) {
IColony iColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
if (null == iColony) {
if (sender instanceof EntityPlayer) {
final Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity != null) {
final UUID mayorID = senderEntity.getUniqueID();
if (iColony == null) {
iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
}
}
}
if (null != iColony) {
colony = ColonyManager.getColony(iColony.getID());
}
}
}
// Required argument: would never be null at this point.
if (null == colony) {
sender.sendMessage(new TextComponentString("You are not allowed to do this"));
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ColonyTeleportCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
Colony colony = null;
// see if player is allowed to use in the configs
if (args.length == 1) {
try {
final int colonyId = Integer.parseInt(args[0]);
colony = ColonyManager.getColony(colonyId);
} catch (final NumberFormatException e) {
// we ignore the exception and deal with a null colony below.
}
}
if (null == colony) {
sender.sendMessage(new TextComponentString("You are not allowed to do this"));
return;
}
executeShared(server, sender, colony);
}
Aggregations