Overview
The database system provides:- Automatic connection management with fallback to local storage
- Async player data saving with queue system
- Player movement mode persistence
- Player visibility preference storage
- Automatic table initialization
- Connection validation and error handling
Configuration
Configure database settings inconfig.yml:
config.yml
Configuration Options
enabled
enabled
Enable or disable database integration.Type: Boolean
Default:
Note: If disabled or connection fails, the plugin falls back to PersistentDataContainer storage
Default:
trueNote: If disabled or connection fails, the plugin falls back to PersistentDataContainer storage
host
host
The MySQL server hostname or IP address.Type: String
Default:
Default:
localhostport
port
The MySQL server port.Type: Integer
Default:
Default:
3306database
database
The name of the MySQL database to use.Type: String
Default:
Default:
minecraftusername
username
MySQL user account username.Type: String
Default:
Default:
hubblypassword
password
MySQL user account password.Type: String
Default:
Security: Change this from the default!
Default:
hubblypasswordSecurity: Change this from the default!
Database Schema
Hubbly automatically creates the required tables when it connects. The main table structure:player_data Table
Columns
- uuid: Player’s unique identifier (Primary Key)
- name: Player’s current username
- movement: Player’s movement mode (
NONE, or other custom modes) - visibility: Player visibility preference (
VISIBLE,HIDDEN) - last_seen: Timestamp of last data save
- idx_name: Index on player name for faster lookups
How It Works
Plugin startup
When Hubbly starts,
StorageManager reads the database configuration and attempts to connect.Connection validation
The connection is validated with a 2-second timeout. If successful, tables are initialized.
Fallback on failure
If the connection fails, Hubbly logs a warning and falls back to PersistentDataContainer (local) storage.
Implementation Details
StorageManager
TheStorageManager class handles all database operations:
StorageManager.java
Async Save Queue
Player data is saved asynchronously to prevent blocking the main server thread:StorageManager.java
Loading Player Data
StorageManager.java
Saving Player Data
StorageManager.java
The save operation uses
INSERT ... ON DUPLICATE KEY UPDATE to handle both new players and existing player updates in a single query.Fallback Storage
When the database is disabled or unavailable, Hubbly automatically falls back to using Bukkit’s PersistentDataContainer system. This stores player data locally in the player’s .dat file.Benefits of Fallback
- No data loss: Players can still use features even if the database is down
- Seamless transition: Plugin continues to function normally
- Local persistence: Data is saved per-player and persists across restarts
Limitations of Fallback
- Not cross-server: Data doesn’t sync across multiple servers
- Player-specific: Can’t query all player data easily
- No historical data: No last_seen timestamps or data history
Best Practices
Use a dedicated database user
Create a MySQL user specifically for Hubbly with only the necessary permissions (SELECT, INSERT, UPDATE on the database).
Secure credentials
- Use a strong password
- Set appropriate file permissions on config.yml
- Consider using environment variables for sensitive data
MySQL Setup Guide
Creating the Database
Creating the User
For Remote Connections
If your MySQL server is on a different machine:Troubleshooting
Connection failed
Connection failed
Common causes:
- MySQL server not running
- Incorrect host, port, or credentials
- Firewall blocking connection
- User doesn’t have permission from the connecting host
- Verify MySQL is running:
systemctl status mysql - Check credentials are correct
- Test connection manually:
mysql -h HOST -u USERNAME -p - Check MySQL user host permissions
Table not found errors
Table not found errors
Cause: Tables didn’t initialize automaticallySolution:
- Check server logs for SQL errors during startup
- Verify the database user has CREATE permission
- Manually create tables using the schema above
Data not persisting
Data not persisting
Common causes:
- Database connection failed and fell back to local storage
- Save queue not flushing on shutdown
- SQL errors during save operations
- Check logs for “Falling back to PersistentDataContainer” message
- Verify shutdown method properly flushes the save queue
- Enable debug mode to see detailed save operations
Slow performance
Slow performance
Common causes:
- High network latency to database server
- Inefficient queries
- No database indexing
- Host database on same machine or local network
- Ensure indexes exist (automatically created by Hubbly)
- Consider connection pooling for high player counts
Related Features
- Player Visibility - Uses database to persist visibility preferences
- Movement Items - Movement modes stored in database
- Configuration - General configuration guide