Skip to content

Commit bb1603d

Browse files
committed
1.4.0 对接DiscordSRV
1 parent 425bc2d commit bb1603d

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

pom.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
<groupId>cn.handyplus.chat</groupId>
88
<artifactId>PlayerChat</artifactId>
9-
<version>1.3.7</version>
9+
<version>1.4.0</version>
1010
<description>一款有点好用的聊天插件</description>
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<spigot-api.vesion>1.21.8-R0.1-SNAPSHOT</spigot-api.vesion>
15-
<HandyLib.version>3.24.6</HandyLib.version>
14+
<spigot-api.vesion>1.21.10-R0.1-SNAPSHOT</spigot-api.vesion>
15+
<HandyLib.version>3.28.2</HandyLib.version>
1616
<lombok.version>1.18.38</lombok.version>
1717
<annotations.version>26.0.2</annotations.version>
1818
<placeholderapi.version>2.11.6</placeholderapi.version>
19+
<discordsrv.version>1.30.1</discordsrv.version>
1920
</properties>
2021

2122
<dependencies>
@@ -48,6 +49,12 @@
4849
<version>${annotations.version}</version>
4950
<scope>compile</scope>
5051
</dependency>
52+
<dependency>
53+
<groupId>com.discordsrv</groupId>
54+
<artifactId>discordsrv</artifactId>
55+
<version>${discordsrv.version}</version>
56+
<scope>provided</scope>
57+
</dependency>
5158
</dependencies>
5259

5360
<build>

src/main/java/cn/handyplus/chat/PlayerChat.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
public class PlayerChat extends JavaPlugin {
2121
public static PlayerChat INSTANCE;
2222
public static boolean USE_PAPI;
23+
public static boolean USE_DISCORD_SRV;
2324

2425
@Override
2526
public void onEnable() {
@@ -31,6 +32,8 @@ public void onEnable() {
3132
if (USE_PAPI) {
3233
new PlaceholderUtil(this).register();
3334
}
35+
// 加载DiscordSRV
36+
USE_DISCORD_SRV = BaseUtil.hook(HookPluginEnum.DISCORD_SRV);
3437
// 加载主数据
3538
initApi.initCommand("cn.handyplus.chat.command")
3639
.initListener("cn.handyplus.chat.listener")

src/main/java/cn/handyplus/chat/listener/PlayerChannelChatEventListener.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package cn.handyplus.chat.listener;
22

3+
import cn.handyplus.chat.PlayerChat;
34
import cn.handyplus.chat.core.ChatUtil;
45
import cn.handyplus.chat.event.PlayerChannelChatEvent;
56
import cn.handyplus.chat.event.PlayerChannelTellEvent;
67
import cn.handyplus.lib.annotation.HandyListener;
78
import cn.handyplus.lib.util.BcUtil;
9+
import github.scarsz.discordsrv.DiscordSRV;
10+
import github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel;
811
import org.bukkit.entity.Player;
912
import org.bukkit.event.EventHandler;
1013
import org.bukkit.event.Listener;
@@ -27,7 +30,10 @@ public void onChat(PlayerChannelChatEvent event) {
2730
if (event.isCancelled()) {
2831
return;
2932
}
33+
// 发送Plc消息
3034
sendMsg(event.getBcMessageParam(), event.getPlayer());
35+
// 发送Discord消息
36+
this.sendDiscord(event);
3137
}
3238

3339
/**
@@ -56,4 +62,20 @@ private static void sendMsg(BcUtil.BcMessageParam bcMessageParam, Player player)
5662
BcUtil.sendParamForward(player, bcMessageParam);
5763
}
5864

65+
/**
66+
* 发送Discord消息
67+
*
68+
* @param event 事件
69+
*/
70+
private void sendDiscord(PlayerChannelChatEvent event) {
71+
if (!PlayerChat.USE_DISCORD_SRV) {
72+
return;
73+
}
74+
// 根据游戏频道名获取对应的Discord频道
75+
TextChannel channel = DiscordSRV.getPlugin().getDestinationTextChannelForGameChannelName(event.getChannel());
76+
if (channel != null) {
77+
DiscordSRV.getPlugin().processChatMessage(event.getPlayer(), event.getOriginalMessage(), event.getChannel(), false, event);
78+
}
79+
}
80+
5981
}

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: PlayerChat
22
main: cn.handyplus.chat.PlayerChat
3-
version: 1.3.7
3+
version: 1.4.0
44
author: handy
55
api-version: 1.13
6-
softdepend: [ PlaceholderAPI ]
6+
softdepend: [ PlaceholderAPI,DiscordSRV ]
77
website: https://ricedoc.handyplus.cn/wiki/PlayerChat/log/
88
description: 一款有点好用的聊天插件
99
folia-supported: true

0 commit comments

Comments
 (0)