use of com.minecolonies.api.colony.IColony 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.api.colony.IColony 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.api.colony.IColony in project minecolonies by Minecolonies.
the class BuildingBasedRequester method updateBuilding.
private void updateBuilding() {
if (building != null) {
return;
}
if (location == null) {
return;
}
final World world = MineColonies.proxy.getWorld(location.getDimension());
final IColony colony = ColonyManager.getClosestIColony(world, location.getInDimensionLocation());
building = colony.getRequesterBuildingForPosition(location.getInDimensionLocation());
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class ShowColonyInfoCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int colonyId = getIthArgument(args, 0, -1);
IColony tempColony = ColonyManager.getColony(colonyId);
if (colonyId == -1 && args.length >= 1) {
final GameProfile playerProfile = server.getPlayerProfileCache().getGameProfileForUsername(args[0]);
if (playerProfile != null) {
tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), playerProfile.getId());
}
}
if (sender.getCommandSenderEntity() != null) {
final UUID mayorID = sender.getCommandSenderEntity().getUniqueID();
if (tempColony == null) {
tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
}
if (tempColony != null) {
colonyId = tempColony.getID();
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, SHOWCOLONYINFO, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
if (tempColony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
}
return;
}
final Colony colony = ColonyManager.getColony(tempColony.getID());
if (colony == null) {
if (colonyId == -1 && args.length != 0) {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOR_PLAYER_FOUND_MESSAGE, args[0])));
} else {
sender.sendMessage(new TextComponentString(String.format(NO_COLONY_WITH_ID_FOUND_MESSAGE, colonyId)));
}
return;
}
executeShared(server, sender, colony);
}
use of com.minecolonies.api.colony.IColony in project minecolonies by Minecolonies.
the class WhoAmICommand method executeShared.
private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender) throws CommandException {
if (!(sender instanceof EntityPlayer)) {
Log.getLogger().info("Very funny, you're a console!");
return;
}
final IColony colony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
final BlockPos pos = colony.getCenter();
final String colonyName = colony.getName();
final String playerName = sender.getDisplayName().getFormattedText();
final String posString = "x: " + pos.getX() + " y: " + pos.getY() + " z: " + pos.getZ();
sender.sendMessage(new TextComponentString(String.format(TELL_HIM, playerName, colonyName, posString)));
}
Aggregations