1.15.2 Passing bungeecord plugin config to spigot plugin

Discussion in 'Spigot Plugin Development' started by Cubixor, Jan 15, 2020.

  1. Hi, I have a problem with sending bungeecord plugin config to spigot server, and getting values from it. I used these tutorials:
    https://www.spigotmc.org/wiki/using-the-bungee-configuration-system/ https://www.spigotmc.org/wiki/sending-a-custom-plugin-message-from-bungeecord/
    and send the configuration by my messaging channel that way:

    Bungeecord (conf is my bungeecord plugin configuration):
    Code (Java):
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    String output = gson.toJson(conf);
    out.writeUTF(output);
     
    Spigot (config is Configuration type variable):
    Code (Java):
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();
    String json = in.readUTF();
    config = gson.fromJson(json, Configuration.class);
    Everything works fine, bungeecord is sending config, spigot receive it and I can get it's values from spigot using for example config.getInt("c"). But when I try to use getSection() method in spigot (for example config.getSection("a").getInt("b")) it cause error:
    Code (Text):
    java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to net.md_5.bungee.config.Configuration
    It happens only when using getSection() method, and only in spigot. When I try to use it on bungeecord it works.
     
  2. Did you compare the JSON BungeeCord receives with the JSON your Spigot server receives? If it works in one case this may give enough information to solve the problem.

    Otherwise try to simplify the configuration as much as possible and check if the error still occurs. If no, start rebuilding it step by step and check after each step if your last change causes the error.
     
  3. I've checked it and the problem is because of this parsing to json. When I get config directly from variable it works but when I convert it to json and again to Configuration variable there is this error (everything tested on bungeecord, without sending it to spigot server):
    Code (Text):
    java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to net.md_5.bungee.config.Configuration
    So how to repair this JSON parsing or send custom plugin message via bungeecord in the other way?


    EDIT: Okay, I know where the problem is. So I saved this parsed and unparsed config to another file and discovered that this:
    Code (Text):
    section1:
      section2: "test"
    changed to this:
    Code (Text):
    section1:
      self:
        section2: "test"
    So why there is this "self" section and how to prevent it's creation?
     
    #3 Cubixor, Jan 15, 2020
    Last edited: Jan 15, 2020