Skip to content

Commit

Permalink
update: 1.18.0, 添加无玩家在线时的配置
Browse files Browse the repository at this point in the history
  • Loading branch information
4o4E committed May 12, 2024
1 parent 20a4a84 commit aa5936a
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 29 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.8.21"
kotlin("plugin.serialization") version "1.8.21"
kotlin("jvm") version "1.9.22"
kotlin("plugin.serialization") version "1.9.22"
id("com.github.johnrengelman.shadow") version "7.1.2"
}

group = "top.e404"
version = "1.17.2"
val epluginVer = "1.2.0"
version = "1.18.0"
val epluginVer = "1.3.0"

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

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
14 changes: 7 additions & 7 deletions src/main/kotlin/EClean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import java.io.File
open class EClean : EPlugin {
companion object {
val logo = listOf(
"""&6 ______ ______ __ ______ ______ __ __ """.color(),
"""&6/\ ___\ /\ ___\ /\ \ /\ ___\ /\ __ \ /\ "-.\ \ """.color(),
"""&6\ \ __\ \ \ \____ \ \ \____ \ \ __\ \ \ __ \ \ \ \-. \ """.color(),
"""&6 \ \_____\ \ \_____\ \ \_____\ \ \_____\ \ \_\ \_\ \ \_\\"\_\""".color(),
"""&6 \/_____/ \/_____/ \/_____/ \/_____/ \/_/\/_/ \/_/ \/_/""".color()
"""&6 ______ ______ __ ______ ______ __ __ """.color,
"""&6/\ ___\ /\ ___\ /\ \ /\ ___\ /\ __ \ /\ "-.\ \ """.color,
"""&6\ \ __\ \ \ \____ \ \ \____ \ \ __\ \ \ __ \ \ \ \-. \ """.color,
"""&6 \ \_____\ \ \_____\ \ \_____\ \ \_____\ \ \_\ \_\ \ \_\\"\_\""".color,
"""&6 \/_____/ \/_____/ \/_____/ \/_____/ \/_/\/_/ \/_/ \/_/""".color
)
}

Expand Down Expand Up @@ -65,14 +65,14 @@ open class EClean : EPlugin {
Trashcan.register()
if (PapiHook.enable) Papi.register()
for (line in logo) info(line)
info("&a加载完成, 作者404E, 感谢使用".color())
info("&a加载完成, 作者404E, 感谢使用".color)
}

override fun onDisable() {
MenuManager.shutdown()
if (PapiHook.enable) Papi.unregister()
Bukkit.getScheduler().cancelTasks(this)
info("&a已卸载, 作者404E, 感谢使用".color())
info("&a已卸载, 作者404E, 感谢使用".color)
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/clean/Clean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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.util.noOnline
import top.e404.eclean.util.noOnlineClean
import top.e404.eclean.util.noOnlineMessage
import top.e404.eplugin.EPlugin.Companion.color

object Clean {
Expand All @@ -23,14 +26,18 @@ object Clean {
PL.info("&f设置清理任务, 间隔${duration}")
Config.config.message.forEach { (delay, message) ->
if (delay > duration) PL.warn(Lang["warn.out_of_range", "message" to message, "duration" to duration])
else PL.info("&f设置清理前${delay}秒提醒: ${message.color()}")
else PL.info("&f设置清理前${delay}秒提醒: ${message.color}")
}
task = PL.runTaskTimer(20, 20) {
count++
Config.config.message[duration - count]?.let { PL.broadcastMsg(it) }
if (noOnline && noOnlineMessage) {
Config.config.message[duration - count]?.let { PL.broadcastMsg(it) }
}
if (count >= duration) {
count = 0
clean()
if (noOnline && noOnlineClean) {
clean()
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/clean/chunk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.bukkit.entity.LivingEntity
import top.e404.eclean.PL
import top.e404.eclean.config.Config
import top.e404.eclean.util.info
import top.e404.eclean.util.noOnline
import top.e404.eclean.util.noOnlineMessage
import top.e404.eplugin.EPlugin.Companion.placeholder

private inline val chunkCfg get() = Config.config.chunk
Expand Down Expand Up @@ -45,8 +47,10 @@ fun cleanDenseEntities() {

PL.debug { "密集实体清理共${lastChunk}个, 耗时${time}ms" }

val finish = Config.config.chunk.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder("clean" to lastChunk))
if (noOnline && noOnlineMessage) {
val finish = Config.config.chunk.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder("clean" to lastChunk))
}
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/clean/drop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.bukkit.inventory.meta.BookMeta
import top.e404.eclean.PL
import top.e404.eclean.config.Config
import top.e404.eclean.util.isMatch
import top.e404.eclean.util.noOnline
import top.e404.eclean.util.noOnlineMessage
import top.e404.eplugin.EPlugin.Companion.placeholder

private inline val dropCfg get() = Config.config.drop
Expand Down Expand Up @@ -43,9 +45,11 @@ fun cleanDrop() {
lastDrop = result.sumOf { it.first }
PL.debug { "掉落物清理共${lastDrop}个, 耗时${time}ms" }

val all = result.sumOf { it.second }
val finish = dropCfg.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder("clean" to lastDrop, "all" to all))
if (noOnline && noOnlineMessage) {
val all = result.sumOf { it.second }
val finish = dropCfg.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder("clean" to lastDrop, "all" to all))
}
}

/**
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/clean/living.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import top.e404.eclean.PL
import top.e404.eclean.config.Config
import top.e404.eclean.util.info
import top.e404.eclean.util.isMatch
import top.e404.eclean.util.noOnline
import top.e404.eclean.util.noOnlineMessage
import top.e404.eplugin.EPlugin.Companion.placeholder

private inline val livingCfg get() = Config.config.living
Expand Down Expand Up @@ -43,9 +45,11 @@ fun cleanLiving() {
lastLiving = result.sumOf { it.first }
PL.debug { "生物清理共${lastLiving}个, 耗时${time}ms" }

val all = result.sumOf { it.second }
val finish = livingCfg.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder(mapOf("clean" to lastLiving, "all" to all)))
if (noOnline && noOnlineMessage) {
val all = result.sumOf { it.second }
val finish = livingCfg.finish
if (finish.isNotBlank()) PL.broadcastMsg(finish.placeholder(mapOf("clean" to lastLiving, "all" to all)))
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/command/Players.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object Players : ECommand(
) {
Bukkit.getOnlinePlayers().groupBy { it.world }.forEach { (world, list) ->
val s = list.joinToString { "\n &b${it.name}&f: ${it.location.run { "$blockX $blockY $blockZ" }}" }
sender.sendMessage("&6${world.name}:$s".color())
sender.sendMessage("&6${world.name}:$s".color)
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/command/Stats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Stats : ECommand(
false,
"eclean.admin"
) {
override val usage get() = Lang["command.usage.stats"].color()
override val usage get() = Lang["command.usage.stats"].color

override fun onTabComplete(
sender: CommandSender,
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ data class ConfigData(
var drop: DropConfig,
var chunk: ChunkConfig,
var trashcan: TrashcanConfig,
@SerialName("no_online")
var noOnline: NoOnlineConfig = NoOnlineConfig(),
)

@Serializable
Expand Down Expand Up @@ -92,3 +94,9 @@ data class TrashcanConfig(
var collect: Boolean = true,
var duration: Long? = 6000,
)

@Serializable
data class NoOnlineConfig(
var clean: Boolean = true,
var message: Boolean = true,
)
8 changes: 8 additions & 0 deletions src/main/kotlin/util/online.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package top.e404.eclean.util

import org.bukkit.Bukkit
import top.e404.eclean.config.Config

val noOnline get() = Bukkit.getOnlinePlayers().isEmpty()
val noOnlineClean get() = Config.config.noOnline.clean
val noOnlineMessage get() = Config.config.noOnline.message
9 changes: 8 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ trashcan:
# 设置为true则掉落物清理的掉落物会收集到垃圾桶中
collect: true
# 清空垃圾桶的时间间隔, 单位秒, 设置为空则不会主动清理(可能导致内存泄露占用大量内存)
duration: 6000
duration: 6000

# 无在线玩家时的配置
no_online:
# 设置为false则没有在线玩家时不发送消息(倒计时和清理结果)
message: true
# 设置为false则没有在线玩家时不清理(但是会显示清理倒计时)
clean: true
9 changes: 7 additions & 2 deletions src/test/kotlin/clean/ChunkCleanTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import be.seeseemelk.mockbukkit.entity.LivingEntityMock
import org.bukkit.Location
import org.bukkit.entity.Entity
import org.bukkit.entity.EntityType
import org.junit.jupiter.api.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import top.e404.eclean.clean.cleanDenseEntities
import top.e404.eclean.clean.lastChunk
import top.e404.eclean.config.*
import top.e404.eclean.config.Config
import top.e404.eclean.test.*

abstract class ChunkCleanTest {
Expand All @@ -33,6 +36,7 @@ abstract class ChunkCleanTest {
chunk.load()
val location = Location(world, 8.0, 8.0, 8.0)
val entities = world.spawnEntities(location, EntityType.ZOMBIE, 16) { _, zombie ->
@Suppress("DEPRECATION")
zombie.customName = "custom name"
}

Expand All @@ -53,6 +57,7 @@ abstract class ChunkCleanTest {
chunk.load()
val location = Location(world, 8.0, 8.0, 8.0)
val entities = world.spawnEntities(location, EntityType.ZOMBIE, 16) { _, zombie ->
@Suppress("DEPRECATION")
zombie.customName = "custom name"
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/clean/DropCleanTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ abstract class DropCleanTest {
ItemStack(Material.WRITABLE_BOOK).apply {
if (index == 0) editItemMeta {
this as BookMeta
@Suppress("DEPRECATION")
this.pages = mutableListOf("a", "b")
}
}
Expand All @@ -106,6 +107,7 @@ abstract class DropCleanTest {
ItemStack(Material.WRITABLE_BOOK).apply {
if (index == 0) editItemMeta {
this as BookMeta
@Suppress("DEPRECATION")
this.pages = mutableListOf("a", "b")
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/kotlin/clean/LivingCleanTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class LivingCleanTest {
chunk.load()
val location = Location(world, 8.0, 8.0, 8.0)
val entities = world.spawnEntities(location, EntityType.ZOMBIE, 16) { _, zombie ->
@Suppress("DEPRECATION")
zombie.customName = "custom name"
}

Expand All @@ -54,6 +55,7 @@ abstract class LivingCleanTest {
chunk.load()
val location = Location(world, 8.0, 8.0, 8.0)
val entities = world.spawnEntities(location, EntityType.ZOMBIE, 16) { _, zombie ->
@Suppress("DEPRECATION")
zombie.customName = "custom name"
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/kotlin/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ fun resetConfig() {
living = LivingConfig(enable = false),
drop = DropConfig(enable = false),
chunk = ChunkConfig(enable = false),
trashcan = TrashcanConfig()
trashcan = TrashcanConfig(),
noOnline = NoOnlineConfig()
)
// 清空控制台输出
consoleOut
Expand Down

0 comments on commit aa5936a

Please sign in to comment.