Resource MaterialBridgeAPI

Discussion in 'Spigot Plugin Development' started by NJDaeger, Jul 24, 2018.

  1. Link: https://github.com/NJDaeger/MaterialBridgeAPI

    Overview:

    The MaterailBridge API is meant to be a bridge between Pretechnical and Technical+ versions of Minecraft. The point of this API is to allow plugin developers use it and let their plugin be compatible with both 1.12.x and 1.13.x. This API isn't near complete as of yet, but when it is, it should bring the 1.13 Material API to Pretechnical versions allowing easier editing and use of materials.

    Usage:
    The MBAPI (once finished) will allow developers to use one API for two different versions of Minecraft. An example usage is here:
    Code (Text):
    Slab slab = Material.ACACIA_SLAB.get();
    slab.setType(SlabType.TOP);
    slab.setBlock(new Location(0, 0, 0));
    One thing you might notice with this example is how I don't need to cast Material#get() to Slab. The reason behind this is because the provided Material class is not an enum, which in return allows me to add generics to the materials. This is how the Acacia Slab is registered in the class:
    Code (Text):
    public static final Material<Slab> ACACIA_SLAB = new Material<>(Slab.class, "WOOD_STEP", "ACACIA_SLAB", "wooden_slab", "acacia_slab", new LegacyData(126, 4));
    Rather than having to create BlockData and cast it to its respective type, we automatically know the type upon usage.

    If you don't plan on placing a block you can just use this API to get the correct Bukkit material as well. An example of this is shown below:
    Code (Text):
    org.bukkit.Material carpet = Material.BROWN_CARPET.asBukkit();
    This gets you the straightforward Bukkit Material API material.

    Useful Methods:
    Becuase this class is not an enum, you may be wondering if I provide alternatives to the enum methods such as "valueOf" and "values." In short, yes I do provide those methods. In addition to those, I also provide a Material#of(org.bukkit.Material bukkitMaterial) method for a quick transformation from Bukkit materials.

    Finishing note:
    This API is very very WIP. It's definitely not ready for production use. Writing this API by myself is a very tedious process and I could really use some help on this. If you'd like to help me on this, please consider submitting a PR to the GitHub page. It will be very appreciated.

    In addition; just installing this API will not magically make your plugin work for the desired version. The plugin must be written with this API in order to work on the desired multiple versions.
     
    • Winner Winner x 1
    • Useful Useful x 1
  2. Heyo,
    I've seen a few people having trouble with converting material names in their config files, could you possibly make an online resource tool to give the new material name when you put in an old material name?
     
  3. Rather than doing that, I could make a method in this API which would convert it over to the proper type. Although it may not be entirely accurate if they dont provide any of the metadata along with the given material.
     
  4. Nice resource! IIRC Oracle was planning on adding generics to enums. :unsure:
     
  5. I would love it if they did. At the point they do, though, I assume this API will be close, if not completed, by then. I really wish they had it :(
     
    • Useful Useful x 1
    • Useful Useful x 1
  6. This seems all well and good, but rather useless in an API seeing as the conversion will only need to happen once! I think people who aren't able to code would want a tool to convert all instances of old material names in a file to new ones. This would be great if you could make this into a downloadable tool for people to use.