Search in sources :

Example 61 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project minecolonies by Minecolonies.

the class KillCitizenCommand method executeSpecializedCode.

@Override
public void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizenManager().getCitizen(citizenId);
    citizenData.getCitizenEntity().ifPresent(entityCitizen -> {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
        final BlockPos position = entityCitizen.getPosition();
        sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
        sender.sendMessage(new TextComponentString(REMOVED_MESSAGE));
        server.addScheduledTask(() -> entityCitizen.onDeath(CONSOLE_DAMAGE_SOURCE));
    });
}
Also used : CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 62 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project minecolonies by Minecolonies.

the class ListCitizensCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final Colony colony, final Integer pageProvided) throws CommandException {
    int page;
    if (null != pageProvided) {
        page = pageProvided.intValue();
    } else {
        page = 1;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if ((null != colony) && !canPlayerUseCommand(player, LISTCITIZENS, colony.getID())) {
            player.sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
            return;
        }
    }
    final List<CitizenData> citizens = colony.getCitizenManager().getCitizens();
    final int citizenCount = citizens.size();
    // check to see if we have to add one page to show the half page
    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())))));
        citizen.getCitizenEntity().ifPresent(entityCitizen -> {
            final BlockPos position = entityCitizen.getPosition();
            sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
        });
    }
    drawPageSwitcher(sender, page, citizenCount, halfPage, (null != colony ? colony.getID() : -1));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Style(net.minecraft.util.text.Style) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 63 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project minecolonies by Minecolonies.

the class ListCitizensCommand method drawPageSwitcher.

/**
 * Draws the page switcher at the bottom.
 *
 * @param sender   the sender.
 * @param page     the page number.
 * @param count    number of citizens.
 * @param halfPage the halfPage.
 * @param colonyId the colony id.
 */
private static void drawPageSwitcher(@NotNull final ICommandSender sender, final int page, final int count, final int halfPage, final int colonyId) {
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (count / CITIZENS_ON_PAGE) + halfPage);
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, prevPage))));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(LIST_COMMAND_SUGGESTED, colonyId, nextPage))));
    final ITextComponent beginLine = new TextComponentString(PAGE_LINE);
    final ITextComponent endLine = new TextComponentString(PAGE_LINE);
    sender.sendMessage(beginLine.appendSibling(prevButton).appendSibling(new TextComponentString(PAGE_LINE_DIVIDER)).appendSibling(nextButton).appendSibling(endLine));
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 64 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project minecolonies by Minecolonies.

the class AddOfficerCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final Colony colony, final String playerName) throws CommandException {
    final Entity senderEntity = sender.getCommandSenderEntity();
    if (senderEntity instanceof EntityPlayer) {
        final EntityPlayer senderPlayer = (EntityPlayer) sender;
        if (!canPlayerUseCommand(senderPlayer, ADDOFFICER, colony.getID())) {
            senderEntity.sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    colony.getPermissions().addPlayer(playerName, Rank.OFFICER, colony.getWorld());
    sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE_ADD_OFFICER, playerName, colony.getID())));
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 65 with TextComponentString

use of net.minecraft.util.text.TextComponentString in project minecolonies by Minecolonies.

the class ChangeColonyOwnerCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final Colony colony, final EntityPlayer player) throws CommandException {
    if (player == null) {
        sender.sendMessage(new TextComponentString(NO_PLAYER));
        return;
    }
    if (!isPlayerOpped(sender)) {
        return;
    }
    if (ColonyManager.getIColonyByOwner(sender.getEntityWorld(), player) != null) {
        sender.sendMessage(new TextComponentString(String.format(HAS_A_COLONY, player.getName())));
        return;
    }
    colony.getPermissions().setOwner(player);
    sender.sendMessage(new TextComponentString(String.format(SUCCESS_MESSAGE_OWNERCHANGE, player.getName(), colony.getID())));
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TextComponentString (net.minecraft.util.text.TextComponentString)343 EntityPlayer (net.minecraft.entity.player.EntityPlayer)79 ItemStack (net.minecraft.item.ItemStack)68 BlockPos (net.minecraft.util.math.BlockPos)60 ITextComponent (net.minecraft.util.text.ITextComponent)48 TileEntity (net.minecraft.tileentity.TileEntity)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)35 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)32 Colony (com.minecolonies.coremod.colony.Colony)26 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)26 IBlockState (net.minecraft.block.state.IBlockState)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)21 Style (net.minecraft.util.text.Style)21 IColony (com.minecolonies.api.colony.IColony)19 ClickEvent (net.minecraft.util.text.event.ClickEvent)19 Entity (net.minecraft.entity.Entity)18 Block (net.minecraft.block.Block)17 World (net.minecraft.world.World)17 ArrayList (java.util.ArrayList)16 ActionResult (net.minecraft.util.ActionResult)13