Solved Strange Jar Glitch??!?!?

Discussion in 'Plugin Development' started by baighxansgaming, Aug 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    baighxansgaming

    I'm using the same code for json chat in eclipse and intellij, but when i build the artifact in intellij the chat msg looks the same with the color and stuff, but before the color there is a weird A symbol, but it doesnt show up when i export my jar in eclipse? any1 know whats going on? Thanks!

    Here is the Welcome part of code "§cWelcome to the server!"

    https://gyazo.com/f84a2e8591981c384f663911d06d35e6

    See the top one, thats exporting on eclipse, the bottom one is building an artifact in intellij using the EXACT SAME code
     
  2. Offline

    Tecno_Wizard

    SkyleTyler1337 likes this.
  3. Offline

    adam753

    @baighxansgaming
    Probably a character encoding thing caused by having "§" in your code file. The different IDEs may handle non-ASCII characters differently. In any case, you should be using the ChatColor class instead:
    Code:
    player.sendMessage(ChatColor.RED + "This message is red!");
     
  4. Offline

    Tecno_Wizard

    @adam753, I don't think so. I use intellij and never seen this issue.
     
  5. Offline

    Shortninja66

    I use section signs in my JSON and I do not get this. Not sure what could be causing it exactly. Try using ChatColor like @adam753 said.
     
    Tecno_Wizard likes this.
  6. Offline

    baighxansgaming

    @Shortninja66

    @Tecno_Wizard

    Here is the full code of the packets

    Code:
    public void exampleJson(Player player) {
            IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a("{\"text\":\"§cWelcome to the server! \",\"extra\":[{\"text\":\"§bClick here for website!\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"§cClick me! :D\"},\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http://google.com\"}}]}");
            PacketPlayOutChat packet = new PacketPlayOutChat(comp);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }

    @adam753
    I don't think chatcolor works on packets but there might be a json way, but the most efficient is the section sign but its making that symbol >.<
     
  7. Offline

    Konato_K

    @baighxansgaming "efficient" is subjective.

    The problem is that your source file has one encoding, but the default of your system is different (and the Java compiler uses the default by... default), you either have to change the encoding of your file or specify the -encoding option while compiling.
     
  8. Offline

    baighxansgaming

    @Konato_K Well what encoding do i choose ? I'm currently using UTF-8
     
  9. Offline

    mythbusterma

    Depending on your platform and where the files were originally saved, IntelliJ may use a different default encoding.

    That is the correct encoding, but the actual solution to your problem is:

    That constant is defined as being equal to sign character + c and is already compiled for you. Furthermore, it makes your code far clearer.

    Also, I don't see how it's more efficient? If you measure efficiency by character count, I suppose. That is certainly not a good measure of code, however. Readability always comes before brevity.
     
    Konato_K likes this.
  10. Offline

    Tecno_Wizard

    @mythbusterma I can confirm that intellij's default encoding is utf-8
     
  11. Offline

    baighxansgaming

    @mythbusterma Actually you're wrong it was just the encoding. I changed it to ISO-8859-1 and it worked

    @Konato_K thanks for the solution

    @everyoneElse thanks for helping
     
  12. Offline

    mythbusterma

    @baighxansgaming

    It's a JVM flag what encoding should be used. And I still don't understand why you refuse to do this the proper way, but laziness is bliss, I suppose.

    It is also an agreed upon industry standard that source code be saved in UTF-8, so as not to break higher Unicode characters and is far more readable than the \uHHHHHH escape sequences for representing characters in ASCII.


    @Tecno_Wizard

    Re-read my post and think about what you said. On my configuration files default to windows-1252.

    Again, it depends on a lot of factors.
     
    Last edited: Aug 27, 2015
    rbrick likes this.
  13. 1. No, ChatColors don't work like this in json. They work like this:
    Code:
    {text:\"Welcome to the server!\",color:gold,extra:[{text:"..."}]}
    2. You need to change your compiler encoding settings to UTF-8
    3. If you like to make those json text much simpler you can try out my JsonBuilder class:
    Code:
    JsonBuilder jb = new JsonBuilder("§cWelcome to the server! ").parse("§bClick here for website!")
    .withHoverEvent(HoverAction.SHOW_TEXT, "§cClick me! :D")
    .withClickEvent(ClickAction.OPEN_URL, "http://google.com");
    jb.sendJson(player);
    I'm not sure if the colors work for the hover event but try it out. The rest is made so it parses & adds the § characters to ,color:xxxxxx to the last segment added to the json.
     
  14. Offline

    teej107

    @FisheyLP Funny enough, ChatColors still work in JSON text.
     
  15. Offline

    meguy26

    @teej107
    True, but I think @FisheyLP was reffering to the fact that chat JSONs can have a "color" key, and that is certainly a readable/proper way to add color to JSONs, as opposed to directly inside the "text" key...
     
  16. Offline

    teej107

     
  17. I meant they are suppossed to be the color tag/key because you can't even use the § character ingame. But with plugins or modifications you can use it if you like..
     
Thread Status:
Not open for further replies.

Share This Page