Skip to content

Commit e24d7e4

Browse files
authored
Merge pull request #539 from VOLLEY888/玩家完成书与笔编辑时检查发言权限
玩家完成书与笔编辑时检查发言权限
2 parents 8c76d96 + baa5cee commit e24d7e4

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerBookEdit.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package me.arasple.mc.trchat.module.internal.listener
22

3+
import me.arasple.mc.trchat.module.internal.TrChatBukkit
34
import me.arasple.mc.trchat.util.color.MessageColors
5+
import me.arasple.mc.trchat.util.data
6+
import me.arasple.mc.trchat.util.session
7+
import org.bukkit.entity.Player
48
import org.bukkit.event.player.PlayerEditBookEvent
59
import taboolib.common.platform.Platform
610
import taboolib.common.platform.PlatformSide
711
import taboolib.common.platform.event.EventPriority
812
import taboolib.common.platform.event.SubscribeEvent
913
import taboolib.module.configuration.ConfigNode
14+
import taboolib.platform.util.sendLang
1015

1116
/**
1217
* @author ItsFlicker
@@ -19,6 +24,9 @@ object ListenerBookEdit {
1924
var color = true
2025
private set
2126

27+
@ConfigNode("Chat.Permission-Check.Book", "settings.yml")
28+
var bookEditPermissionCheck = false
29+
2230
@Suppress("Deprecation")
2331
@SubscribeEvent(priority = EventPriority.HIGHEST, ignoreCancelled = true)
2432
fun onBookEdit(e: PlayerEditBookEvent) {
@@ -29,4 +37,21 @@ object ListenerBookEdit {
2937
}
3038
e.newBookMeta = meta
3139
}
40+
41+
@SubscribeEvent(priority = EventPriority.LOW, ignoreCancelled = true)
42+
fun onBookEditCheck(e: PlayerEditBookEvent) {
43+
if (!bookEditPermissionCheck) return
44+
val player = e.player
45+
if (!player.hasPermission("trchat.bypass.bookedit") && !canSpeak(player)) {
46+
e.isCancelled = true
47+
player.sendLang("Book-Edit-No-Permission")
48+
}
49+
}
50+
51+
private fun canSpeak(player: Player): Boolean {
52+
if (TrChatBukkit.isGlobalMuting && !player.hasPermission("trchat.bypass.globalmute")) return false
53+
if (player.data.isMuted) return false
54+
val channel = player.session.getChannel()
55+
return channel == null || channel.canSpeak(player)
56+
}
3257
}

project/runtime-bukkit/src/main/kotlin/me/arasple/mc/trchat/module/internal/listener/ListenerSignChange.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ object ListenerSignChange {
2929
var filter = true
3030
private set
3131

32-
@ConfigNode("Chat.Sign-Edit-Permission-Check", "settings.yml")
32+
@ConfigNode("Chat.Permission-Check.Sign", "settings.yml")
3333
var signEditPermissionCheck = false
3434

3535
@ConfigNode("Color.Sign", "settings.yml")

project/runtime-bukkit/src/main/resources/lang/en_US.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,14 @@ Channel-Bad-Language:
226226
pitch: 0
227227
Sign-Edit-No-Permission:
228228
- type: actionbar
229-
text: '&cNo Edit Sign Permission'
229+
text: '&cYou do not have permission to edit the bulletin board.'
230+
- type: sound
231+
sound: 'ENTITY_ITEM_BREAK'
232+
volume: 1
233+
pitch: 0
234+
Book-Edit-No-Permission:
235+
- type: actionbar
236+
text: '&cYou do not have permission to edit the book.'
230237
- type: sound
231238
sound: 'ENTITY_ITEM_BREAK'
232239
volume: 1

project/runtime-bukkit/src/main/resources/lang/es_ES.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,14 @@ Channel-Bad-Language:
219219
pitch: 0
220220
Sign-Edit-No-Permission:
221221
- type: actionbar
222-
text: '&cNo Edit Sign Permission'
222+
text: '&cYou do not have permission to edit the bulletin board.'
223+
- type: sound
224+
sound: 'ENTITY_ITEM_BREAK'
225+
volume: 1
226+
pitch: 0
227+
Book-Edit-No-Permission:
228+
- type: actionbar
229+
text: '&cYou do not have permission to edit the book.'
223230
- type: sound
224231
sound: 'ENTITY_ITEM_BREAK'
225232
volume: 1

project/runtime-bukkit/src/main/resources/lang/zh_CN.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ Sign-Edit-No-Permission:
234234
sound: 'ENTITY_ITEM_BREAK'
235235
volume: 1
236236
pitch: 0
237+
Book-Edit-No-Permission:
238+
- type: actionbar
239+
text: '&c你没有权限编辑书与笔'
240+
- type: sound
241+
sound: 'ENTITY_ITEM_BREAK'
242+
volume: 1
243+
pitch: 0
237244

238245
Mute-Muted-Player: '&8[&3Tr&bChat&8] &7你已禁言 {0} {1}.原因: {2}'
239246
Mute-Cancel-Muted-Player: '&8[&3Tr&bChat&8] &7你已取消禁言 {0}.'

project/runtime-bukkit/src/main/resources/settings.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Chat:
3838
Anti-Repeat: 0.85
3939
Cooldown: '2.0s'
4040
Length-Limit: 100
41-
Sign-Edit-Permission-Check: false
41+
Permission-Check:
42+
Sign: false #无发言权限无法编辑告示牌 true 开启 false关闭
43+
Book: false #无发言权限无法编辑书与笔 true 开启 false关闭
4244

4345
Color:
4446
Chat: true

0 commit comments

Comments
 (0)