1.15.2 Saving location to database with id

Discussion in 'Spigot Plugin Development' started by Iwitrag, Feb 10, 2020.

  1. Iwitrag



    I'm developing a plugin, where I need to store bukkit Location into DB (no json nor yml... I want to use MySQL).

    Locations will be saved to separate table. Location table will have ID as primary key and I need to include that ID with instance itself (for joins and foreign keys without extra queries to get ID).

    My question is what would be the best way to achieve this...

    a) Create something like LocationManager with all Locations with their IDs.
    b) Create wrapper class MyLocation with ID field and with reference to original Location.
    c) Extend Location and use that everywhere instead.
    d) Something else

    Thank you
  2. Iwitrag


    Do you think that b) is better than c) ?

    Because with c) you can use that new class directly in places where Bukkit Location is needed.
    But with b) you need to type loc.getLocation() every time.
  3. I think that's probably only gonna be an issue during start-up and shut down (and maybe some intermediate steps).
    Personally, I don't like extensions; but that's up to everyone's personal preference. Using b), you have the option to better control and have the ability to use inheritance and that good stuff.
    But again, I think this is a personal preference
  4. Iwitrag


    Yeah you are probably right.

    Also I would not be able to do that with interfaces... I could extend CraftBukkit class in these cases but then my plugin would become version-dependent.