1.8 - 1.13 Enum Compatabilty

Discussion in 'Spigot Plugin Development' started by abandoncaptian, Aug 12, 2018.

  1. I'm working with potion effects in a plugin that is 1.8 - 1.13 compatible. When I add in the External Jars I get the PotionEffectType for the main first version (1.8) that's fine but say a server is running on 1.13 only. I'm wanting to be able to interact with 1.13 potion effects too while another server could be running 1.8 and they both use the same jar. How do I make it so I can use the 1.13 potion effects if the server is 1.13 while maintaining support for all versions if applicable?
     
  2. The way I ended up doing it for this is checking if the server is 1.13 ( getServer().getVersion().contains("1.13") but for future 1.13 versions, I wouldn't do this, it's just to make things a bit simpler) and if so, use PotionEffectType#getByName("1.13-potion-effect-here"). However that's just my best guess considering I haven't worked with potions, but had to make it so that skull items can be accessed in both 1.8-1.12.x as well as 1.13 at the same time, so in the meantime, it's the same concept.
     
    1. Add a try/catch case. This will make sure that even if methods are removed/enums are removed, the code can still run.
    2. Inside the try, try to get the 1.13 material. You can do this either by getting the enum instance, or by using a "getByName"/"valueOf" call. If the server is on a lower version, it will go straight to the catch. Note that this will support 1.13 and all versions higher (*as long as they have this enum value)
    3. In the catch, then try to get the 1.12- enum value, either getting the instance (if you build off of 1.12-) or by using valueOf.
     
  3. Ok thank you that's what I kind of figured I just wanted to ask.
    Also just a quick question too when I add external jars should I add all the versions 1.8 - 1.12?
     
  4. I'd say if you're using anything like NMS, yes, but if not, I don't think it's a major concern.