Skip to content

Commit eec176e

Browse files
committed
Merge remote-tracking branch 'origin/v2' into v2
2 parents cf58eee + bd08e40 commit eec176e

7 files changed

Lines changed: 104 additions & 5 deletions

File tree

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import me.arasple.mc.trchat.module.adventure.toAdventure
55
import me.arasple.mc.trchat.module.internal.TrChatBukkit
66
import me.arasple.mc.trchat.util.color.MessageColors
77
import me.arasple.mc.trchat.util.parseSimple
8+
import me.arasple.mc.trchat.util.data
9+
import me.arasple.mc.trchat.util.session
810
import org.bukkit.entity.HumanEntity
11+
import org.bukkit.entity.Player
912
import org.bukkit.event.inventory.InventoryType
1013
import org.bukkit.event.inventory.PrepareAnvilEvent
1114
import org.bukkit.inventory.meta.ItemMeta
@@ -18,6 +21,8 @@ import taboolib.library.reflex.Reflex.Companion.invokeMethod
1821
import taboolib.module.configuration.ConfigNode
1922
import taboolib.platform.util.isAir
2023
import taboolib.platform.util.modifyMeta
24+
import taboolib.platform.util.sendLang
25+
import me.arasple.mc.trchat.module.internal.data.PlayerData
2126

2227
/**
2328
* @author ItsFlicker
@@ -38,17 +43,34 @@ object ListenerAnvilChange {
3843
var simple = false
3944
private set
4045

46+
@ConfigNode("Chat.Permission-Check.Anvil", "settings.yml")
47+
var anvilPermissionCheck = false
48+
4149
@Suppress("Deprecation")
4250
@SubscribeEvent(priority = EventPriority.HIGHEST, ignoreCancelled = true)
4351
fun onAnvilCraft(e: PrepareAnvilEvent) {
4452
// e.view -> AnvilView
4553
// java.lang.IncompatibleClassChangeError: Found class org.bukkit.inventory.InventoryView, but interface was expected
46-
val p = e.invokeMethod<Any>("getView")!!.invokeMethod<HumanEntity>("getPlayer")!!
54+
val p = e.invokeMethod<Any>("getView")!!.invokeMethod<HumanEntity>("getPlayer")!! as? Player ?: return
4755
val result = e.result
4856

4957
if (e.inventory.type != InventoryType.ANVIL || result.isAir()) {
5058
return
5159
}
60+
61+
val left = e.inventory.getItem(0) // 左侧输入槽物品
62+
val right = e.inventory.getItem(1) // 右侧输入槽物品
63+
val resultName = result.itemMeta?.displayName
64+
val leftName = left?.itemMeta?.displayName
65+
val rightName = right?.itemMeta?.displayName
66+
val isRenaming = resultName != null && resultName != leftName && resultName != rightName
67+
68+
if (anvilPermissionCheck && isRenaming && !canSpeak(p)) {
69+
e.result = null
70+
p.sendLang("Anvil-Edit-No-Permission")
71+
return
72+
}
73+
5274
result.modifyMeta<ItemMeta> {
5375
if (!hasDisplayName()) {
5476
return@modifyMeta
@@ -64,4 +86,11 @@ object ListenerAnvilChange {
6486
}
6587
e.result = result
6688
}
89+
90+
private fun canSpeak(player: Player): Boolean {
91+
if (TrChatBukkit.isGlobalMuting && !player.hasPermission("trchat.bypass.globalmute")) return false
92+
if (player.data.isMuted) return false
93+
val channel = player.session.getChannel()
94+
return channel == null || channel.canSpeak(player)
95+
}
6796
}

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,21 @@ 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.'
237+
- type: sound
238+
sound: 'ENTITY_ITEM_BREAK'
239+
volume: 1
240+
pitch: 0
241+
Anvil-Edit-No-Permission:
242+
- type: actionbar
243+
text: '&cYou do not have permission to rename items in anvil.'
230244
- type: sound
231245
sound: 'ENTITY_ITEM_BREAK'
232246
volume: 1

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,21 @@ 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.'
230+
- type: sound
231+
sound: 'ENTITY_ITEM_BREAK'
232+
volume: 1
233+
pitch: 0
234+
Anvil-Edit-No-Permission:
235+
- type: actionbar
236+
text: '&cYou do not have permission to rename items in anvil.'
223237
- type: sound
224238
sound: 'ENTITY_ITEM_BREAK'
225239
volume: 1

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ 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
244+
Anvil-Edit-No-Permission:
245+
- type: actionbar
246+
text: '&c你没有权限在铁砧中重命名物品。'
247+
- type: sound
248+
sound: 'ENTITY_ITEM_BREAK'
249+
volume: 1
250+
pitch: 0
237251

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

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ 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关闭
44+
Anvil: false #无发言权限无法铁砧改名 true 开启 false关闭
4245

4346
Color:
4447
Chat: true

0 commit comments

Comments
 (0)