Search in sources :

Example 56 with TextComponentString

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

the class ListColoniesCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @Nullable final Integer pageProvided, @Nullable final Integer abandonedSinceTimeInHoursProvided) throws CommandException {
    int page;
    if (null != pageProvided) {
        page = pageProvided.intValue();
    } else {
        page = 1;
    }
    int abandonedSinceTimeInHours;
    if (null != abandonedSinceTimeInHoursProvided) {
        abandonedSinceTimeInHours = abandonedSinceTimeInHoursProvided.intValue();
    } else {
        abandonedSinceTimeInHours = 0;
    }
    final List<Colony> colonies;
    if (abandonedSinceTimeInHours > 0) {
        colonies = ColonyManager.getColoniesAbandonedSince(abandonedSinceTimeInHours);
    } else {
        colonies = ColonyManager.getColonies();
    }
    final int colonyCount = colonies.size();
    // check to see if we have to add one page to show the half page
    final int halfPage = (colonyCount % COLONIES_ON_PAGE == 0) ? 0 : 1;
    final int pageCount = ((colonyCount) / COLONIES_ON_PAGE) + halfPage;
    if (page < 1 || page > pageCount) {
        page = 1;
    }
    final int pageStartIndex = COLONIES_ON_PAGE * (page - 1);
    final int pageStopIndex = Math.min(COLONIES_ON_PAGE * page, colonyCount);
    final int prevPage = Math.max(0, page - 1);
    final int nextPage = Math.min(page + 1, (colonyCount / COLONIES_ON_PAGE) + halfPage);
    final List<Colony> coloniesPage;
    if (pageStartIndex < 0 || pageStartIndex >= colonyCount) {
        coloniesPage = new ArrayList<>();
    } else {
        coloniesPage = colonies.subList(pageStartIndex, pageStopIndex);
    }
    final ITextComponent headerLine = new TextComponentString(PAGE_TOP_LEFT + page + PAGE_TOP_MIDDLE + pageCount + PAGE_TOP_RIGHT);
    sender.sendMessage(headerLine);
    for (final Colony colony : coloniesPage) {
        sender.sendMessage(new TextComponentString(String.format(ID_AND_NAME_TEXT, colony.getID(), colony.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_COLONY_INFO, colony.getID())))));
        final BlockPos center = colony.getCenter();
        final ITextComponent teleport = new TextComponentString(COORDINATES_TEXT + String.format(COORDINATES_XYZ, center.getX(), center.getY(), center.getZ()));
        if (isPlayerOpped(sender)) {
            teleport.setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, TELEPORT_COMMAND + colony.getID())));
        }
        sender.sendMessage(teleport);
    }
    final ITextComponent prevButton = new TextComponentString(PREV_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + prevPage)));
    final ITextComponent nextButton = new TextComponentString(NEXT_PAGE).setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, LIST_COMMAND_SUGGESTED + 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) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 57 with TextComponentString

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

the class MakeNotAutoDeletableCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @Nullable final Colony colony, final boolean canBeDeleted) {
    if (sender instanceof EntityPlayer && !isPlayerOpped(sender)) {
        sender.sendMessage(new TextComponentString("Must be OP to use command"));
        return;
    } else if (sender instanceof TileEntity) {
        return;
    }
    sender.sendMessage(new TextComponentString(MARKED));
    colony.setCanBeAutoDeleted(canBeDeleted);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 58 with TextComponentString

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

the class MakeNotAutoDeletableCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length < NUMBER_OR_ARGS_REQUIRED) {
        sender.sendMessage(new TextComponentString(NOT_ENOUGH_ARGUMENTS));
        return;
    }
    final int colonyId;
    colonyId = Integer.parseInt(args[0]);
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(String.format(NO_COLONY_FOUND_MESSAGE_ID, colonyId)));
        return;
    }
    final boolean canBeDeleted;
    canBeDeleted = Boolean.parseBoolean(args[1]);
    executeShared(server, sender, colony, canBeDeleted);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 59 with TextComponentString

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

the class RefreshColonyCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final Colony colony) {
    if (sender instanceof EntityPlayer) {
        final EntityPlayer senderPlayer = (EntityPlayer) sender.getCommandSenderEntity();
        if (!canPlayerUseCommand(senderPlayer, Commands.REFRESH_COLONY, colony.getID())) {
            senderPlayer.sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    sender.sendMessage(new TextComponentString(REFRESH));
    colony.getPermissions().restoreOwnerIfNull();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 60 with TextComponentString

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

the class AbstractCitizensCommands method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    final Colony colony = actionMenu.getColonyForArgument("colony");
    if (colony == null) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    final CitizenData citizenData = actionMenu.getCitizenForArgument("citizen");
    if (null == citizenData) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    final int citizenId = citizenData.getId();
    executeSpecializedCode(server, sender, colony, citizenId);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) 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