Search in sources :

Example 11 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class ListCitizensCommand 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, getColonyId(sender));
    if (sender instanceof EntityPlayer) {
        if (colonyId == -1) {
            IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
            if (colony != null) {
                colonyId = colony.getID();
            }
        }
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, LISTCITIZENS, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
            return;
        }
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    final List<CitizenData> citizens = new ArrayList<>(colony.getCitizens().values());
    final int citizenCount = citizens.size();
    // check to see if we have to add one page to show the half page
    int page = getIthArgument(args, 1, 1);
    final int halfPage = (citizenCount % CITIZENS_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((citizenCount) / CITIZENS_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = CITIZENS_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(CITIZENS_ON_PAGE * page, citizenCount);
    final List<CitizenData> citizensPage;
    if (pageStartIndex < 0 || pageStartIndex >= citizenCount) {
        citizensPage = new ArrayList<>();
    } else {
        citizensPage = citizens.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(String.format(PAGE_TOP, page, pageCount));
    sender.sendMessage(headerLine);
    for (final CitizenData citizen : citizensPage) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizen.getId(), citizen.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO, citizen.getColony().getID(), citizen.getId())))));
        if (citizen.getCitizenEntity() != null) {
            final BlockPos position = citizen.getCitizenEntity().getPosition();
            sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
        }
    }
    drawPageSwitcher(sender, page, citizenCount, halfPage, colonyId);
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) IColony(com.minecolonies.coremod.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Example 12 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class AddOfficerCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    int colonyId = getIthArgument(args, 0, -1);
    if (colonyId == -1 && sender instanceof EntityPlayer) {
        final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
        if (colony == null) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(COLONY_NULL));
            return;
        }
        colonyId = colony.getID();
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
        return;
    }
    if (sender instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, ADDOFFICER, colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    String playerName = null;
    if (args.length >= 2) {
        playerName = args[1];
    }
    if (playerName == null || playerName.isEmpty()) {
        playerName = sender.getName();
    }
    colony.getPermissions().addPlayer(playerName, Rank.OFFICER, colony.getWorld());
    sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE, playerName, colonyId)));
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 13 with IColony

use of com.minecolonies.coremod.colony.IColony in project minecolonies by Minecolonies.

the class AbstractCitizensCommands method execute.

@NotNull
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    boolean firstArgumentColonyId = true;
    int colonyId = -1;
    if (args.length >= 2) {
        colonyId = getIthArgument(args, 0, -1);
        if (colonyId == -1) {
            final EntityPlayer player = server.getEntityWorld().getPlayerEntityByName(args[0]);
            if (player != null) {
                IColony tempColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
                if (tempColony != null) {
                    colonyId = tempColony.getID();
                }
            }
            firstArgumentColonyId = false;
        }
    }
    final Colony colony;
    if (sender instanceof EntityPlayer && colonyId == -1) {
        final IColony tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
        if (tempColony != null) {
            colonyId = tempColony.getID();
            firstArgumentColonyId = false;
        }
    }
    colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
    if (citizenId == -1 || colony.getCitizen(citizenId) == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    executeSpecializedCode(server, sender, colony, citizenId);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IColony (com.minecolonies.coremod.colony.IColony)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)10 TextComponentString (net.minecraft.util.text.TextComponentString)9 Colony (com.minecolonies.coremod.colony.Colony)8 NotNull (org.jetbrains.annotations.NotNull)3 UUID (java.util.UUID)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 ArrayList (java.util.ArrayList)1 BlockSilverfish (net.minecraft.block.BlockSilverfish)1 Minecraft (net.minecraft.client.Minecraft)1 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 Style (net.minecraft.util.text.Style)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1