Exemplo n.º 1
0
  public void func_71515_b(ICommandSender p_71515_1_, String[] p_71515_2_) {
    if (p_71515_2_.length >= 1 && p_71515_2_[0].length() > 1) {
      Matcher var3 = field_147211_a.matcher(p_71515_2_[0]);
      IChatComponent var4 = null;
      if (p_71515_2_.length >= 2) {
        var4 = func_147178_a(p_71515_1_, p_71515_2_, 1);
      }

      if (var3.matches()) {
        this.func_147210_a(p_71515_1_, p_71515_2_[0], var4 == null ? null : var4.func_150260_c());
      } else {
        EntityPlayerMP var5 =
            MinecraftServer.func_71276_C().func_71203_ab().func_72361_f(p_71515_2_[0]);
        if (var5 == null) {
          throw new PlayerNotFoundException("commands.banip.invalid", new Object[0]);
        }

        this.func_147210_a(
            p_71515_1_, var5.func_71114_r(), var4 == null ? null : var4.func_150260_c());
      }

    } else {
      throw new WrongUsageException("commands.banip.usage", new Object[0]);
    }
  }
Exemplo n.º 2
0
 /**
  * Returns true if the given quest made progress and/or no further interactions should occur.
  *
  * @param player
  * @param quest Quest instance to check for progress
  * @param handler IQuestHandler will have its methods called at appropriate times; pass {@link
  *     #DEFAULT_QUEST_HANDLER} if none available
  * @param data Optional arguments passed to the various {@code IQuest} methods, e.g. {@link
  *     IQuest#begin begin} and {@link IQuest#complete complete}
  * @return True if something happened, i.e. the calling interaction should be canceled
  */
 public static boolean checkQuestProgress(
     EntityPlayer player, IQuest quest, IQuestHandler handler, Object... data) {
   boolean changed = false;
   if (quest.isComplete(player)) {
     // do nothing if quest is already complete
   } else if (quest.canBegin(player)) {
     if (quest.begin(player, data)) {
       handler.onQuestBegun(quest, player);
       changed = true;
     }
   } else if (quest.canComplete(player)) {
     if (quest.complete(player, data)) {
       handler.onQuestCompleted(quest, player);
       changed = true;
     }
   } else if (quest.hasBegun(player) && quest.update(player, data)) {
     handler.onQuestChanged(quest, player);
     changed = true;
   }
   if (!changed) { // check for hint
     IChatComponent hint = quest.getHint(player, data);
     if (hint != null) { // result may be different on client vs. server due to Random
       if (!player.worldObj.isRemote && !hint.getFormattedText().equals("")) {
         player.addChatMessage(hint);
       }
       return true;
     }
   }
   if (changed && quest.requiresSync() && player instanceof EntityPlayerMP) {
     PacketDispatcher.sendTo(new SyncQuestPacket(quest), (EntityPlayerMP) player);
   }
   return changed;
 }
Exemplo n.º 3
0
  /** Called when a CommandSender executes this command */
  public void execute(ICommandSender sender, String[] args) throws CommandException {
    if (args.length >= 1 && args[0].length() > 1) {
      IChatComponent ichatcomponent =
          args.length >= 2 ? getChatComponentFromNthArg(sender, args, 1) : null;
      Matcher matcher = field_147211_a.matcher(args[0]);

      if (matcher.matches()) {
        this.func_147210_a(
            sender, args[0], ichatcomponent == null ? null : ichatcomponent.getUnformattedText());
      } else {
        EntityPlayerMP entityplayermp =
            MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(args[0]);

        if (entityplayermp == null) {
          throw new PlayerNotFoundException("commands.banip.invalid", new Object[0]);
        }

        this.func_147210_a(
            sender,
            entityplayermp.getPlayerIP(),
            ichatcomponent == null ? null : ichatcomponent.getUnformattedText());
      }
    } else {
      throw new WrongUsageException("commands.banip.usage", new Object[0]);
    }
  }
Exemplo n.º 4
0
 @Override
 public synchronized void printChatMessageWithOptionalDeletion(IChatComponent ichat, int id) {
   // chat listeners
   ChatRecievedEvent chatevent = new ChatRecievedEvent(ichat, id);
   chatevent.channels.add(ChatChannel.DEFAULT_CHANNEL);
   tc.getEventManager().onChatRecieved(chatevent);
   // chat filters
   ichat = chatevent.chat;
   id = chatevent.id;
   if (ichat != null && !ichat.getUnformattedText().isEmpty()) {
     if (id != 0) {
       // send removable msg to current channel
       chatevent.channels.clear();
       chatevent.channels.add(this.chat.getActiveChannel());
     }
     if (chatevent.channels.contains(ChatChannel.DEFAULT_CHANNEL)
         && chatevent.channels.size() > 1
         && !tc.serverSettings.general.useDefaultTab.getValue()) {
       chatevent.channels.remove(ChatChannel.DEFAULT_CHANNEL);
     }
     boolean msg = !chatevent.channels.contains(this.chat.getActiveChannel());
     for (Channel channel : chatevent.channels) {
       channel.addMessage(ichat, id);
       if (msg) {
         channel.setStatus(ChannelStatus.UNREAD);
       }
     }
     TabbyChat.getLogger().info("[CHAT] " + ichat.getUnformattedText());
     this.chat.getChatBox().updateComponent();
   }
 }
Exemplo n.º 5
0
  public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) {
    if (par2ArrayOfStr.length >= 1 && par2ArrayOfStr[0].length() > 1) {
      Matcher var3 = field_147211_a.matcher(par2ArrayOfStr[0]);
      IChatComponent var4 = null;

      if (par2ArrayOfStr.length >= 2) {
        var4 = func_147178_a(par1ICommandSender, par2ArrayOfStr, 1);
      }

      if (var3.matches()) {
        this.func_147210_a(
            par1ICommandSender, par2ArrayOfStr[0], var4 == null ? null : var4.getUnformattedText());
      } else {
        EntityPlayerMP var5 =
            MinecraftServer.getServer()
                .getConfigurationManager()
                .getPlayerEntity(par2ArrayOfStr[0]);

        if (var5 == null) {
          throw new PlayerNotFoundException("commands.banip.invalid", new Object[0]);
        }

        this.func_147210_a(
            par1ICommandSender,
            var5.getPlayerIP(),
            var4 == null ? null : var4.getUnformattedText());
      }
    } else {
      throw new WrongUsageException("commands.banip.usage", new Object[0]);
    }
  }
Exemplo n.º 6
0
  /** Creates a copy of this component. Almost a deep copy, except the style is shallow-copied. */
  public ChatComponentText createCopy() {
    ChatComponentText var1 = new ChatComponentText(this.text);
    var1.setChatStyle(this.getChatStyle().createShallowCopy());
    Iterator var2 = this.getSiblings().iterator();

    while (var2.hasNext()) {
      IChatComponent var3 = (IChatComponent) var2.next();
      var1.appendSibling(var3.createCopy());
    }

    return var1;
  }
Exemplo n.º 7
0
  public ChatComponentScore func_179996_i() {
    ChatComponentScore var1 = new ChatComponentScore(this.field_179999_b, this.field_180000_c);
    var1.func_179997_b(this.field_179998_d);
    var1.setChatStyle(this.getChatStyle().createShallowCopy());
    Iterator var2 = this.getSiblings().iterator();

    while (var2.hasNext()) {
      IChatComponent var3 = (IChatComponent) var2.next();
      var1.appendSibling(var3.createCopy());
    }

    return var1;
  }
Exemplo n.º 8
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);
    }
  }
Exemplo n.º 9
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;
  }
Exemplo n.º 10
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();
       }
     }
   }
 }
Exemplo n.º 11
0
  public IChatComponent C() {
    ChatComponentText chatcomponenttext = new ChatComponentText(this.q());

    if (this.s()) {
      chatcomponenttext.b().b(Boolean.valueOf(true));
    }

    IChatComponent ichatcomponent = (new ChatComponentText("[")).a(chatcomponenttext).a("]");

    if (this.d != null) {
      NBTTagCompound nbttagcompound = new NBTTagCompound();

      this.b(nbttagcompound);
      ichatcomponent
          .b()
          .a(
              new HoverEvent(
                  HoverEvent.Action.SHOW_ITEM, new ChatComponentText(nbttagcompound.toString())));
      ichatcomponent.b().a(this.u().e);
    }

    return ichatcomponent;
  }
Exemplo n.º 12
0
  public static void sendNotice(ICommandSender sender, IChatComponent msg, String permission) {
    ChatComponentTranslation notice =
        new ChatComponentTranslation("chat.type.admin", sender.getName(), msg.createCopy());
    notice.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true);

    if (NEIServerConfig.canPlayerPerformAction("CONSOLE", permission)) {
      MinecraftServer.getServer().addChatMessage(notice);
    }

    for (EntityPlayer p : ServerUtils.getPlayers()) {
      if (p == sender) {
        p.addChatComponentMessage(msg);
      } else if (NEIServerConfig.canPlayerPerformAction(p.getName(), permission)) {
        p.addChatComponentMessage(notice);
      }
    }
  }
Exemplo n.º 13
0
 @SideOnly(Side.CLIENT)
 public InventoryBasic(IChatComponent title, int slotCount) {
   this(title.getUnformattedText(), true, slotCount);
 }
Exemplo n.º 14
0
 /**
  * Notifies this sender of some sort of information. This is for messages intended to display to
  * the user. Used for typical output (like "you asked for whether or not this game rule is set, so
  * here's your answer"), warnings (like "I fetched this block for you by ID, but I'd like you to
  * know that every time you do this, I die a little inside"), and errors (like "it's not called
  * iron_pixacke, silly").
  */
 public void addChatMessage(IChatComponent message) {
   logger.info(message.getUnformattedText());
 }
Exemplo n.º 15
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.º 16
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;
      }
    }
Exemplo n.º 17
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;
    }
  }
Exemplo n.º 18
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.º 19
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 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;
      }
    }
Exemplo n.º 20
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;
      }
    }
  }
Exemplo n.º 21
0
 /**
  * Notifies this sender of some sort of information. This is for messages intended to display to
  * the user. Used for typical output (like "you asked for whether or not this game rule is set, so
  * here's your answer"), warnings (like "I fetched this block for you by ID, but I'd like you to
  * know that every time you do this, I die a little inside"), and errors (like "it's not called
  * iron_pixacke, silly").
  */
 public void addChatMessage(IChatComponent message) {
   this.buffer.append(message.getUnformattedText());
 }
Exemplo n.º 22
0
  public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) {
    if (par2ArrayOfStr.length >= 1) {
      String var3 = par2ArrayOfStr[0];
      double var4 = (double) par1ICommandSender.getCommandSenderPosition().posX + 0.5D;
      double var6 = (double) par1ICommandSender.getCommandSenderPosition().posY;
      double var8 = (double) par1ICommandSender.getCommandSenderPosition().posZ + 0.5D;

      if (par2ArrayOfStr.length >= 4) {
        var4 = func_110666_a(par1ICommandSender, var4, par2ArrayOfStr[1]);
        var6 = func_110666_a(par1ICommandSender, var6, par2ArrayOfStr[2]);
        var8 = func_110666_a(par1ICommandSender, var8, par2ArrayOfStr[3]);
      }

      World var10 = par1ICommandSender.getEntityWorld();

      if (!var10.blockExists((int) var4, (int) var6, (int) var8)) {
        notifyAdmins(par1ICommandSender, "commands.summon.outOfWorld", new Object[0]);
      } else {
        NBTTagCompound var11 = new NBTTagCompound();
        boolean var12 = false;

        if (par2ArrayOfStr.length >= 5) {
          IChatComponent var13 = func_147178_a(par1ICommandSender, par2ArrayOfStr, 4);

          try {
            NBTBase var14 = JsonToNBT.func_150315_a(var13.getUnformattedText());

            if (!(var14 instanceof NBTTagCompound)) {
              notifyAdmins(
                  par1ICommandSender, "commands.summon.tagError", new Object[] {"Not a valid tag"});
              return;
            }

            var11 = (NBTTagCompound) var14;
            var12 = true;
          } catch (NBTException var17) {
            notifyAdmins(
                par1ICommandSender, "commands.summon.tagError", new Object[] {var17.getMessage()});
            return;
          }
        }

        var11.setString("id", var3);
        Entity var18 = EntityList.createEntityFromNBT(var11, var10);

        if (var18 != null) {
          var18.setLocationAndAngles(var4, var6, var8, var18.rotationYaw, var18.rotationPitch);

          if (!var12 && var18 instanceof EntityLiving) {
            ((EntityLiving) var18).onSpawnWithEgg((IEntityLivingData) null);
          }

          var10.spawnEntityInWorld(var18);
          Entity var19 = var18;

          for (NBTTagCompound var15 = var11;
              var15.func_150297_b("Riding", 10);
              var15 = var15.getCompoundTag("Riding")) {
            Entity var16 = EntityList.createEntityFromNBT(var15.getCompoundTag("Riding"), var10);

            if (var16 != null) {
              var16.setLocationAndAngles(var4, var6, var8, var16.rotationYaw, var16.rotationPitch);
              var10.spawnEntityInWorld(var16);
              var19.mountEntity(var16);
            }

            var19 = var16;
          }

          notifyAdmins(par1ICommandSender, "commands.summon.success", new Object[0]);
        } else {
          notifyAdmins(par1ICommandSender, "commands.summon.failed", new Object[0]);
        }
      }
    } else {
      throw new WrongUsageException("commands.summon.usage", new Object[0]);
    }
  }
 /**
  * Invoked when disconnecting, the parameter is a ChatComponent describing the reason for
  * termination
  */
 public void onDisconnect(IChatComponent reason) {
   logger.info(this.func_147317_d() + " lost connection: " + reason.getUnformattedText());
 }
Exemplo n.º 24
0
  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;
  }
Exemplo n.º 25
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;
    }
  }
Exemplo n.º 26
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();
    }
  }
Exemplo n.º 27
0
 public static IChatComponent setColour(IChatComponent msg, EnumChatFormatting colour) {
   msg.getChatStyle().setColor(colour);
   return msg;
 }
Exemplo n.º 28
0
 public void func_175188_a(IChatComponent p_175188_1_, boolean p_175188_2_) {
   this.setRecordPlaying(p_175188_1_.getUnformattedText(), p_175188_2_);
 }