Java 类net.minecraft.server.IChatBaseComponent 实例源码

项目:Craftbukkit    文件:CraftMetaBook.java   
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
    super.serialize(builder);

    if (hasTitle()) {
        builder.put(BOOK_TITLE.BUKKIT, title);
    }

    if (hasAuthor()) {
        builder.put(BOOK_AUTHOR.BUKKIT, author);
    }

    if (hasPages()) {
        List<String> pagesString = new ArrayList<String>();
        for (IChatBaseComponent comp : pages) {
            pagesString.add(CraftChatMessage.fromComponent(comp));
        }
        builder.put(BOOK_PAGES.BUKKIT, pagesString);
    }

    if (generation != null) {
        builder.put(GENERATION.BUKKIT, generation);
    }

    return builder;
}
项目:Craftbukkit    文件:CraftChatMessage.java   
public static String fromComponent(IChatBaseComponent component, EnumChatFormat defaultColor) {
    if (component == null) return "";
    StringBuilder out = new StringBuilder();

    for (IChatBaseComponent c : (Iterable<IChatBaseComponent>) component) {
        ChatModifier modi = c.getChatModifier();
        out.append(modi.getColor() == null ? defaultColor : modi.getColor());
        if (modi.isBold()) {
            out.append(EnumChatFormat.BOLD);
        }
        if (modi.isItalic()) {
            out.append(EnumChatFormat.ITALIC);
        }
        if (modi.isUnderlined()) {
            out.append(EnumChatFormat.UNDERLINE);
        }
        if (modi.isStrikethrough()) {
            out.append(EnumChatFormat.STRIKETHROUGH);
        }
        if (modi.isRandom()) {
            out.append(EnumChatFormat.OBFUSCATED);
        }
        out.append(c.getText());
    }
    return out.toString().replaceFirst("^(" + defaultColor + ")*", "");
}
项目:SpigotSource    文件:CraftMetaBook.java   
@Override
Builder<String, Object> serialize(Builder<String, Object> builder) {
    super.serialize(builder);

    if (hasTitle()) {
        builder.put(BOOK_TITLE.BUKKIT, title);
    }

    if (hasAuthor()) {
        builder.put(BOOK_AUTHOR.BUKKIT, author);
    }

    if (hasPages()) {
        List<String> pagesString = new ArrayList<String>();
        for (IChatBaseComponent comp : pages) {
            pagesString.add(CraftChatMessage.fromComponent(comp));
        }
        builder.put(BOOK_PAGES.BUKKIT, pagesString);
    }

    if (generation != null) {
        builder.put(GENERATION.BUKKIT, generation);
    }

    return builder;
}
项目:SpigotSource    文件:CraftChatMessage.java   
public static String fromComponent(IChatBaseComponent component, EnumChatFormat defaultColor) {
    if (component == null) return "";
    StringBuilder out = new StringBuilder();

    for (IChatBaseComponent c : (Iterable<IChatBaseComponent>) component) {
        ChatModifier modi = c.getChatModifier();
        out.append(modi.getColor() == null ? defaultColor : modi.getColor());
        if (modi.isBold()) {
            out.append(EnumChatFormat.BOLD);
        }
        if (modi.isItalic()) {
            out.append(EnumChatFormat.ITALIC);
        }
        if (modi.isUnderlined()) {
            out.append(EnumChatFormat.UNDERLINE);
        }
        if (modi.isStrikethrough()) {
            out.append(EnumChatFormat.STRIKETHROUGH);
        }
        if (modi.isRandom()) {
            out.append(EnumChatFormat.OBFUSCATED);
        }
        out.append(c.getText());
    }
    return out.toString().replaceFirst("^(" + defaultColor + ")*", "");
}
项目:ProjectAres    文件:PacketTracer.java   
@Override
public PacketTracer a(IChatBaseComponent chat) {
    value("Chat", chat);
    try {
        mute = true;
        super.a(chat);
    } finally {
        mute = false;
    }
    return this;
}
项目:Craftbukkit    文件:CraftSign.java   
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);

    if (result) {
        IChatBaseComponent[] newLines = sanitizeLines(lines);
        System.arraycopy(newLines, 0, sign.lines, 0, 4);
        sign.update();
    }

    return result;
}
项目:Craftbukkit    文件:CraftSign.java   
public static IChatBaseComponent[] sanitizeLines(String[] lines) {
    IChatBaseComponent[] components = new IChatBaseComponent[4];

    for (int i = 0; i < 4; i++) {
        if (i < lines.length && lines[i] != null) {
            components[i] = CraftChatMessage.fromString(lines[i])[0];
        } else {
            components[i] = new ChatComponentText("");
        }
    }

    return components;
}
项目:Craftbukkit    文件:CraftSign.java   
public static String[] revertComponents(IChatBaseComponent[] components) {
    String[] lines = new String[components.length];
    for (int i = 0; i < lines.length; i++) {
        lines[i] = revertComponent(components[i]);
    }
    return lines;
}
项目:Craftbukkit    文件:CraftMetaBookSigned.java   
@Override
void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData, false);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    } else {
        itemData.setString(BOOK_TITLE.NBT, " ");
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    } else {
        itemData.setString(BOOK_AUTHOR.NBT, " ");
    }

    if (hasPages()) {
        NBTTagList list = new NBTTagList();
        for (IChatBaseComponent page : pages) {
            list.add(new NBTTagString(
                ChatSerializer.a(page)
            ));
        }
        itemData.set(BOOK_PAGES.NBT, list);
    }        
    itemData.setBoolean(RESOLVED.NBT, true);

    if (generation != null) {
        itemData.setInt(GENERATION.NBT, generation);
    } else {
        itemData.setInt(GENERATION.NBT, 0);
    }
}
项目:Craftbukkit    文件:CraftMetaBook.java   
void applyToItem(NBTTagCompound itemData, boolean handlePages) {
    super.applyToItem(itemData);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    }

    if (handlePages) {
        if (hasPages()) {
            NBTTagList list = new NBTTagList();
            for (IChatBaseComponent page : pages) {
                list.add(new NBTTagString(CraftChatMessage.fromComponent(page)));
            }
            itemData.set(BOOK_PAGES.NBT, list);
        }

        itemData.remove(RESOLVED.NBT);
    }

    if (generation != null) {
        itemData.setInt(GENERATION.NBT, generation);
    }
}
项目:Craftbukkit    文件:CraftMetaBook.java   
public List<String> getPages() {
    final List<IChatBaseComponent> copy = ImmutableList.copyOf(pages);
    return new AbstractList<String>() {

        @Override
        public String get(int index) {
            return CraftChatMessage.fromComponent(copy.get(index));
        }

        @Override
        public int size() {
            return copy.size();
        }
    };
}
项目:SpigotSource    文件:CraftSign.java   
@Override
public boolean update(boolean force, boolean applyPhysics) {
    boolean result = super.update(force, applyPhysics);

    if (result) {
        IChatBaseComponent[] newLines = sanitizeLines(lines);
        System.arraycopy(newLines, 0, sign.lines, 0, 4);
        sign.update();
    }

    return result;
}
项目:SpigotSource    文件:CraftSign.java   
public static IChatBaseComponent[] sanitizeLines(String[] lines) {
    IChatBaseComponent[] components = new IChatBaseComponent[4];

    for (int i = 0; i < 4; i++) {
        if (i < lines.length && lines[i] != null) {
            components[i] = CraftChatMessage.fromString(lines[i])[0];
        } else {
            components[i] = new ChatComponentText("");
        }
    }

    return components;
}
项目:SpigotSource    文件:CraftSign.java   
public static String[] revertComponents(IChatBaseComponent[] components) {
    String[] lines = new String[components.length];
    for (int i = 0; i < lines.length; i++) {
        lines[i] = revertComponent(components[i]);
    }
    return lines;
}
项目:SpigotSource    文件:CraftMetaBookSigned.java   
@Override
void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData, false);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    } else {
        itemData.setString(BOOK_TITLE.NBT, " ");
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    } else {
        itemData.setString(BOOK_AUTHOR.NBT, " ");
    }

    if (hasPages()) {
        NBTTagList list = new NBTTagList();
        for (IChatBaseComponent page : pages) {
            list.add(new NBTTagString(
                ChatSerializer.a(page)
            ));
        }
        itemData.set(BOOK_PAGES.NBT, list);
    }        
    itemData.setBoolean(RESOLVED.NBT, true);

    if (generation != null) {
        itemData.setInt(GENERATION.NBT, generation);
    } else {
        itemData.setInt(GENERATION.NBT, 0);
    }
}
项目:SpigotSource    文件:CraftMetaBook.java   
void applyToItem(NBTTagCompound itemData, boolean handlePages) {
    super.applyToItem(itemData);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    }

    if (handlePages) {
        if (hasPages()) {
            NBTTagList list = new NBTTagList();
            for (IChatBaseComponent page : pages) {
                list.add(new NBTTagString(CraftChatMessage.fromComponent(page)));
            }
            itemData.set(BOOK_PAGES.NBT, list);
        }

        itemData.remove(RESOLVED.NBT);
    }

    if (generation != null) {
        itemData.setInt(GENERATION.NBT, generation);
    }
}
项目:SpigotSource    文件:CraftMetaBook.java   
public List<String> getPages() {
    final List<IChatBaseComponent> copy = ImmutableList.copyOf(pages);
    return new AbstractList<String>() {

        @Override
        public String get(int index) {
            return CraftChatMessage.fromComponent(copy.get(index));
        }

        @Override
        public int size() {
            return copy.size();
        }
    };
}
项目:CraftBukkit    文件:CraftChatMessage.java   
private StringMessage(String message) {
    this.message = message;
    if (message == null) {
        output = new IChatBaseComponent[] { currentChatComponent };
        return;
    }
    list.add(currentChatComponent);

    Matcher matcher = INCREMENTAL_PATTERN.matcher(message);
    String match = null;
    while (matcher.find()) {
        int groupId = 0;
        while ((match = matcher.group(++groupId)) == null) {
            // NOOP
        }
        appendNewComponent(matcher.start(groupId));
        switch (groupId) {
        case 1:
            EnumChatFormat format = formatMap.get(match.toLowerCase().charAt(1));
            if (format == EnumChatFormat.RESET) {
                modifier = new ChatModifier();
            } else if (format.isFormat()) {
                switch (format) {
                case BOLD:
                    modifier.setBold(Boolean.TRUE);
                    break;
                case ITALIC:
                    modifier.setItalic(Boolean.TRUE);
                    break;
                case STRIKETHROUGH:
                    modifier.setStrikethrough(Boolean.TRUE);
                    break;
                case UNDERLINE:
                    modifier.setUnderline(Boolean.TRUE);
                    break;
                case RANDOM:
                    modifier.setRandom(Boolean.TRUE);
                    break;
                default:
                    throw new AssertionError("Unexpected message format");
                }
            } else { // Color resets formatting
                modifier = new ChatModifier().setColor(format);
            }
            break;
        case 2:
            currentChatComponent = null;
            break;
        case 3:
            modifier.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
            appendNewComponent(matcher.end(groupId));
            modifier.setChatClickable((ChatClickable) null);
        }
        currentIndex = matcher.end(groupId);
    }

    if (currentIndex < message.length()) {
        appendNewComponent(message.length());
    }

    output = list.toArray(new IChatBaseComponent[0]);
}
项目:CraftBukkit    文件:CraftChatMessage.java   
private IChatBaseComponent[] getOutput() {
    return output;
}
项目:CraftBukkit    文件:CraftChatMessage.java   
public static IChatBaseComponent[] fromString(String message) {
    return new StringMessage(message).getOutput();
}
项目:Craftbukkit    文件:CraftSign.java   
private static String revertComponent(IChatBaseComponent component) {
    return CraftChatMessage.fromComponent(component);
}
项目:Craftbukkit    文件:CraftInventoryCustom.java   
@Override
public IChatBaseComponent getScoreboardDisplayName() {
    return new ChatComponentText(title);
}
项目:Craftbukkit    文件:CraftMetaBook.java   
@Override
public CraftMetaBook clone() {
    CraftMetaBook meta = (CraftMetaBook) super.clone();
    meta.pages = new ArrayList<IChatBaseComponent>(pages);
    return meta;
}
项目:Craftbukkit    文件:InventoryWrapper.java   
@Override
public IChatBaseComponent getScoreboardDisplayName() {
    return CraftChatMessage.fromString(getName())[0];
}
项目:Craftbukkit    文件:CraftChatMessage.java   
private StringMessage(String message,  boolean keepNewlines) {
    this.message = message;
    if (message == null) {
        output = new IChatBaseComponent[] { currentChatComponent };
        return;
    }
    list.add(currentChatComponent);

    Matcher matcher = INCREMENTAL_PATTERN.matcher(message);
    String match = null;
    while (matcher.find()) {
        int groupId = 0;
        while ((match = matcher.group(++groupId)) == null) {
            // NOOP
        }
        appendNewComponent(matcher.start(groupId));
        switch (groupId) {
        case 1:
            EnumChatFormat format = formatMap.get(match.toLowerCase().charAt(1));
            if (format == EnumChatFormat.RESET) {
                modifier = new ChatModifier();
            } else if (format.isFormat()) {
                switch (format) {
                case BOLD:
                    modifier.setBold(Boolean.TRUE);
                    break;
                case ITALIC:
                    modifier.setItalic(Boolean.TRUE);
                    break;
                case STRIKETHROUGH:
                    modifier.setStrikethrough(Boolean.TRUE);
                    break;
                case UNDERLINE:
                    modifier.setUnderline(Boolean.TRUE);
                    break;
                case OBFUSCATED:
                    modifier.setRandom(Boolean.TRUE);
                    break;
                default:
                    throw new AssertionError("Unexpected message format");
                }
            } else { // Color resets formatting
                modifier = new ChatModifier().setColor(format);
            }
            break;
        case 2:
            if (keepNewlines) {
                currentChatComponent.addSibling(new ChatComponentText("\n"));
            } else {
                currentChatComponent = null;
            }
            break;
        case 3:
            if ( !( match.startsWith( "http://" ) || match.startsWith( "https://" ) ) ) {
                match = "http://" + match;
            }
            modifier.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
            appendNewComponent(matcher.end(groupId));
            modifier.setChatClickable((ChatClickable) null);
        }
        currentIndex = matcher.end(groupId);
    }

    if (currentIndex < message.length()) {
        appendNewComponent(message.length());
    }

    output = list.toArray(new IChatBaseComponent[list.size()]);
}
项目:Craftbukkit    文件:CraftChatMessage.java   
private IChatBaseComponent[] getOutput() {
    return output;
}
项目:Craftbukkit    文件:CraftChatMessage.java   
public static IChatBaseComponent[] fromString(String message) {
    return fromString(message, false);
}
项目:Craftbukkit    文件:CraftChatMessage.java   
public static IChatBaseComponent[] fromString(String message, boolean keepNewlines) {
    return new StringMessage(message, keepNewlines).getOutput();
}
项目:Craftbukkit    文件:CraftChatMessage.java   
public static String fromComponent(IChatBaseComponent component) {
    return fromComponent(component, EnumChatFormat.BLACK);
}
项目:Craftbukkit    文件:CraftChatMessage.java   
public static IChatBaseComponent fixComponent(IChatBaseComponent component) {
    Matcher matcher = LINK_PATTERN.matcher("");
    return fixComponent(component, matcher);
}
项目:Craftbukkit    文件:CraftBlockCommandSender.java   
public void sendMessage(String message) {
    for (IChatBaseComponent component : CraftChatMessage.fromString(message)) {
        commandBlock.sendMessage(component);
    }
}
项目:Tweakkit-Server    文件:CraftChatMessage.java   
private StringMessage(String message) {
    this.message = message;
    if (message == null) {
        output = new IChatBaseComponent[] { currentChatComponent };
        return;
    }
    list.add(currentChatComponent);

    Matcher matcher = INCREMENTAL_PATTERN.matcher(message);
    String match = null;
    while (matcher.find()) {
        int groupId = 0;
        while ((match = matcher.group(++groupId)) == null) {
            // NOOP
        }
        appendNewComponent(matcher.start(groupId));
        switch (groupId) {
        case 1:
            EnumChatFormat format = formatMap.get(match.toLowerCase().charAt(1));
            if (format == EnumChatFormat.RESET) {
                modifier = new ChatModifier();
            } else if (format.isFormat()) {
                switch (format) {
                case BOLD:
                    modifier.setBold(Boolean.TRUE);
                    break;
                case ITALIC:
                    modifier.setItalic(Boolean.TRUE);
                    break;
                case STRIKETHROUGH:
                    modifier.setStrikethrough(Boolean.TRUE);
                    break;
                case UNDERLINE:
                    modifier.setUnderline(Boolean.TRUE);
                    break;
                case RANDOM:
                    modifier.setRandom(Boolean.TRUE);
                    break;
                default:
                    throw new AssertionError("Unexpected message format");
                }
            } else { // Color resets formatting
                modifier = new ChatModifier().setColor(format);
            }
            break;
        case 2:
            currentChatComponent = null;
            break;
        case 3:
            if ( !( match.startsWith( "http://" ) || match.startsWith( "https://" ) ) ) {
                match = "http://" + match;
            }
            modifier.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
            appendNewComponent(matcher.end(groupId));
            modifier.setChatClickable((ChatClickable) null);
        }
        currentIndex = matcher.end(groupId);
    }

    if (currentIndex < message.length()) {
        appendNewComponent(message.length());
    }

    output = list.toArray(new IChatBaseComponent[list.size()]);
}
项目:Tweakkit-Server    文件:CraftChatMessage.java   
private IChatBaseComponent[] getOutput() {
    return output;
}
项目:Tweakkit-Server    文件:CraftChatMessage.java   
public static IChatBaseComponent[] fromString(String message) {
    return new StringMessage(message).getOutput();
}
项目:SpigotSource    文件:CraftSign.java   
private static String revertComponent(IChatBaseComponent component) {
    return CraftChatMessage.fromComponent(component);
}
项目:SpigotSource    文件:CraftInventoryCustom.java   
@Override
public IChatBaseComponent getScoreboardDisplayName() {
    return new ChatComponentText(title);
}
项目:SpigotSource    文件:CraftMetaBook.java   
@Override
public CraftMetaBook clone() {
    CraftMetaBook meta = (CraftMetaBook) super.clone();
    meta.pages = new ArrayList<IChatBaseComponent>(pages);
    return meta;
}
项目:SpigotSource    文件:InventoryWrapper.java   
@Override
public IChatBaseComponent getScoreboardDisplayName() {
    return CraftChatMessage.fromString(getName())[0];
}
项目:SpigotSource    文件:CraftChatMessage.java   
private StringMessage(String message,  boolean keepNewlines) {
    this.message = message;
    if (message == null) {
        output = new IChatBaseComponent[] { currentChatComponent };
        return;
    }
    list.add(currentChatComponent);

    Matcher matcher = INCREMENTAL_PATTERN.matcher(message);
    String match = null;
    while (matcher.find()) {
        int groupId = 0;
        while ((match = matcher.group(++groupId)) == null) {
            // NOOP
        }
        appendNewComponent(matcher.start(groupId));
        switch (groupId) {
        case 1:
            EnumChatFormat format = formatMap.get(match.toLowerCase().charAt(1));
            if (format == EnumChatFormat.RESET) {
                modifier = new ChatModifier();
            } else if (format.isFormat()) {
                switch (format) {
                case BOLD:
                    modifier.setBold(Boolean.TRUE);
                    break;
                case ITALIC:
                    modifier.setItalic(Boolean.TRUE);
                    break;
                case STRIKETHROUGH:
                    modifier.setStrikethrough(Boolean.TRUE);
                    break;
                case UNDERLINE:
                    modifier.setUnderline(Boolean.TRUE);
                    break;
                case OBFUSCATED:
                    modifier.setRandom(Boolean.TRUE);
                    break;
                default:
                    throw new AssertionError("Unexpected message format");
                }
            } else { // Color resets formatting
                modifier = new ChatModifier().setColor(format);
            }
            break;
        case 2:
            if (keepNewlines) {
                currentChatComponent.addSibling(new ChatComponentText("\n"));
            } else {
                currentChatComponent = null;
            }
            break;
        case 3:
            if ( !( match.startsWith( "http://" ) || match.startsWith( "https://" ) ) ) {
                match = "http://" + match;
            }
            modifier.setChatClickable(new ChatClickable(EnumClickAction.OPEN_URL, match));
            appendNewComponent(matcher.end(groupId));
            modifier.setChatClickable((ChatClickable) null);
        }
        currentIndex = matcher.end(groupId);
    }

    if (currentIndex < message.length()) {
        appendNewComponent(message.length());
    }

    output = list.toArray(new IChatBaseComponent[list.size()]);
}
项目:SpigotSource    文件:CraftChatMessage.java   
private IChatBaseComponent[] getOutput() {
    return output;
}