Exemplo n.º 1
0
    public IChatComponent deserialize(
        JsonElement p_deserialize_1_,
        Type p_deserialize_2_,
        JsonDeserializationContext p_deserialize_3_) {
      if (p_deserialize_1_.isJsonPrimitive()) {
        return new ChatComponentText(p_deserialize_1_.getAsString());
      } else if (!p_deserialize_1_.isJsonObject()) {
        if (p_deserialize_1_.isJsonArray()) {
          JsonArray jsonarray1 = p_deserialize_1_.getAsJsonArray();
          IChatComponent ichatcomponent = null;
          Iterator iterator = jsonarray1.iterator();

          while (iterator.hasNext()) {
            JsonElement jsonelement1 = (JsonElement) iterator.next();
            IChatComponent ichatcomponent1 =
                this.deserialize(jsonelement1, jsonelement1.getClass(), p_deserialize_3_);

            if (ichatcomponent == null) {
              ichatcomponent = ichatcomponent1;
            } else {
              ichatcomponent.appendSibling(ichatcomponent1);
            }
          }

          return ichatcomponent;
        } else {
          throw new JsonParseException(
              "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
        }
      } else {
        JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
        Object object;

        if (jsonobject.has("text")) {
          object = new ChatComponentText(jsonobject.get("text").getAsString());
        } else if (jsonobject.has("translate")) {
          String s = jsonobject.get("translate").getAsString();

          if (jsonobject.has("with")) {
            JsonArray jsonarray = jsonobject.getAsJsonArray("with");
            Object[] aobject = new Object[jsonarray.size()];

            for (int i = 0; i < aobject.length; ++i) {
              aobject[i] = this.deserialize(jsonarray.get(i), p_deserialize_2_, p_deserialize_3_);

              if (aobject[i] instanceof ChatComponentText) {
                ChatComponentText chatcomponenttext = (ChatComponentText) aobject[i];

                if (chatcomponenttext.getChatStyle().isEmpty()
                    && chatcomponenttext.getSiblings().isEmpty()) {
                  aobject[i] = chatcomponenttext.getChatComponentText_TextValue();
                }
              }
            }

            object = new ChatComponentTranslation(s, aobject);
          } else {
            object = new ChatComponentTranslation(s, new Object[0]);
          }
        } else if (jsonobject.has("score")) {
          JsonObject jsonobject1 = jsonobject.getAsJsonObject("score");

          if (!jsonobject1.has("name") || !jsonobject1.has("objective")) {
            throw new JsonParseException("A score component needs a least a name and an objective");
          }

          object =
              new ChatComponentScore(
                  JsonUtils.getJsonObjectStringFieldValue(jsonobject1, "name"),
                  JsonUtils.getJsonObjectStringFieldValue(jsonobject1, "objective"));

          if (jsonobject1.has("value")) {
            ((ChatComponentScore) object)
                .func_179997_b(JsonUtils.getJsonObjectStringFieldValue(jsonobject1, "value"));
          }
        } else {
          if (!jsonobject.has("selector")) {
            throw new JsonParseException(
                "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
          }

          object =
              new ChatComponentSelector(
                  JsonUtils.getJsonObjectStringFieldValue(jsonobject, "selector"));
        }

        if (jsonobject.has("extra")) {
          JsonArray jsonarray2 = jsonobject.getAsJsonArray("extra");

          if (jsonarray2.size() <= 0) {
            throw new JsonParseException("Unexpected empty array of components");
          }

          for (int j = 0; j < jsonarray2.size(); ++j) {
            ((IChatComponent) object)
                .appendSibling(
                    this.deserialize(jsonarray2.get(j), p_deserialize_2_, p_deserialize_3_));
          }
        }

        ((IChatComponent) object)
            .setChatStyle(
                (ChatStyle) p_deserialize_3_.deserialize(p_deserialize_1_, ChatStyle.class));
        return (IChatComponent) object;
      }
    }
Exemplo n.º 2
0
    public IChatComponent deserialize(
        JsonElement p_deserialize_1_,
        Type p_deserialize_2_,
        JsonDeserializationContext p_deserialize_3_) {
      if (p_deserialize_1_.isJsonPrimitive()) {
        return new ChatComponentText(p_deserialize_1_.getAsString());
      } else if (!p_deserialize_1_.isJsonObject()) {
        if (p_deserialize_1_.isJsonArray()) {
          JsonArray var11 = p_deserialize_1_.getAsJsonArray();
          IChatComponent var12 = null;
          Iterator var15 = var11.iterator();

          while (var15.hasNext()) {
            JsonElement var17 = (JsonElement) var15.next();
            IChatComponent var18 = this.deserialize(var17, var17.getClass(), p_deserialize_3_);

            if (var12 == null) {
              var12 = var18;
            } else {
              var12.appendSibling(var18);
            }
          }

          return var12;
        } else {
          throw new JsonParseException(
              "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
        }
      } else {
        JsonObject var4 = p_deserialize_1_.getAsJsonObject();
        Object var5;

        if (var4.has("text")) {
          var5 = new ChatComponentText(var4.get("text").getAsString());
        } else if (var4.has("translate")) {
          String var6 = var4.get("translate").getAsString();

          if (var4.has("with")) {
            JsonArray var7 = var4.getAsJsonArray("with");
            Object[] var8 = new Object[var7.size()];

            for (int var9 = 0; var9 < var8.length; ++var9) {
              var8[var9] = this.deserialize(var7.get(var9), p_deserialize_2_, p_deserialize_3_);

              if (var8[var9] instanceof ChatComponentText) {
                ChatComponentText var10 = (ChatComponentText) var8[var9];

                if (var10.getChatStyle().isEmpty() && var10.getSiblings().isEmpty()) {
                  var8[var9] = var10.getChatComponentText_TextValue();
                }
              }
            }

            var5 = new ChatComponentTranslation(var6, var8);
          } else {
            var5 = new ChatComponentTranslation(var6, new Object[0]);
          }
        } else if (var4.has("score")) {
          JsonObject var13 = var4.getAsJsonObject("score");

          if (!var13.has("name") || !var13.has("objective")) {
            throw new JsonParseException("A score component needs a least a name and an objective");
          }

          var5 =
              new ChatComponentScore(
                  JsonUtils.getJsonObjectStringFieldValue(var13, "name"),
                  JsonUtils.getJsonObjectStringFieldValue(var13, "objective"));

          if (var13.has("value")) {
            ((ChatComponentScore) var5)
                .func_179997_b(JsonUtils.getJsonObjectStringFieldValue(var13, "value"));
          }
        } else {
          if (!var4.has("selector")) {
            throw new JsonParseException(
                "Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
          }

          var5 =
              new ChatComponentSelector(JsonUtils.getJsonObjectStringFieldValue(var4, "selector"));
        }

        if (var4.has("extra")) {
          JsonArray var14 = var4.getAsJsonArray("extra");

          if (var14.size() <= 0) {
            throw new JsonParseException("Unexpected empty array of components");
          }

          for (int var16 = 0; var16 < var14.size(); ++var16) {
            ((IChatComponent) var5)
                .appendSibling(
                    this.deserialize(var14.get(var16), p_deserialize_2_, p_deserialize_3_));
          }
        }

        ((IChatComponent) var5)
            .setChatStyle(
                (ChatStyle) p_deserialize_3_.deserialize(p_deserialize_1_, ChatStyle.class));
        return (IChatComponent) var5;
      }
    }
Exemplo n.º 3
0
  @Override
  public boolean run(Screenshot screen) {
    try {
      String title = ConfigHandler.SAVE_DATE_FORMAT.format(new Date());
      String description = "A minecraft screenshot ";

      if (Minecraft.getMinecraft().isSingleplayer()) {
        description += "in " + Minecraft.getMinecraft().getIntegratedServer().getFolderName();
      } else {
        ServerData data = Minecraft.getMinecraft().func_147104_D();
        description +=
            "on " + data.serverIP + (data.field_82821_f != 25565 ? ":" + data.field_82821_f : "");
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(screen.image, "png", baos);
      String data = Base64.encodeBase64String(baos.toByteArray());

      List<NameValuePair> arguments = new ArrayList<NameValuePair>(3);
      arguments.add(new BasicNameValuePair("client_id", ImgurAuthHandler.CLIENT_ID));
      arguments.add(new BasicNameValuePair("image", data));
      arguments.add(new BasicNameValuePair("type", "base64"));
      arguments.add(new BasicNameValuePair("title", title));
      arguments.add(new BasicNameValuePair("description", description));

      HttpPost hpost = new HttpPost("https://api.imgur.com/3/upload");
      hpost.setEntity(new UrlEncodedFormEntity(arguments));

      if (ImgurAuthHandler.getInstance().getAccessToken() != null) {
        hpost.addHeader(
            "Authorization", "Bearer " + ImgurAuthHandler.getInstance().getAccessToken());
      } else {
        hpost.addHeader("Authorization", "Client-ID " + ImgurAuthHandler.CLIENT_ID);
      }

      HttpClient client = HttpClientBuilder.create().build();
      HttpResponse resp = client.execute(hpost);
      String result = EntityUtils.toString(resp.getEntity());

      JsonObject responce = new JsonParser().parse(result).getAsJsonObject();
      JsonObject responceData = responce.get("data").getAsJsonObject();

      if (responce.has("success") && responce.get("success").getAsBoolean()) {
        final String uploadUrl = responceData.get("link").getAsString();

        HistoryHandler.addUploadedImage(
            new UploadedImage(title, uploadUrl, screen, new ImgurImageSource(uploadUrl)));

        IChatComponent message = new ChatComponentTranslation("image.upload.success");
        IChatComponent url = new ChatComponentText("Imgur");
        IChatComponent tooltip =
            new ChatComponentText(uploadUrl)
                .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.AQUA));

        url.setChatStyle(
            new ChatStyle()
                .setColor(EnumChatFormatting.GOLD)
                .setBold(true)
                .setChatHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip))
                .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, uploadUrl)));

        message.appendSibling(url);

        MessageHandler.sendChatMessage(message);

        if (ConfigHandler.COPY_URL_TO_CLIPBOARD) {
          GuiScreen.setClipboardString(uploadUrl);
          MessageHandler.sendChatMessage("image.upload.copy");
        }
      } else {
        MessageHandler.sendChatMessage(
            "image.upload.fail", "Imgur", responce.get("status").getAsInt());
        MessageHandler.sendChatMessage(responceData.get("error").getAsString());
        return false;
      }
      return true;
    } catch (Exception ex) {
      ex.printStackTrace();
      MessageHandler.sendChatMessage("image.upload.fail", "Imgur", ex.getMessage());
      return false;
    }
  }