Having problems or questions? Join our discord server.
ServerDataAPI
is designed to provide detailed information about your Minecraft server through multiple API endpoints. This plugin allows administrators to access real-time data, such as player statistics, world information, and general server status. You can choose to store data using MySQL or SQLite, configurable in the config.yml file
.
Key Features:
- Supports both MySQL and SQLite, configurable in config.yml.
- Real-time information on online players, worlds, and server statistics.
- Customizable rate limits to protect your API from abuse.
- Built-in caching system to enhance performance and reduce database queries.
- Support for HTTPS, allowing you to secure API communications by enabling HTTPS in config.yml with your SSL certificate.
- Option to control which domains or IP addresses can access your API through the allowed_origins configuration. This adds an extra layer of security by restricting cross-origin requests to only trusted sources.
- Easy-to-use API endpoints for retrieving server information
Installation Guide
- Download the plugin and place it in your plugins folder.
- Start the server to generate the config.yml file.
- Edit config.yml to configure the port, the database (MySQL or SQLite), set rate limits, and adjust other parameters.
- Configure API access by specifying allowed origins to control which domains or IPs can interact with the API.
- Restart your server, and the plugin is ready to use.
API Endpoints
(All the methods are
GET)
/players
Retrieves a list of all online players, including details like their name, UUID, IP address, and health status.
/player/:name
Fetches information about a specific player (whether online or offline). If the player is online, it includes their real-time data such as health, location, experience, and level. If the player is offline, it fetches the data from the database.
/server-status
Provides the current status of the Minecraft server, including server version, the number of online players, max players allowed, whitelist status, and the server's uptime.
/whitelisted-players
Returns a list of all players who are whitelisted on the server, with their name and UUID.
/banned-players
Returns a list of all players who are banned from the server, including their name and UUID.
/worlds
Retrieves details about all loaded worlds on the server, including the world name, environment type, number of players, number of entities, and the current time in the world.
/online-player-count
Returns the total number of online players and the maximum number of players that the server can handle.
Example of use in a discord bot:
Code (Text):
const { Client, GatewayIntentBits } = require('discord.js');
const axios = require('axios');
// Your Discord bot token and API URL
const BOT_TOKEN = 'YOUR_DISCORD_BOT_TOKEN';
const API_URL = 'http://localhost:4567'; // Replace with your Minecraft API URL
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('messageCreate', async message => {
// Ignore bot messages and only respond to "!players" command
if (message.author.bot || message.content !== '!players') return;
try {
const response = await axios.get(`${API_URL}/players`);
const players = response.data;
if (players.length > 0) {
message.channel.send(`Online players: ${players.map(p => p.name).join(', ')}`);
} else {
message.channel.send('No players are online.');
}
} catch (error) {
message.channel.send('Error fetching players from the server.');
}
});
client.login(BOT_TOKEN);
How It Works:
- Command: The bot listens for the !players command.
- Response: It makes a request to the /players endpoint of your Minecraft API.
- Result: If players are online, it sends their names to the Discord channel. If no players are online, it tells the user.
Thank you for using our plugin! We hope it helps enhance your Minecraft server experience. Your support means a lot to us, and we're always striving to improve. If you have any feedback, suggestions, or if you'd like a custom endpoint, feel free to contact us at our
Discord. Happy gaming, and thanks again from the team at
Lomihost.com!