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; }
@Override public boolean c(EntityHuman entityhuman) { if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) { return true; } // If the window type has changed for some reason, update the player // This method will be called every tick or something, so it's // as good a place as any to put something like this. boolean typeChanged = (cachedType != view.getType()); cachedType = view.getType(); cachedTitle = view.getTitle(); if (view.getPlayer() instanceof CraftPlayer) { CraftPlayer player = (CraftPlayer) view.getPlayer(); String type = getNotchInventoryType(cachedType); IInventory top = ((CraftInventory)view.getTopInventory()).getInventory(); IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); this.b.clear(); this.c.clear(); if (typeChanged) { setupSlots(top, bottom); } int size = getSize(); player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle), size)); player.updateInventory(); } return true; }
@Override public boolean c(EntityHuman entityhuman) { if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) { return true; } // If the window type has changed for some reason, update the player // This method will be called every tick or something, so it's // as good a place as any to put something like this. boolean typeChanged = (cachedType != view.getType()); cachedType = view.getType(); cachedTitle = view.getTitle(); if (view.getPlayer() instanceof CraftPlayer) { CraftPlayer player = (CraftPlayer) view.getPlayer(); String type = getNotchInventoryType(cachedType); IInventory top = ((CraftInventory) view.getTopInventory()).getInventory(); IInventory bottom = ((CraftInventory) view.getBottomInventory()).getInventory(); this.b.clear(); this.c.clear(); if (typeChanged) { setupSlots(top, bottom); } int size = getSize(); player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle), size)); player.updateInventory(); } return true; }
@Override public IChatBaseComponent getScoreboardDisplayName() { return new ChatComponentText(title); }
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()]); }
@Override public void sendMessage(String message) { RemoteControlCommandListener.getInstance().sendMessage(new ChatComponentText(message + "\n")); // Send a newline after each message, to preserve formatting. }
public PacketPlayOutPlayerInfo.PlayerInfoData getPlayerInfo(Player viewer, PacketPlayOutPlayerInfo listPacket) { int ping = getPing(); return listPacket.new PlayerInfoData(getProfile(), ping < 0 ? 1000 : ping, EnumGamemode.SURVIVAL, new ChatComponentText(getDisplayName(viewer))); }
@Override public void sendMessage(String message) { listener.sendMessage(new ChatComponentText(message + "\n")); // Send a newline after each message, to preserve formatting. }