Search in sources :

Example 1 with Style

use of net.minecraft.util.text.Style in project SpongeCommon by SpongePowered.

the class MixinTextComponentBase method toLegacy.

@Override
public String toLegacy(char code) {
    StringBuilder builder = new StringBuilder();
    ResolvedChatStyle current = null;
    Style previous = null;
    for (ITextComponent component : withChildren()) {
        Style newStyle = component.getStyle();
        ResolvedChatStyle style = resolve(current, previous, newStyle);
        previous = newStyle;
        if (current == null || (current.color != style.color) || (current.bold && !style.bold) || (current.italic && !style.italic) || (current.underlined && !style.underlined) || (current.strikethrough && !style.strikethrough) || (current.obfuscated && !style.obfuscated)) {
            if (style.color != null) {
                apply(builder, code, style.color);
            } else if (current != null) {
                apply(builder, code, RESET);
            }
            apply(builder, code, BOLD, style.bold);
            apply(builder, code, ITALIC, style.italic);
            apply(builder, code, UNDERLINE, style.underlined);
            apply(builder, code, STRIKETHROUGH, style.strikethrough);
            apply(builder, code, OBFUSCATED, style.obfuscated);
        } else {
            apply(builder, code, BOLD, current.bold != style.bold);
            apply(builder, code, ITALIC, current.italic != style.italic);
            apply(builder, code, UNDERLINE, current.underlined != style.underlined);
            apply(builder, code, STRIKETHROUGH, current.strikethrough != style.strikethrough);
            apply(builder, code, OBFUSCATED, current.obfuscated != style.obfuscated);
        }
        current = style;
        builder.append(component.getUnformattedComponentText());
    }
    return builder.toString();
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) ResolvedChatStyle(org.spongepowered.common.text.ResolvedChatStyle) TextStyle(org.spongepowered.api.text.format.TextStyle) Style(net.minecraft.util.text.Style) ResolvedChatStyle(org.spongepowered.common.text.ResolvedChatStyle)

Example 2 with Style

use of net.minecraft.util.text.Style in project Charset by CharsetMC.

the class SubCommandHelp method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
    if (args.length >= 1) {
        SubCommand command = (getSide() == Side.CLIENT ? CommandCharset.CLIENT : CommandCharset.SERVER).SUB_COMMAND_MAP.get(args[0].toLowerCase());
        if (command != null && sender.canUseCommand(getPermissionLevel(), "charset") && (command.getSide() == Side.SERVER || (sender.getEntityWorld() != null && sender.getEntityWorld().isRemote))) {
            String[] usage = command.getUsage().split("\n");
            for (int i = 0; i < usage.length; i++) {
                sender.sendMessage(new TextComponentString(usage[i]));
            }
        } else {
            sender.sendMessage(new TextComponentTranslation("commands.generic.parameter.invalid", args[0]).setStyle(new Style().setColor(TextFormatting.RED)));
        }
    } else {
        for (SubCommand command : (getSide() == Side.CLIENT ? CommandCharset.CLIENT : CommandCharset.SERVER).SUB_COMMANDS) {
            if (sender.canUseCommand(getPermissionLevel(), "charset") && (command.getSide() == Side.SERVER || (sender.getEntityWorld() != null && sender.getEntityWorld().isRemote))) {
                String[] usage = command.getUsage().split("\n");
                if (usage.length > 0) {
                    String name = TextFormatting.BOLD + command.getName() + TextFormatting.RESET;
                    if (command.getAliases().size() > 0) {
                        name += " (" + CommandCharset.COMMAS.join(command.getAliases()) + ")";
                    }
                    sender.sendMessage(new TextComponentString("- " + name + ": " + usage[0]));
                    for (int i = 1; i < usage.length; i++) {
                        sender.sendMessage(new TextComponentString(usage[i]));
                    }
                }
            }
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with Style

use of net.minecraft.util.text.Style in project HorsePower by GoryMoon.

the class HorsePowerCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 1) {
        if ("entity".equals(args[0])) {
            if (sender instanceof EntityPlayerSP) {
                RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
                if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
                    Entity entity = result.entityHit;
                    sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.has", entity.getClass().getName()));
                    try {
                        StringSelection selection = new StringSelection(entity.getClass().getName());
                        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
                    } catch (Exception ignored) {
                    }
                } else
                    sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.no"));
            } else
                throw new CommandException("commands.horsepower.entity.invalid");
            return;
        }
        if ("reload".equals(args[0])) {
            sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload").setStyle(new Style().setColor(TextFormatting.YELLOW).setBold(true)));
            HPEventHandler.reloadConfig();
            boolean hasErrors = HPRecipes.ERRORS.size() > 0;
            Utils.sendSavedErrors();
            if (hasErrors)
                sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.error").setStyle(new Style().setColor(TextFormatting.DARK_RED).setBold(true)));
            else
                sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.noerror").setStyle(new Style().setColor(TextFormatting.GREEN).setBold(true)));
            return;
        }
    }
    throw new WrongUsageException(getUsage(sender));
}
Also used : Entity(net.minecraft.entity.Entity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WrongUsageException(net.minecraft.command.WrongUsageException) RayTraceResult(net.minecraft.util.math.RayTraceResult) Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) StringSelection(java.awt.datatransfer.StringSelection)

Example 4 with Style

use of net.minecraft.util.text.Style 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 5 with Style

use of net.minecraft.util.text.Style 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)

Aggregations

Style (net.minecraft.util.text.Style)39 TextComponentString (net.minecraft.util.text.TextComponentString)21 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)17 BlockPos (net.minecraft.util.math.BlockPos)9 ClickEvent (net.minecraft.util.text.event.ClickEvent)9 ITextComponent (net.minecraft.util.text.ITextComponent)8 CommandException (net.minecraft.command.CommandException)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 World (net.minecraft.world.World)4 Colony (com.minecolonies.coremod.colony.Colony)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)3 GameProfile (com.mojang.authlib.GameProfile)2 ArrayList (java.util.ArrayList)2 Entity (net.minecraft.entity.Entity)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Biome (net.minecraft.world.biome.Biome)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonElement (com.google.gson.JsonElement)1