Search in sources :

Example 1 with IColony

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());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with IColony

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);
}
Also used : Entity(net.minecraft.entity.Entity) Colony(com.minecolonies.coremod.colony.Colony) TeleportToColony(com.minecolonies.coremod.util.TeleportToColony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IColony

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());
}
Also used : IColony(com.minecolonies.api.colony.IColony) World(net.minecraft.world.World)

Example 4 with IColony

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);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with IColony

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)));
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

IColony (com.minecolonies.api.colony.IColony)22 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 TextComponentString (net.minecraft.util.text.TextComponentString)14 Colony (com.minecolonies.coremod.colony.Colony)12 Entity (net.minecraft.entity.Entity)7 UUID (java.util.UUID)5 Player (com.minecolonies.api.colony.permissions.Player)2 ColonyView (com.minecolonies.coremod.colony.ColonyView)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 NotNull (org.jetbrains.annotations.NotNull)2 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)1 TeleportToColony (com.minecolonies.coremod.util.TeleportToColony)1 GameProfile (com.mojang.authlib.GameProfile)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1