Best practices for plugin development

Discussion in 'Plugin Development' started by DevClimber, Mar 17, 2024.

  1. Offline

    DevClimber

    Hello,
    I am new to this plugin development world and have a few questions. I tried some fun things on my server but I am not sure about the way I am doing them. Here are the questions:
    1. There are a lot of plugins already existing. For a complex server I end up using 20 or 30 of them. I am worried it might cause lag. Is it a good idea (it will take time) to integrate the functionalities in my custom plugin ?
    2. This question is linked to the first one : should I build a single plugin with everything I need or one per function.
    3. More technical : the scheduler is nice, is it better to run all my functions in the next ticks ?
    4. I'd like to access data from my plugin. Can I use it as a web server backend or should I share the data any other way ?
    5. I would like to count the number of minerals broken with a given pickaxe. I am actually usings nbts and rerendering the item every time. Is there other ways to do it ?
    6. I am adding data to the player using getEntityData on the player, is it okay or does it have flaws ?
    7. I need to store data (for instance the waiting rewards,when players are offline at the time a weekly game ends), what would you use for that ? Database, file, ORM, local or remote ? SQLite is quite slow and seems wrong in my architecture.
    8. I need something to be done every Sunday at noon. Do I start a scheduler at every boot or should I use an external cron or systemd timer to send a command ?
    This is a lot and maybe there is no right or wrong way to do it, but I'd to see what and how I could improve what I am doing :)
    Thanks for reading !
     
  2. Online

    timtower Administrator Administrator Moderator

    @DevClimber
    1. How will having multiple plugins cause lag? The server sleeps every tick anyways
    2. Depends on how big the function is, if it is a big thing: make it its own plugin, for smaller things you can make a collection
    3. Why would you run it on the next tick?
    4. What kind of data, from where do you want to access it?
    5. Probably, but are you worried about it? Giving the pickaxe an UUID and saving it in the plugin could also work.
    6. Should work fine.
    7. Why does SQLite seem wrong? How much data is it? How long do you need to store it? Normally file storage is fine.
    8. What do you need to do there?
     
  3. Offline

    DevClimber

    @timtower thanks :)
    1. Every plugins listens to the same events and adds its own code. It is adding complexity, so I don't see how it could not add lag at some point.
    2. Thanks
    3. That's a good question, if I need it later, then I'll now I have to use the scheduler I guess
    4. The idea was to extract stats from the server and display them in an interface.
    5. Re-rendering the item is sometimes slow can be seen by the player
    6. Thanks
    7. I don't have enormous amount of data, but it seems wrong because I always filter by world/player/item and I feel like I should access it through java objects
    8. Launch a few commands basically, to reset ladders and give a few items. I can create a custom command and put the logic in the command and call it from systemd/cron or call a function with the scheduler
     
  4. Online

    timtower Administrator Administrator Moderator

    @DevClimber 1. If you encounter lag from that: sure, then do it. But in the end the amount of code being called will be exactly the same.
    4. What kind of stats? How often do they update? What kind of interface? Could just write it to a database.
    5. Then try the UUID way
    7. Should not access that data every time you need it, you load it in memory at start, and save it when it updates.
    8. Scheduler works fine, just run it ... time, or delay by time till actual moment / 2
     
  5. Offline

    ChaceUnderwood

    Integrating functions into one plugin or creating separate ones depends on the server. Running functions in the next ticks can optimize the load. To access plugin data, you can use a back-end web server or other data transfer methods. Mineral counting can be improved through the database. Using getEntityData on a player is fine, but there are other methods as well. To store data, consider a database or local storage. A scheduler for doing things at specific times can be handy.
     
  6. Online

    timtower Administrator Administrator Moderator

    @ChaceUnderwood How would running functions in next ticks optimize the load?
    And you say that mineral counting can be improved through the database, how would that work?
     
  7. Offline

    ChaceUnderwood

    Hmm. You'll need to set up this special digital system where you can store info about where you find different minerals and how many there are. Then, you'll need to figure out a way to gather this data. You can either do it yourself by typing it in, or you can use some cool tech stuff to automatically do it for you while you play. Playing with friends on a server, connect the database to the game so it updates in real-time. That way, everyone can see what's going on with the minerals.
     
  8. Online

    timtower Administrator Administrator Moderator

    So your claim that it would be improved is based on nothing?
    The "some cool tech stuff" would be this very plugin.
     

Share This Page