Block Regeneration (Delayed and Random), supporting server restarts...

Discussion in 'Plugin Development' started by GeekyCompz, Jun 29, 2016.

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


    Here is my current GitHub project (if you would like to help optimize; I'm a beginner [kind of]):

    Now a huge feature we wish to implement is when blocks are placed/broken or an explosion destroys blocks. These blocks are to be regenerated back randomly after said duration (configurable, default 12 hours). ONLY REGENERATED BACK IF THE BLOCK IS IN AN ACTIVE WAR CLAIMED LAND (EXCLUDING CHESTS ITEMS).
    However, our server restarts, thus the blocks would need logging and possibly a timer that checks if 12 hours had passed since a block was edited.

    =------ Off-Topic -------=

    This plugin integrates into Factions and allows for wars to be declared and logged.
    So far these features work:
    - Declaration
    - Accept/Deny
    - Forfeit
    - Cancel
    - End (both factions agree on a winner)
    - War statistics logging (faction k/d, and individual player stats)
    - Looking up previous war logs.
  2. Offline


    What is your issue? You don't clearly state what your problem is, nor do you show the code related to your problem.
  3. Offline


    @Zombie_Striker I basically have no clue how to efficiently and effectively store the blocks for regeneration after 'x' amount of time. Alongside this, how would I randomly regenerate the blocks back?
  4. Offline


    1. Create an object for storing a "snapshot" of the blocks that need to be restored.
    2. Create an List or set of all the blocks you want to regenerate.
    3. Create a repeating task, that will regenerate a block after __ ticks
    4. If you want it to be random, use ThreadLocalRandom to get a random number, and test if that random number is equal to zero. If so, then do the next step. This means it will not always restore a block every set amount of time.
    5. Get a random block from the set, and restore the snapshot.
    6. In the onDisable, save the snapshots and the blocks to a Config. In the onEnable, get the snapshots and blocks from the config, and restore the repeating task.
Thread Status:
Not open for further replies.

Share This Page