Solved Sound.NOTE_PLING 1.8.8

Discussion in 'Spigot Plugin Development' started by WAS, May 17, 2017.

  1. WAS

    WAS

    I'm confused. Someone is getting the following on 1.8.8, where my IDE is telling me BLOCK_NOTE_PLING is wrong and to use NOTE_PLING with 1.8.8 API.

    Code (Text):
    [16-05-2017 19:29:18] Could not pass event AsyncPlayerChatEvent to WeChat v0.3.5 BETA
    [16-05-2017 19:29:18] org.bukkit.event.EventException
    [16-05-2017 19:29:18] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:18] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:18] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:18] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:18] at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1084) [custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:18] at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1022) [custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:19] at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:19] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_65]
    [16-05-2017 19:29:19] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_65]
    [16-05-2017 19:29:19] at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_65]
    [16-05-2017 19:29:19] at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_65]
    [16-05-2017 19:29:19] at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
    [16-05-2017 19:29:19] Caused by: java.lang.Error: Unresolved compilation problems:
    [16-05-2017 19:29:19] NOTE_PLING cannot be resolved or is not a field
    [16-05-2017 19:29:19] NOTE_PLING cannot be resolved or is not a field
    [16-05-2017 19:29:19] at wa.was.wechat.events.ChannelMessages_1_8_R3.onAsyncChat(ChannelMessages_1_8_R3.java:115) ~[?:?]
    [16-05-2017 19:29:19] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
    [16-05-2017 19:29:19] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
    [16-05-2017 19:29:19] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65]
    [16-05-2017 19:29:19] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_65]
    [16-05-2017 19:29:19] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[custom.jar:git-Spigot-db6de12-18fbb24]
    [16-05-2017 19:29:19] ... 11 more

    [​IMG]

    Naturally, if I apply any version 1.9+ Sound.NOTE_PLING Is wrong, and I need to use Sound.BLOCK_NOTE_PLING. Any ideas why this person is receiving this error?

    If this is a issue, I don't see how to resolve it as I'm not sure how to detect this exact version over any others as it only comes up as 1_8_R3.
     
  2. That's actually a compilation error, not a unknown field error.

    You compiled your code with a 1.9+ JAR instead of compiling with 1.8.X.
     
  3. WAS

    WAS

    It's compiled with 1.12 actually, yeah. And the versioning is only loading ChannelMessages_1_8_R3.class which specifically only references to 1.8.8, and prior

    I followed tutorials on NMS on different versions, so I'm not sure how to compile a single jar for multiple servers, then. You'd think the code running the jar would know the reference as the point of referencing the API, no? o_O Other references to other versions don't complain.For example, you'd think all the 1.7.10 - 1.8.8 references would be complaining on 1.9+

    Doesn't make sense how people could ever achieve cross-compatibility when you can compile and get references to one API JAR in build paths at a time... What am I missing then?
     
    #3 WAS, May 17, 2017
    Last edited: May 17, 2017
  4. As far as I know for Sound fields you can't do what you are doing.

    You need to do this: Sound.valueOf("NOTE_PLING") instead of directly referencing the field.

    When compiling, Java will use the first JAR that has the Sound class (in your case, 1.12) causing the compiler to change the code to throw an error since the Sound.NOTE_PLING doesn't exist in 1.12.
     
  5. WAS

    WAS

    Why don't, than, 1.7.10 - 1.8.8 references complain in 1.9+? There should be compilation errors regarding NOTE_PLING and not being BLOCK_NOTE_PLING, and vise-versa.

    All sorts of confused. Also using valueOf will still throw an error, so how good of a replacement is that? I'd probably have to use lang3 enum tools.
     
  6. Choco

    Moderator

    They do. The Sound enum was changed completely after the 1.9 update. People often use this to achieve cross-compatibility, but why try adding support for 1.8 when it's a 3 y/o version? If it's too much of a hassle to support, don't do it. The only reason I would ever support anything lower than 1.11.2 is if I'm using NMS and I have no choice but to abstract it for future versions (which is exactly what I did for VeinMiner)
     
  7. ¯\_(ツ)_/¯

    That's what I think it is happening.
     
  8. WAS

    WAS

    Well I mean... they don't. I use my plugin every day. Lol There is no compilation error regarding Sound.BLOCK_NOTE_PLING for 1.7.10 - 1.8.8 lol

    He is on 1.8.8 and getting the error for a Enum that does exist for him.

    So instead I should globally define my sound. If NOTE_PLING doesn't exist, attempt to use BLOCK_NOTE_PLING

    Also I'd love to only support modern versions, but it seems the constant requests for the support is more tiresome than supporting it. Lol
     
  9. Choco

    Moderator

    Irrelevant. Listen to me for once rather than speaking because you tend to do that a lot. I'll do it slowly:

    Server running 1.8:
    - If your plugin is compiled using the Sound constants from Spigot 1.8, it will run perfectly fine
    - If your plugin is compiled using the Sound constants from Spigot 1.9+, it will throw the error you are having at the moment because the sound constants were changed from 1.8 -> 1.9

    Server running 1.9+:
    - If your plugin is compiled using the Sound constants from Spigot 1.8, it will throw the error you are having at the moment because the sound constants were changed from 1.8 -> 1.9
    - If your plugin is compiled using the Sound constants from Spigot 1.9+, it will run perfectly fine

    There's no way around this other than to use the class I linked above. Sound constants were changed in 1.9, that's that... you really can't change it. It was in need for a rewrite, and we got one ;)
     
  10. WAS

    WAS

    Err what?

    Or just (taking into considering you are working with 1.7.10+)

    Code (Java):
        if (EnumUtils.isValidEnum(Sound.class, "NOTE_PLING")) {
           globalSound = Sound.valueOf("NOTE_PLING");
           channelSound = Sound.valueOf("NOTE_PLING");
         } else {
           globalSound = Sound.valueOf("BLOCK_NOTE_PLING");
           channelSound = Sound.valueOf("BLOCK_NOTE_PLING");
         }
    Also that doesn't explain why there is no compilation error for -1.8.8 invalid enums when compiled with 1.12. Can you try again? Seems perfectly logical as Sound.NOTE_PLING doesn't exist? Instead of making derogatory comments, reply with an answer to the actual question.
     
    #10 WAS, May 17, 2017
    Last edited: May 17, 2017
  11. Choco

    Moderator

    If you're doing that for every sound you want to play, it's going to get rather cluttered and the class I linked above would make it as easy as:
    Code (Java):
    // The class I linked
    player.playSound(Sounds.NOTE_PLING.bukkitSound());

    // Compared to your method of...
    Sound sound;
    if (EnumUtils.isValidEnum(Sound.class, "NOTE_PLING")) {
        sound = Sound.valueOf("NOTE_PLING");
    } else {
        sound = Sound.valueOf("BLOCK_NOTE_PLING");
    }

    player.playSound(sound);
    It makes absolutely no sense whatsoever for there not to be an error for that. If you're not receiving an error, then I can give you no logical explanation. You're running some really screwed up server.
     
  12. WAS

    WAS

    More derogatory comments.

    It's a freshly built Spigot 1.12 pre2 with only WeChat and WorldBorder for testing. lmfao. I guess you're suggesting Spigot is screwed up. As people can only build it with BuildTools.
     
  13. Choco

    Moderator

    It was not a derogatory comment, it was a statement. Not once did I say "Spigot is screwed up", nor did I even imply it. Look... I gave you a class that fixes your issue, either you use it or you don't. Not my problem if you don't, and continue to get complaints. This thread has gone on about 6 replies too many.
     
  14. WAS

    WAS

    I've already fixed the issue with my own code, as there is only two sounds in question and no need for a class. This can be done inside the versioning method.

    And you apparently do not know what derogatory is.

    When you should be assuming people are running the software you endorse, and can only be obtained through BuildTools. Lol
    When you're the one that didn't understand the question to explain it. It seems to go both ways.
     
    #14 WAS, May 17, 2017
    Last edited: May 17, 2017