CodeRandomCore
当前版本 v1.0.0-1.21
CodeRandomCore 是一个 Bukkit 插件,旨在管理 Minecraft 服务器的各个方面,包括玩家 UUID、MySQL 数据库交互以及消息工具。本指南将帮助您设置和使用该插件提供的 API。
目录
安装
- 下载 CodeRandomCore 插件的最新发布版本。
- 将插件 JAR 文件放入服务器的
plugins 目录中。
- 启动您的 Minecraft 服务器以生成默认配置文件。
配置
该插件使用位于 plugins/CodeRandomCore/config.yml 的配置文件。以下是 MySQL 配置部分的示例:
MySQL:
enabled: false
host: localhost
port: 3306
database: code_random
username: root
password: ""
配置选项
enabled: 设置为 true 以启用 MySQL 支持。
host: 您的 MySQL 服务器的主机名或 IP 地址。
port: 您的 MySQL 服务器的端口号(默认为 3306)。
database: 要使用的数据库名称。
username: MySQL 连接的用户名。
password: MySQL 连接的密码。
用法
UUID 管理
CodeRandomCore 提供了用于管理玩家 UUID 的工具,特别是针对使用 Floodgate 的基岩版玩家。
获取 UUID
要获取玩家的 UUID:
UUID uuid = UUIDFetcher.getUUID("playerName");
此方法将自动确定玩家是基岩版玩家、在线玩家还是离线玩家,并相应地获取 UUID。
MySQL 和 JSON 文件管理
该插件使用 HikariCP 来管理 MySQL 连接。
初始化 MySQL
确保在 config.yml 文件中启用了 MySQL。MySQLManager 类管理连接池:
MySQLManager mysqlManager = MySQLManager.getInstance();
if (mysqlManager.connect()) {
// 连接成功
} else {
// 连接失败
}
执行查询
要执行查询:
String query = "SELECT * FROM players";
try (ResultSet rs = mysqlManager.executeQuery(query)) {
while (rs.next()) {
// 处理结果集
}
} catch (SQLException e) {
e.printStackTrace();
}
消息工具
该插件提供了向玩家发送格式化消息的工具。
发送消息
要发送格式化消息:
MessageUtils.formattedMessage(player, "Your message here");
要发送带有标题和行的消息:
MessageUtils.messageWithTitle(player, "Title", "Line 1", "Line 2" ...);
标题工具
要向玩家发送标题:
TitleUtils.title(player, "Main Title", "Subtitle", 20, 100, 20);
这将显示一个标题,淡入时间为 20 刻,停留时间为 100 刻,淡出时间为 20 刻。
动作栏工具
要发送动作栏消息:
ActionBarUtils.actionBar(player, "ActionBar Message", 60);
这将显示持续 3 秒(60 刻)的动作栏消息。
许可证
本项目采用非商业许可,但允许 API 使用例外。详情请参阅 LICENSE 文件。
CodeRandomCore
Current version v1.0.0-1.21
CodeRandomCore is a Bukkit plugin designed to manage various aspects of a Minecraft server, including player UUIDs, MySQL database interactions, and messaging utilities. This guide will help you set up and use the API provided by the plugin.
Table of Contents
Installation
- Download the latest release of the CodeRandomCore plugin.
- Place the plugin JAR file in your server's
plugins directory.
- Start your Minecraft server to generate the default configuration files.
Configuration
The plugin uses a configuration file located at plugins/CodeRandomCore/config.yml. Here is an example of the MySQL configuration section:
MySQL:
enabled: false
host: localhost
port: 3306
database: code_random
username: root
password: ""
Configuration Options
enabled: Set to true to enable MySQL support.
host: The hostname or IP address of your MySQL server.
port: The port number of your MySQL server (default is 3306).
database: The name of the database to use.
username: The username for the MySQL connection.
password: The password for the MySQL connection.
Usage
UUID Management
CodeRandomCore provides utilities for managing player UUIDs, especially for Bedrock players using Floodgate.
Fetching UUIDs
To fetch a player's UUID:
UUID uuid = UUIDFetcher.getUUID("playerName");
This method will automatically determine if the player is a Bedrock player, an online player, or an offline player, and fetch the UUID accordingly.
MySQL and JSON File Management
The plugin uses HikariCP for managing MySQL connections.
Initializing MySQL
Ensure that MySQL is enabled in your config.yml file. The MySQLManager class manages the connection pool:
MySQLManager mysqlManager = MySQLManager.getInstance();
if (mysqlManager.connect()) {
// Connected successfully
} else {
// Connection failed
}
Executing Queries
To execute queries:
String query = "SELECT * FROM players";
try (ResultSet rs = mysqlManager.executeQuery(query)) {
while (rs.next()) {
// Process the result set
}
} catch (SQLException e) {
e.printStackTrace();
}
Messaging Utilities
The plugin provides utilities for sending formatted messages to players.
Sending Messages
To send a formatted message:
MessageUtils.formattedMessage(player, "Your message here");
To send a message with a title and lines:
MessageUtils.messageWithTitle(player, "Title", "Line 1", "Line 2" ...);
Title Utilities
To send titles to players:
TitleUtils.title(player, "Main Title", "Subtitle", 20, 100, 20);
This will display a title with a fade-in time of 20 ticks, stay time of 100 ticks, and fade-out time of 20 ticks.
ActionBar Utilities
To send an action bar message:
ActionBarUtils.actionBar(player, "ActionBar Message", 60);
This will display an action bar message for 3 seconds (60 ticks).
License
This project is Non-Commercial License with API Usage Exception. See the LICENSE file for details.
评论 0
登录后参与评分
还没有评论,来抢沙发吧