1.13 Material.values() returns 1.12 materials?

Discussion in 'Spigot Plugin Development' started by Hex_27, Jul 21, 2018.

  1. Code (Java):
    public void onEnable(){
            Bukkit.getLogger().info("==================================");
            Bukkit.getLogger().info("");
            Bukkit.getLogger().info("");
            Bukkit.getLogger().info("");
            for(Material mat:Material.values()){
                try(FileWriter fw = new FileWriter("myfile.txt", true);
                        BufferedWriter bw = new BufferedWriter(fw);
                        PrintWriter out = new PrintWriter(bw))
                    {
                   
                        out.println(mat.toString() + "(Material." + mat.toString() + "),");

                    } catch (IOException e) {
                        //exception handling left as an exercise for the reader
                    }
           
            }
            Bukkit.getLogger().info("");
            Bukkit.getLogger().info("");
            Bukkit.getLogger().info("");
            Bukkit.getLogger().info("==================================");
        }
    The above code runs in a 1.13 server. But what gets written to the file is 1.12 materials (Material.WOOD, etc). Am I doing something wrong?
     
  2. gzx

    gzx

    Do you have
    Code (Text):
    api-version: 1.13
    set in your plugin.yml? If not, Spigot uses a compatibility layer to retain compatability with 1.12 plugins, which will also affect the output of Material#toString().
     
  3. I assume you are running without 'api-version: 1.13' inside your plugin.yml? In that case your calls to Material#toString and Material#name() will be replaced with calls to corresponding methods inside CraftLegacy, which remove the 'LEGACY_' prefix from the legacy material's name.

    Edit: ninja'd
     
  4. Woa. Didn't know that exists. Will try changing it
     
  5. Wait a moment, doesn't that mean all plugins need to do to run in 1.13 is turn api-version to 1.12? Does that mean we can compile in 1.12 (despite being unable to compile in 1.13), and still be able to run the plugin in 1.13?
     
  6. gzx

    gzx

    In most cases, yes, although there's a lot of overhead associated with it because Spigot needs to do bytecode manipulation to get that to work.
     
    • Like Like x 1
    • Informative Informative x 1