- **Improved `onBlockBreak` Event Handling**:
- Updated the `onBlockBreak` event handler in `PlantListener` to include a database existence check before attempting to remove a record. This ensures that only valid records are removed, preventing unnecessary operations and errors.
- **Database Existence Verification**:
- Added logic to fetch the material associated with the block's location from the database using the `getMaterialAtLocation` method.
- If a corresponding record exists in the database, the record is removed using the `recordRemoval` method.
- If no record is found, the plugin logs a debug message, preventing attempts to delete non-existent records.
- **Improved Debugging Information**:
- Enhanced logging for better debugging, including messages when records are successfully removed or when no record is found for the block being broken.
- **Consistent Record Management**:
- Ensured that the same existence check and removal process are used consistently across various block-related events, including block breaks, explosions, and burning events.
- **Code Refactoring**:
- Refactored the event handling methods to reduce redundancy and improve code readability and maintainability.
- Centralized the logic for database checks and record removal to streamline future updates and bug fixes.
This update enhances the reliability and performance of the plugin by ensuring that database operations are only performed when necessary, reducing potential errors and improving overall efficiency.
EntityExplodeEvent and BlockExplodeEvent: These events are triggered when explosions occur. The event.blockList() method provides a list of blocks affected by the explosion.
handleBlockExplosion method: This method is called for each block affected by the explosion. It performs the same checks and actions as in the onBlockBreak method, ensuring that blocks with growth times are removed from the database.
onBlockBurn Event: This event handler listens for BlockBurnEvent and calls the handleBlockBurn method to handle the block removal.
handleBlockBurn Method: This method performs similar actions as handleBlockExplosion to check if the block has a growth time and then removes it from the database if necessary.
Minor fixes and cleanup
The newly added code changes, allow the plugin to determine the type of mangrove tree to grow, based on a value specified in a configuration file.
Instead of using a fixed number to decide between tall and regular mangrove trees, the plugin now reads this decision-making number from the config.yml file.
This makes it easy to adjust how often each type of tree appears without changing the code.
Added database Maintenance, to ensure there are no old data or duplications, and a Vacuum to shrink the database file, with configurations inside the config.yml file.