Quill Notifications

模组

· 作者 electrobrine

一款小巧的库模组,用于以优雅的方式向在线和离线玩家发送通知!

0 本站下载 0 关注 更新于 1 年前

需要前置:SQLib、Fabric API

最新 1.2.3 · 1.21.5 · Fabric / Quilt

一键开服(送7天)

Quill Notifications

一款小型库模组,用于以优雅的方式向在线和离线玩家发送通知!

用法

此模组需要 Fabric API 和 SQLib。

使用 Adventure API 不是必需的,但推荐使用。

一旦模组安装在你的服务器上,首次启动后会生成一个配置文件。请务必编辑该配置文件并将其指向文件路径或 MySQL 数据库。

对于开发者

开始使用

要在项目中包含此模组,只需将其添加为依赖项:

repositories {
    maven { url "https://api.modrinth.com/maven" }
    // adventure api is not strictly necessary but is helpful and will allow you to use Component messages
    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 is not strictly necessary but is helpful and allow you to use Component messages
    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() // 在通知发送给玩家之前取消它
}

事件系统

// 事件系统允许你在通知发送前修改通知数据
QuillEvents.PRE_SEND_NOTIFICATION.register((notification) -> {
  System.out.println(notification.getPlayerEntity().getName().getString());
  // 返回 true 允许消息发送,返回 false 将阻止消息被看到
  return true;
  // 利用 metadata 或其他变量做一些酷炫的事情,具体由你决定。
});

你是这个资源的作者?登录后可认领此资源。

评论 0

0.0
暂无评分
5 星
0
4 星
0
3 星
0
2 星
0
1 星
0
我的评分

登录后参与评分

还没有评论,来抢沙发吧

评论配图

相似资源