Skip to content

Commit d92b4e2

Browse files
committed
feat: 1.21.0, 添加回收despawn物品到垃圾桶的功能
1 parent 37a3919 commit d92b4e2

5 files changed

Lines changed: 64 additions & 1 deletion

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "top.e404"
11-
version = "1.20.1"
11+
version = "1.21.0"
1212
val epluginVer = "1.4.0"
1313

1414
fun eplugin(module: String, version: String = epluginVer) = "top.e404:eplugin-$module:$version"

src/main/kotlin/EClean.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import top.e404.eclean.config.Config
1010
import top.e404.eclean.config.Lang
1111
import top.e404.eclean.hook.HookManager
1212
import top.e404.eclean.hook.PapiHook
13+
import top.e404.eclean.listener.DespawnListener
1314
import top.e404.eclean.menu.MenuManager
1415
import top.e404.eclean.papi.Papi
1516
import top.e404.eclean.update.Update
@@ -62,6 +63,7 @@ open class EClean : EPlugin {
6263
Clean.schedule()
6364
HookManager.register()
6465
MenuManager.register()
66+
DespawnListener.register()
6567
Trashcan.register()
6668
if (PapiHook.enable) Papi.register()
6769
for (line in logo) info(line)

src/main/kotlin/config/Config.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ data class TrashcanConfig(
9494
var enable: Boolean = true,
9595
var collect: Boolean = true,
9696
var duration: Long? = 6000,
97+
var despawn: DespawnConfig = DespawnConfig(),
98+
)
99+
100+
@Serializable
101+
data class DespawnConfig(
102+
var enable: Boolean = false,
103+
@SerialName("disable_world")
104+
var disableWorlds: MutableList<@Serializable(RegexSerialization::class) Regex> = mutableListOf(),
105+
var match: MutableList<@Serializable(RegexSerialization::class) Regex> = mutableListOf(),
97106
)
98107

99108
@Serializable
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package top.e404.eclean.listener
2+
3+
import org.bukkit.event.EventHandler
4+
import org.bukkit.event.EventPriority
5+
import org.bukkit.event.entity.ItemDespawnEvent
6+
import top.e404.eclean.PL
7+
import top.e404.eclean.clean.Trashcan
8+
import top.e404.eclean.config.Config
9+
import top.e404.eplugin.config.matches
10+
import top.e404.eplugin.listener.EListener
11+
12+
object DespawnListener : EListener(PL) {
13+
@EventHandler(priority = EventPriority.HIGHEST)
14+
fun ItemDespawnEvent.onEvent() {
15+
val item = entity.itemStack
16+
PL.debug { "物品到时间后销毁: ${item.type.name}, 世界: ${entity.world.name}" }
17+
Config.config.trashcan.run {
18+
if (!enable
19+
|| !despawn.enable
20+
|| despawn.disableWorlds.matches(entity.world.name)
21+
|| !despawn.match.matches(item.type.name)
22+
) return
23+
}
24+
PL.debug { "回收匹配物品到垃圾桶: ${item.type.name}, 世界: ${entity.world.name}" }
25+
Trashcan.addItem(item.clone())
26+
// 确保物品被移除
27+
entity.remove()
28+
}
29+
}

src/main/resources/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,29 @@ trashcan:
152152
collect: true
153153
# 清空垃圾桶的时间间隔, 单位秒, 设置为空则不会主动清理(可能导致内存泄露占用大量内存)
154154
duration: 6000
155+
despawn:
156+
# 设置为true则回收despawn的物品
157+
enable: false
158+
# 禁用的世界(支持正则)
159+
disable_world:
160+
- "不回收的世界"
161+
# 放入垃圾桶的掉落物类型(支持正则) 可以设置如下格式回收所有物品
162+
# match:
163+
# - .*
164+
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
165+
match:
166+
- "DIAMOND[A-Z_]*"
167+
- "NETHERITE[A-Z_]*"
168+
- "[A-Z_]*SHULKER_BOX"
169+
- "[A-Z_]*(HEAD|SKULL)"
170+
- "SHULKER_SHELL"
171+
- "BEACON"
172+
- "(ENCHANTED_)?GOLDEN_APPLE"
173+
- "TRIDENT"
174+
- "TOTEM_OF_UNDYING"
175+
- "ENDER_CHEST"
176+
- "DRAGON_EGG"
177+
- "ELYTRA"
155178

156179
# 无在线玩家时的配置
157180
no_online:

0 commit comments

Comments
 (0)