File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ plugins {
88}
99
1010group = " top.e404"
11- version = " 1.20.1 "
11+ version = " 1.21.0 "
1212val epluginVer = " 1.4.0"
1313
1414fun eplugin (module : String , version : String = epluginVer) = " top.e404:eplugin-$module :$version "
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import top.e404.eclean.config.Config
1010import top.e404.eclean.config.Lang
1111import top.e404.eclean.hook.HookManager
1212import top.e404.eclean.hook.PapiHook
13+ import top.e404.eclean.listener.DespawnListener
1314import top.e404.eclean.menu.MenuManager
1415import top.e404.eclean.papi.Papi
1516import 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)
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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# 无在线玩家时的配置
157180no_online :
You can’t perform that action at this time.
0 commit comments