
羽毛笔通知
一个小型库模组,用于以优雅的方式处理向在线和离线玩家发送通知!
Quill Notifications
一个小型库模组,用于以优雅的方式向在线和离线玩家发送通知!
使用方法
此模组需要 Fabric API 和 SQLib。
不强制要求使用 Adventure API,但推荐使用。
模组在服务器上安装后,首次启动会生成一个配置文件。请务必编辑此配置文件,将其指向一个文件路径或 MySQL 数据库。
面向开发者
入门
要将此模组包含在你的项目中,只需将其添加为依赖项:
repositories {
maven { url "https://api.modrinth.com/maven" }
// adventure api 并非严格必需,但它很有帮助,可以让你使用 Component 消息
maven {
name = "sonatype-oss-snapshots1"
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
mavenContent { snapshotsOnly() }
}
}
dependencies {
modImplementation("maven.modrinth:quill:1.2.3")
// adventure api 并非严格必需,但它很有帮助,可以让你使用 Component 消息
modImplementation include("net.kyori:adventure-platform-fabric:6.4.0")
}
通用用法
Notification notification = NotificationBuilder.Notification(receiverUUID) // 初始化一条要发送的新通知
.setMessage(message) // setMessage() 接受 String、MutableText 或 Component 变量(注意,通知只会保存最后设置的消息)
.setStyle(Scribe.INFO) // setStyle() 仅适用于 String 消息
.setMetadata(jsonData) // 将 json 数据注入消息中,以便与事件系统一起使用
.setSound(SoundEvents.BLOCK_BELL_USE) // 设置收到通知时播放的声音事件
.setCommands(commandString, commandString2) // 设置收到通知时要运行的命令
.setCommandDelay(10, TimeUnit.SECONDS) // 设置通知发送后命令延迟执行的时间(你也可以只传入一个数字,表示延迟的毫秒数)
.setExpiry(15, TimeUnit.MINUTES) // 设置消息的过期时间,如果玩家在过期时间结束前没有上线,通知将不会发送(你也可以只传入一个数字,表示过期前的毫秒数)
.build();
Pigeon.send(notification); // 将通知发送给玩家
for (Notification message: QuillNotifications.getNotifications(receiverUUID)) { // 获取玩家的所有待处理通知(通知按从旧到新的顺序排列)
if (notification.getMessage().toString().equals("Test message plz delete")) message.cancel() // 在通知发送给玩家之前取消它
}
事件系统
// 事件系统会为你提供一个 notification 对象,以便在通知数据发送前对其进行修改
QuillEvents.PRE_SEND_NOTIFICATION.register((notification) -> {
System.out.println(notification.getPlayerEntity().getName().getString());
// 返回 true 允许消息发送,返回 false 将阻止
// 返回 false 将阻止消息被看到
return true;
// 用元数据或其他变量做点酷炫的事吧,我不知道,事件系统任你发挥。
});
正在加载版本记录…
正在加载评论…
评论在新手盒子客户端中发表,这里同步展示。