示例#1
0
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    List<String> commandList = new ArrayList<String>(CommandHandler.getCommandList());
    Collections.sort(commandList, String.CASE_INSENSITIVE_ORDER);
    commandList.remove(getCommandName());
    for (int i = 0; i < commandList.size(); ++i) {
      String name = commandList.get(i);
      if (!CommandHandler.canUseCommand(sender, CommandHandler.getCommandPermission(name), name)) {
        commandList.remove(i--);
      }
    }
    final int pageSize = 7;
    int maxPages = (commandList.size() - 1) / pageSize;
    int page;

    try {
      page =
          args.length == 1 ? 0 : CommandBase.parseIntBounded(sender, args[1], 1, maxPages + 1) - 1;
    } catch (NumberInvalidException numberinvalidexception) {
      String commandName = args[1];
      if (!CommandHandler.getCommandExists(commandName)) {
        throw new CommandNotFoundException("info.cofh.command.notFound");
      }
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + commandName + ".syntax"));
      return;
    }

    int maxIndex = Math.min((page + 1) * pageSize, commandList.size());
    IChatComponent chatcomponenttranslation1 =
        new ChatComponentTranslation("commands.help.header", page + 1, maxPages + 1);
    chatcomponenttranslation1.getChatStyle().setColor(EnumChatFormatting.DARK_GREEN);
    sender.addChatMessage(chatcomponenttranslation1);

    for (int i = page * pageSize; i < maxIndex; ++i) {
      IChatComponent chatcomponenttranslation =
          new ChatComponentText("/cofh " + StringHelper.YELLOW + commandList.get(i));
      chatcomponenttranslation
          .getChatStyle()
          .setChatClickEvent(
              new ClickEvent(
                  ClickEvent.Action.SUGGEST_COMMAND, "/cofh syntax " + commandList.get(i)));
      sender.addChatMessage(chatcomponenttranslation);
    }
  }
示例#2
0
  public IChatComponent func_151000_E() {
    IChatComponent ichatcomponent =
        (new ChatComponentText("[")).appendText(this.getDisplayName()).appendText("]");

    if (this.field_151002_e != null) {
      NBTTagCompound nbttagcompound = new NBTTagCompound();
      this.writeToNBT(nbttagcompound);
      ichatcomponent
          .getChatStyle()
          .setChatHoverEvent(
              new HoverEvent(
                  HoverEvent.Action.SHOW_ITEM, new ChatComponentText(nbttagcompound.toString())));
      ichatcomponent.getChatStyle().setColor(this.getRarity().rarityColor);
    }

    return ichatcomponent;
  }
示例#3
0
 void fixSerialization() {
   List<HoverEvent> list = Lists.newArrayList();
   @SuppressWarnings("unchecked")
   Iterable<IChatComponent> chat = message;
   for (IChatComponent message : chat) {
     ChatStyle style = message.getChatStyle();
     HoverEvent hover = style.getChatHoverEvent();
     if (list.contains(hover)) continue;
     list.add(hover);
     if (hover != null && hover.getAction() == Action.SHOW_ENTITY) {
       // serialization is bugged
       try {
         String[] names = {"b", "field_150703_b", "value"};
         ReflectionHelper.setFieldValue(HoverEvent.class, hover, null, names);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
 }
 public static IChatComponent setColour(IChatComponent msg, EnumChatFormatting colour) {
   msg.getChatStyle().setColor(colour);
   return msg;
 }
示例#5
0
    public JsonElement serialize(
        IChatComponent p_serialize_1_,
        Type p_serialize_2_,
        JsonSerializationContext p_serialize_3_) {
      if (p_serialize_1_ instanceof ChatComponentText
          && p_serialize_1_.getChatStyle().isEmpty()
          && p_serialize_1_.getSiblings().isEmpty()) {
        return new JsonPrimitive(
            ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
      } else {
        JsonObject var4 = new JsonObject();

        if (!p_serialize_1_.getChatStyle().isEmpty()) {
          this.serializeChatStyle(p_serialize_1_.getChatStyle(), var4, p_serialize_3_);
        }

        if (!p_serialize_1_.getSiblings().isEmpty()) {
          JsonArray var5 = new JsonArray();
          Iterator var6 = p_serialize_1_.getSiblings().iterator();

          while (var6.hasNext()) {
            IChatComponent var7 = (IChatComponent) var6.next();
            var5.add(this.serialize(var7, var7.getClass(), p_serialize_3_));
          }

          var4.add("extra", var5);
        }

        if (p_serialize_1_ instanceof ChatComponentText) {
          var4.addProperty(
              "text", ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
        } else if (p_serialize_1_ instanceof ChatComponentTranslation) {
          ChatComponentTranslation var11 = (ChatComponentTranslation) p_serialize_1_;
          var4.addProperty("translate", var11.getKey());

          if (var11.getFormatArgs() != null && var11.getFormatArgs().length > 0) {
            JsonArray var14 = new JsonArray();
            Object[] var16 = var11.getFormatArgs();
            int var8 = var16.length;

            for (int var9 = 0; var9 < var8; ++var9) {
              Object var10 = var16[var9];

              if (var10 instanceof IChatComponent) {
                var14.add(this.serialize((IChatComponent) var10, var10.getClass(), p_serialize_3_));
              } else {
                var14.add(new JsonPrimitive(String.valueOf(var10)));
              }
            }

            var4.add("with", var14);
          }
        } else if (p_serialize_1_ instanceof ChatComponentScore) {
          ChatComponentScore var12 = (ChatComponentScore) p_serialize_1_;
          JsonObject var15 = new JsonObject();
          var15.addProperty("name", var12.func_179995_g());
          var15.addProperty("objective", var12.func_179994_h());
          var15.addProperty("value", var12.getUnformattedTextForChat());
          var4.add("score", var15);
        } else {
          if (!(p_serialize_1_ instanceof ChatComponentSelector)) {
            throw new IllegalArgumentException(
                "Don\'t know how to serialize " + p_serialize_1_ + " as a Component");
          }

          ChatComponentSelector var13 = (ChatComponentSelector) p_serialize_1_;
          var4.addProperty("selector", var13.func_179992_g());
        }

        return var4;
      }
    }
    public JsonElement serialize(
        IChatComponent p_serialize_1_,
        Type p_serialize_2_,
        JsonSerializationContext p_serialize_3_) {
      if (p_serialize_1_ instanceof ChatComponentText
          && p_serialize_1_.getChatStyle().isEmpty()
          && p_serialize_1_.getSiblings().isEmpty()) {
        return new JsonPrimitive(
            ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
      } else {
        JsonObject jsonobject = new JsonObject();

        if (!p_serialize_1_.getChatStyle().isEmpty()) {
          this.serializeChatStyle(p_serialize_1_.getChatStyle(), jsonobject, p_serialize_3_);
        }

        if (!p_serialize_1_.getSiblings().isEmpty()) {
          JsonArray jsonarray = new JsonArray();
          Iterator iterator = p_serialize_1_.getSiblings().iterator();

          while (iterator.hasNext()) {
            IChatComponent ichatcomponent1 = (IChatComponent) iterator.next();
            jsonarray.add(
                this.serialize(ichatcomponent1, ichatcomponent1.getClass(), p_serialize_3_));
          }

          jsonobject.add("extra", jsonarray);
        }

        if (p_serialize_1_ instanceof ChatComponentText) {
          jsonobject.addProperty(
              "text", ((ChatComponentText) p_serialize_1_).getChatComponentText_TextValue());
        } else if (p_serialize_1_ instanceof ChatComponentTranslation) {
          ChatComponentTranslation chatcomponenttranslation =
              (ChatComponentTranslation) p_serialize_1_;
          jsonobject.addProperty("translate", chatcomponenttranslation.getKey());

          if (chatcomponenttranslation.getFormatArgs() != null
              && chatcomponenttranslation.getFormatArgs().length > 0) {
            JsonArray jsonarray1 = new JsonArray();
            Object[] aobject = chatcomponenttranslation.getFormatArgs();
            int i = aobject.length;

            for (int j = 0; j < i; ++j) {
              Object object = aobject[j];

              if (object instanceof IChatComponent) {
                jsonarray1.add(
                    this.serialize((IChatComponent) object, object.getClass(), p_serialize_3_));
              } else {
                jsonarray1.add(new JsonPrimitive(String.valueOf(object)));
              }
            }

            jsonobject.add("with", jsonarray1);
          }
        } else if (p_serialize_1_ instanceof ChatComponentScore) {
          ChatComponentScore chatcomponentscore = (ChatComponentScore) p_serialize_1_;
          JsonObject jsonobject1 = new JsonObject();
          jsonobject1.addProperty("name", chatcomponentscore.func_179995_g());
          jsonobject1.addProperty("objective", chatcomponentscore.func_179994_h());
          jsonobject1.addProperty("value", chatcomponentscore.getUnformattedTextForChat());
          jsonobject.add("score", jsonobject1);
        } else {
          if (!(p_serialize_1_ instanceof ChatComponentSelector)) {
            throw new IllegalArgumentException(
                "Don\'t know how to serialize " + p_serialize_1_ + " as a Component");
          }

          ChatComponentSelector chatcomponentselector = (ChatComponentSelector) p_serialize_1_;
          jsonobject.addProperty("selector", chatcomponentselector.func_179992_g());
        }

        return jsonobject;
      }
    }
示例#7
0
  /** Executes the click event specified by the given chat component */
  protected boolean handleComponentClick(IChatComponent p_175276_1_) {
    if (p_175276_1_ == null) {
      return false;
    } else {
      ClickEvent clickevent = p_175276_1_.getChatStyle().getChatClickEvent();

      if (isShiftKeyDown()) {
        if (p_175276_1_.getChatStyle().getInsertion() != null) {
          this.setText(p_175276_1_.getChatStyle().getInsertion(), false);
        }
      } else if (clickevent != null) {
        if (clickevent.getAction() == ClickEvent.Action.OPEN_URL) {
          if (!this.mc.gameSettings.chatLinks) {
            return false;
          }

          try {
            URI uri = new URI(clickevent.getValue());
            String s = uri.getScheme();

            if (s == null) {
              throw new URISyntaxException(clickevent.getValue(), "Missing protocol");
            }

            if (!PROTOCOLS.contains(s.toLowerCase())) {
              throw new URISyntaxException(
                  clickevent.getValue(), "Unsupported protocol: " + s.toLowerCase());
            }

            if (this.mc.gameSettings.chatLinksPrompt) {
              this.clickedLinkURI = uri;
              this.mc.displayGuiScreen(
                  new GuiConfirmOpenLink(this, clickevent.getValue(), 31102009, false));
            } else {
              this.openWebLink(uri);
            }
          } catch (URISyntaxException urisyntaxexception) {
            LOGGER.error(
                (String) ("Can\'t open url for " + clickevent), (Throwable) urisyntaxexception);
          }
        } else if (clickevent.getAction() == ClickEvent.Action.OPEN_FILE) {
          URI uri1 = (new File(clickevent.getValue())).toURI();
          this.openWebLink(uri1);
        } else if (clickevent.getAction() == ClickEvent.Action.SUGGEST_COMMAND) {
          this.setText(clickevent.getValue(), true);
        } else if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND) {
          this.sendChatMessage(clickevent.getValue(), false);
        } else if (clickevent.getAction() == ClickEvent.Action.TWITCH_USER_INFO) {
          ChatUserInfo chatuserinfo =
              this.mc.getTwitchStream().func_152926_a(clickevent.getValue());

          if (chatuserinfo != null) {
            this.mc.displayGuiScreen(
                new GuiTwitchUserMode(this.mc.getTwitchStream(), chatuserinfo));
          } else {
            LOGGER.error("Tried to handle twitch user but couldn\'t find them!");
          }
        } else {
          LOGGER.error("Don\'t know how to handle " + clickevent);
        }

        return true;
      }

      return false;
    }
  }
示例#8
0
  /** Draws the hover event specified by the given chat component */
  protected void handleComponentHover(
      IChatComponent p_175272_1_, int p_175272_2_, int p_175272_3_) {
    if (p_175272_1_ != null && p_175272_1_.getChatStyle().getChatHoverEvent() != null) {
      HoverEvent hoverevent = p_175272_1_.getChatStyle().getChatHoverEvent();

      if (hoverevent.getAction() == HoverEvent.Action.SHOW_ITEM) {
        ItemStack itemstack = null;

        try {
          NBTBase nbtbase = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());

          if (nbtbase instanceof NBTTagCompound) {
            itemstack = ItemStack.loadItemStackFromNBT((NBTTagCompound) nbtbase);
          }
        } catch (NBTException var11) {;
        }

        if (itemstack != null) {
          this.renderToolTip(itemstack, p_175272_2_, p_175272_3_);
        } else {
          this.drawCreativeTabHoveringText(
              EnumChatFormatting.RED + "Invalid Item!", p_175272_2_, p_175272_3_);
        }
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ENTITY) {
        if (this.mc.gameSettings.advancedItemTooltips) {
          try {
            NBTBase nbtbase1 = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());

            if (nbtbase1 instanceof NBTTagCompound) {
              List<String> list1 = Lists.<String>newArrayList();
              NBTTagCompound nbttagcompound = (NBTTagCompound) nbtbase1;
              list1.add(nbttagcompound.getString("name"));

              if (nbttagcompound.hasKey("type", 8)) {
                String s = nbttagcompound.getString("type");
                list1.add("Type: " + s + " (" + EntityList.getIDFromString(s) + ")");
              }

              list1.add(nbttagcompound.getString("id"));
              this.drawHoveringText(list1, p_175272_2_, p_175272_3_);
            } else {
              this.drawCreativeTabHoveringText(
                  EnumChatFormatting.RED + "Invalid Entity!", p_175272_2_, p_175272_3_);
            }
          } catch (NBTException var10) {
            this.drawCreativeTabHoveringText(
                EnumChatFormatting.RED + "Invalid Entity!", p_175272_2_, p_175272_3_);
          }
        }
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_TEXT) {
        this.drawHoveringText(
            NEWLINE_SPLITTER.splitToList(hoverevent.getValue().getFormattedText()),
            p_175272_2_,
            p_175272_3_);
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ACHIEVEMENT) {
        StatBase statbase = StatList.getOneShotStat(hoverevent.getValue().getUnformattedText());

        if (statbase != null) {
          IChatComponent ichatcomponent = statbase.getStatName();
          IChatComponent ichatcomponent1 =
              new ChatComponentTranslation(
                  "stats.tooltip.type." + (statbase.isAchievement() ? "achievement" : "statistic"),
                  new Object[0]);
          ichatcomponent1.getChatStyle().setItalic(Boolean.valueOf(true));
          String s1 =
              statbase instanceof Achievement ? ((Achievement) statbase).getDescription() : null;
          List<String> list =
              Lists.newArrayList(
                  new String[] {
                    ichatcomponent.getFormattedText(), ichatcomponent1.getFormattedText()
                  });

          if (s1 != null) {
            list.addAll(this.fontRendererObj.listFormattedStringToWidth(s1, 150));
          }

          this.drawHoveringText(list, p_175272_2_, p_175272_3_);
        } else {
          this.drawCreativeTabHoveringText(
              EnumChatFormatting.RED + "Invalid statistic/achievement!", p_175272_2_, p_175272_3_);
        }
      }

      GlStateManager.disableLighting();
    }
  }
示例#9
0
  @Override
  public void run() {
    HttpURLConnection connection = null;
    BufferedReader reader = null;

    try {
      connection = (HttpURLConnection) new URL(changelogURL).openConnection();

      connection.connect();

      reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

      String line = reader.readLine();

      if (line == null) {
        PELogger.logFatal("Update check failed!");
        throw new IOException("No data from github changelog!");
      }

      String latestVersion;
      List<String> changes = Lists.newArrayList();

      latestVersion = line.substring(11);
      latestVersion = latestVersion.trim();

      while ((line = reader.readLine()) != null) {
        if (line.startsWith("###Version")) {
          break;
        }

        if (!line.isEmpty()) {
          line = line.substring(1).trim();
          changes.add(line);
        }
      }

      if (!PECore.VERSION.equals(latestVersion)) {
        PELogger.logInfo(
            "Mod is outdated! Check "
                + curseURL
                + " to get the latest version ("
                + latestVersion
                + ").");

        for (String s : changes) {
          PELogger.logInfo(s);
        }

        if (isServerSide) {
          ChangelogCMD.changelog.addAll(changes);
        } else {
          Minecraft.getMinecraft()
              .thePlayer
              .addChatMessage(
                  new ChatComponentText(
                      String.format(
                          StatCollector.translateToLocal("pe.update.available"), latestVersion)));
          Minecraft.getMinecraft()
              .thePlayer
              .addChatMessage(
                  new ChatComponentText(StatCollector.translateToLocal("pe.update.getit")));

          IChatComponent link = new ChatComponentText(curseURL);
          link.getChatStyle()
              .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, curseURL));
          Minecraft.getMinecraft().thePlayer.addChatMessage(link);

          Minecraft.getMinecraft()
              .thePlayer
              .addChatMessage(
                  new ChatComponentText(StatCollector.translateToLocal("pe.update.changelog")));
        }
      } else {
        PELogger.logInfo("Mod is updated.");
      }
    } catch (Exception e) {
      PELogger.logFatal("Caught exception in Update Checker thread!");
      e.printStackTrace();
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          PELogger.logFatal("Caught exception in Update Checker thread!");
          e.printStackTrace();
        }
      }

      if (connection != null) {
        connection.disconnect();
      }

      if (isServerSide) {
        hasRunServer = true;
      } else {
        hasRunClient = true;
      }
    }
  }
  public static List<IChatComponent> func_178908_a(
      IChatComponent p_178908_0_,
      int p_178908_1_,
      FontRenderer p_178908_2_,
      boolean p_178908_3_,
      boolean p_178908_4_) {
    int i = 0;
    IChatComponent ichatcomponent = new ChatComponentText("");
    List<IChatComponent> list = Lists.<IChatComponent>newArrayList();
    List<IChatComponent> list1 = Lists.newArrayList(p_178908_0_);

    for (int j = 0; j < ((List) list1).size(); ++j) {
      IChatComponent ichatcomponent1 = (IChatComponent) list1.get(j);
      String s = ichatcomponent1.getUnformattedTextForChat();
      boolean flag = false;

      if (s.contains("\n")) {
        int k = s.indexOf(10);
        String s1 = s.substring(k + 1);
        s = s.substring(0, k + 1);
        ChatComponentText chatcomponenttext = new ChatComponentText(s1);
        chatcomponenttext.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
        list1.add(j + 1, chatcomponenttext);
        flag = true;
      }

      String s4 =
          func_178909_a(ichatcomponent1.getChatStyle().getFormattingCode() + s, p_178908_4_);
      String s5 = s4.endsWith("\n") ? s4.substring(0, s4.length() - 1) : s4;
      int i1 = p_178908_2_.getStringWidth(s5);
      ChatComponentText chatcomponenttext1 = new ChatComponentText(s5);
      chatcomponenttext1.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());

      if (i + i1 > p_178908_1_) {
        String s2 = p_178908_2_.trimStringToWidth(s4, p_178908_1_ - i, false);
        String s3 = s2.length() < s4.length() ? s4.substring(s2.length()) : null;

        if (s3 != null && s3.length() > 0) {
          int l = s2.lastIndexOf(" ");

          if (l >= 0 && p_178908_2_.getStringWidth(s4.substring(0, l)) > 0) {
            s2 = s4.substring(0, l);

            if (p_178908_3_) {
              ++l;
            }

            s3 = s4.substring(l);
          } else if (i > 0 && !s4.contains(" ")) {
            s2 = "";
            s3 = s4;
          }

          ChatComponentText chatcomponenttext2 = new ChatComponentText(s3);
          chatcomponenttext2.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
          list1.add(j + 1, chatcomponenttext2);
        }

        i1 = p_178908_2_.getStringWidth(s2);
        chatcomponenttext1 = new ChatComponentText(s2);
        chatcomponenttext1.setChatStyle(ichatcomponent1.getChatStyle().createShallowCopy());
        flag = true;
      }

      if (i + i1 <= p_178908_1_) {
        i += i1;
        ichatcomponent.appendSibling(chatcomponenttext1);
      } else {
        flag = true;
      }

      if (flag) {
        list.add(ichatcomponent);
        i = 0;
        ichatcomponent = new ChatComponentText("");
      }
    }

    list.add(ichatcomponent);
    return list;
  }