注意:原版插件及几乎所有开发工作均由 croemmich 完成。由于他已无暇继续维护,因此授权我来负责此插件的维护工作。
OnlineUsers 是一个简单的插件,用于通过扁平文件(flatfile)或 MySQL 表来记录在线用户。如果选择使用 MySQL,请确保安装 MySQL JDBC 驱动程序。您可以从以下地址获取:
您只需将其放入服务器根目录,与 CraftBukkit jar 包放在同一位置即可。它需要被命名为 mysql-connector-java-bin.jar。或者,如果您了解相关操作,也可以将其添加到您的 Java 路径中。
online-users.properties
- destination=mysql #[mysql|flatfile]
- flatfile=online_users.txt #要写入的扁平文件位置
- flatfile-template=online_users.template #用于创建扁平文件的模板
- flatfile-data=online_users.data #用于填充扁平文件的数据
- remove-offline-users=true #设置为 false 可在用户下线后仍保留在表中。
- db=jdbc\:mysql\:localhost\:3306/minecraft
- user=root
- table=users_online#插件启用时会自动为您创建
- pass=root
请注意,新的 `time_total` 列仅在玩家断开连接时更新。因此,如果某玩家当前处于在线状态,该列将不会计入其当前会话中额外增加的时间。如果您希望获取其在线时长的完全最新数值,可以在查询中进行相应计算。
例如,以下查询可为您提供最新的 `current_time_total` 值:
SELECT *, IF(`online`=1, `time_total` + TIMESTAMPDIFF(SECOND, `time`, NOW()), `time_total`) AS `current_time_total` FROM `users_online`
如果您使用的是早于 1.6.2 的版本,由于 `time_total` 的数据类型不同,查询语句应如下所示:
SELECT *, IF(`online`=1, ADDTIME(`time_total`, TIMEDIFF(NOW(), `time`)), `time_total`) AS `current_time_total` FROM `users_online`
此处提供了一个读取此插件输出文件的 PHP 脚本示例。
更新日志
- 1.8.0 - 现在数据库中跟踪并记录玩家 UUID 作为唯一键,并在每次登录时更新玩家名称(以防名称发生变更),从而确保在线时长正确关联到唯一的玩家账户,而非(即将变为非唯一的)玩家名称。 下载
- 1.7.0 - 通过将处理玩家加入/离开数据库或扁平文件的任务移至独立的异步线程,大幅提升了效率。此前这部分逻辑完全由玩家加入和退出监听器处理,导致主服务器线程阻塞直至操作完成。 下载
- 1.6.3 - 修复了新创建的 MySQL 数据表缺少 'online' 列的问题;感谢 AxxiD 指出此问题。对于缺失该列的现有 MySQL 表,插件将在后续自动补加该列。 下载
- 1.6.2 - 重要提示:针对 MySQL 用户的破坏性变更: 对于 MySQL 数据存储,`time_total` 列的类型从 TIME 更改为 INT(请参阅此处说明) 下载
- 1.6.1 - 主要作为兼容性版本发布,以支持即将到来的 CB 1.1-R5 及以上版本。更新以使用新的 Bukkit 事件系统。修复了时间戳显示 12 小时制而非预期的 24 小时制的问题。移除了插件自身的“加载中”和“关闭中”日志消息,因为 Bukkit 现在已自行处理这些内容。 下载
- 1.6 - 新增数据库列 `time_total`,用于记录玩家在服务器上的在线时长(仅限 MySQL)。 下载
- 1.5.5 - 修复了 {longtime} 和 {shorttime}(在 flatfile 模板中)输出相同内容的问题。 下载
- 1.5.4 - Brettflan 成为新的所有者。已更新以支持 612+ 版本 下载
- 1.5 - 修复 MySQL 相关问题。将 OnlineUsers 目录移至 plugins。下载
- 1.4 - 首次发布 下载
源码 -
如果您喜欢这个插件,欢迎通过 进行支持。
Note: the original plugin and almost all of the work done on it is by croemmich. He doesn't have the time to work it any more, so he's allowed me to maintain it.
OnlineUsers is a simple plugin that maintains a flatfile or MySQL table with logged in users. Make sure to install the MySQL JDBC driver if you choose to use MySQL. You can obtain it from here:
You can simply drop it in your server root folder, alongside the CraftBukkit jar. It will need to be named mysql-connector-java-bin.jar. Alternately, if you know how, you should be able to include it in your Java path.
online-users.properties
- destination=mysql #[mysql|flatfile]
- flatfile=online_users.txt #location of the flatfile to write
- flatfile-template=online_users.template #template used for creating the flatfile
- flatfile-data=online_users.data #data used to fill the flatfile
- remove-offline-users=true #Set to false to keep users in table when logged off.
- db=jdbc\:mysql\:localhost\:3306/minecraft
- user=root
- table=users_online#Will be created for you when the plugin is enabled
- pass=root
Note that the new `time_total` column is only updated when players disconnect. So, if a player is currently connected, that column won't account for the additional time they've been online in their current session. If you want to get a fully up-to-date value for how long they've been online, you can account for it in your query.
For example, this query would give you the up-to-date value as `current_time_total`:
SELECT *, IF(`online`=1, `time_total` + TIMESTAMPDIFF(SECOND, `time`, NOW()), `time_total`) AS `current_time_total` FROM `users_online`
If you're using an older release that 1.6.2, the query would instead look like this due to the different data type for `time_total`:
SELECT *, IF(`online`=1, ADDTIME(`time_total`, TIMEDIFF(NOW(), `time`)), `time_total`) AS `current_time_total` FROM `users_online`
An example PHP script to read from file output from this plugin can be found here.
Changelog
- 1.8.0 - Player UUID is now tracked in database and used as unique key, with the player's name updated at each login in case it has changed, so that time online is properly attached to unique player account rather than (soon to be) non-unique player name. dl
- 1.7.0 - Major efficiency boost by running a separate async task thread to handle adding/removing players from the database or flatfile. Previously this was handled entirely in the player join and quit listeners, thus holding up the main server thread for however long it took. dl
- 1.6.3 - Fix for newly created MySQL database tables missing the 'online' column; thanks to AxxiD for pointing it out. MySQL tables which are missing that column will retroactively have it added. dl
- 1.6.2 - IMPORTANT: BREAKING CHANGE for MySQL users: For MySQL data storage, time_total column type is changed from TIME to INT (read notes here) dl
- 1.6.1 - Primarily a compatibility release to support the upcoming CB 1.1-R5 and above. Update to use the new Bukkit event system. Fix for timestamps showing 12-based hour instead of 24-based as it was supposed to be. Removed the plugin's "loading" and "shutting down" log messages since Bukkit now handles those itself. dl
- 1.6 - added new database column `time_total` to track how long a player has spent on your server (MySQL only). dl
- 1.5.5 - fix for {longtime} and {shorttime} (in flatfile template) both outputting the same thing. dl
- 1.5.4 - Brettflan is now the owner. Updated for 612+ dl
- 1.5 - Fix MySQL issues. Move OnlineUsers directory to plugins. dl
- 1.4 - Initial Release dl
Source -
If you appreciate this plugin, you are welcome to .
评论 0
登录后参与评分
还没有评论,来抢沙发吧