Map of material name conversions between versions?

Discussion in 'Plugin Development' started by DutchJellyV2, Jun 18, 2020.

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

    DutchJellyV2

    Hello coders,

    I'm struggeling with the change of type names of the materials in the Spigot and Bukkit API. Does anyone have a map of all the conversions so I can simply get the proper material by doing something like:
    Code:
    public static Material getMaterial(String name){
        try{
            return Material.byName(newerMaterials.get(name));
        }catch(Exception e){
            return Material.byName(olderMaterials.get(name));
        }
    }
    
    Maybe there's other ways to map the change in type names, but maybe this'd work. Does anyone have any map of the changes to help me move forward? I'll gladly post the function for getting a material across versions if someone could help me out with this.

    And for everyone out there with struggles with the type changes regarding colors, this is how I solved that.

    Code:
    public static ItemStack getColoredItem(String name, DyeColor color){
      try{
         return new ItemStack(Material.valueOf(color.name() + "_" + name));
      }catch(Exception e){
        try{
          return new ItemStack(Material.valueOf(name), 1, color.getDyeData());
        }catch(Exception e2){ }
      }
      Messenger.Message("Could not create item with type " + name + " and color " + color.name());  
      return null;
    }
    
     
    Last edited: Jun 18, 2020
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    DutchJellyV2

    My config files that I want to use will contain info about GUI items, and I'd like to make sure that these files work in all versions so I can just copy them over from the jar into the plugin folder without compiling different versions. I also think it's just a pain to mess around with the different type names when it comes down to config files. Bottom line: I just don't want to create different config files for all the different versions.
     
Thread Status:
Not open for further replies.

Share This Page