Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
4o4E committed Feb 4, 2025
2 parents 13eb303 + 33d3133 commit 688e56c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/main/kotlin/clean/Trashcan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.scheduler.BukkitTask
import top.e404.eclean.PL
import top.e404.eclean.config.Config
import top.e404.eclean.config.Lang
import top.e404.eclean.menu.MenuManager
import top.e404.eclean.menu.trashcan.TrashInfo
import top.e404.eclean.menu.trashcan.TrashcanMenu
Expand All @@ -24,6 +25,13 @@ object Trashcan : EListener(PL) {

var task: BukkitTask? = null

fun cleanTrash(){
Config.plugin.debug { "清空垃圾桶" }
trashData.clear()
trashValues.clear()
PL.broadcastMsg(Lang["command.trash_clean_done"])
}

/**
* 垃圾桶清空倒计时, 单位秒
*/
Expand All @@ -42,9 +50,7 @@ object Trashcan : EListener(PL) {
countdown--
if (countdown <= 0L) {
countdown = duration
Config.plugin.debug { "清空垃圾桶" }
trashData.clear()
trashValues.clear()
cleanTrash()
update()
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/clean/drop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import top.e404.eplugin.EPlugin.Companion.placeholder
private inline val dropCfg get() = Config.config.drop
private inline val trashcanCfg get() = Config.config.trashcan


/**
* 最近一次清理掉落物的数量
*/
Expand Down Expand Up @@ -85,6 +86,10 @@ fun World.cleanDrop(): Pair<Int, Int> {
it.itemStack.type == Material.WRITABLE_BOOK
&& (it.itemStack.itemMeta as? BookMeta)?.hasPages() == true
}
// dropCfg.lore == true 时不清理lore的物品(从列表中移除)
if (dropCfg.lore) waitingForClean.removeIf {
it.itemStack.itemMeta?.hasLore() == true
}

val items = mutableMapOf<String, MutableList<Item>>()
waitingForClean.forEach {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/command/Clean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender
import top.e404.eclean.PL
import top.e404.eclean.clean.*
import top.e404.eclean.clean.Clean
import top.e404.eclean.clean.Trashcan.cleanTrash
import top.e404.eclean.config.Lang
import top.e404.eplugin.command.ECommand

Expand All @@ -17,7 +18,7 @@ object Clean : ECommand(
) {
override val usage get() = Lang["command.usage.clean"]

private val arg = listOf("entity", "drop", "chunk")
private val arg = listOf("entity", "drop", "chunk", "trash")
override fun onTabComplete(
sender: CommandSender,
args: Array<out String>,
Expand All @@ -39,6 +40,7 @@ object Clean : ECommand(
"e", "entity" -> cleanLiving()
"d", "drop" -> cleanDrop()
"c", "chunk" -> cleanDenseEntities()
"t", "trash" -> cleanTrash()
else -> sender.sendMessage(usage)
}

Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ data class DropConfig(
@SerialName("is_black")
var black: Boolean = true,
var enchant: Boolean = false,
var lore: Boolean = false,
@SerialName("written_book")
var writtenBook: Boolean = false,
var match: MutableList<@Serializable(RegexSerialization::class) Regex> = mutableListOf(),
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ drop:
# 若设置为false则清理带附魔的物品
enchant: false

# 若设置为true则不清理带描述的物品
# 若设置为false则清理带描述的物品
lore: false

# 若设置为true则不清理写过的书
# 若设置为false则清理写过的书 (match规则匹配时才会清理)
written_book: false


# 掉落物类型(支持正则)
# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/material/package-summary.html
match:
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ command:
reload_done: "&a重载完成"
trash_disable: "&a垃圾桶功能已被禁用"
trash_open: "&a已打开垃圾桶"
trash_clean_done: "&a垃圾桶清理完成"
clean_done: "&a共清理&6{count}&a个实体"
teleport:
done: "&a传送完成"
Expand Down

0 comments on commit 688e56c

Please sign in to comment.