Skip to content

Commit

Permalink
Ver 1.0.2
Browse files Browse the repository at this point in the history
✅ Complete the Adyeshach support
✅ Refine the language files
🛠 Fix errors in the dependencies section
🛠 Fix the bug of the reload command couldn't refresh the holograms
  • Loading branch information
L1-An committed Oct 24, 2023
1 parent 336e728 commit 4674fe2
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 28 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
Dependency: `MythicMobs`
SoftDependency: `PlaceholderAPI, HolographicDisplays, DecentHolograms, Adyeshach`

[Spigot link](https://www.spigotmc.org/resources/yuspawnerhologram-%E2%9C%85for-mythicspawner-display-refresh-time-%E2%9C%85intelligent-multilingual-support.113207/)

# Usage

## Command
`yuspawnerhologram / spawnerholo / mmholo`

## PlaceHolder
| Placeholder | Description |
|:---------------------------:|:------------------:|
| %spawnerholo_{spawnerName}% | 获取指定 spawner 的重生时间 |
| Placeholder | Description |
|:---------------------------:|:----------------------------------------------:|
| %spawnerholo_{spawnerName}% | Gets the respawn time of the specified spawner |

# Building

Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ taboolib {
name("L1An")
}
dependencies {
name("MythicMobs").with("bukkit")
name("PlaceholderAPI").with("bukkit").optional(true)
name("HolographicDisplays").with("bukkit").optional(true)
name("DecentHolograms").with("bukkit").optional(true)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=com.github.l1an.yuspawnerhologram
version=1.0.1
version=1.0.2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.l1an.yuspawnerhologram.internal.command.subcommand

import com.github.l1an.yuspawnerhologram.internal.config.YuSpawnerHologramConfig.config
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.AdyeshachHologram.refreshHologramByADY
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.DecentHologram.refreshHologramByDH
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HologramEnter.adyeshach
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HologramEnter.decentHolograms
Expand All @@ -17,7 +18,7 @@ val CommandRefresh = subCommand {
val keys = Utils.getConfigKeys(config, "hologramText")
for (spawnerName in keys) {
when {
//adyeshach != null -> refreshHologramByADY(spawnerName, sender)
adyeshach != null -> refreshHologramByADY(spawnerName, sender)
decentHolograms != null -> refreshHologramByDH(spawnerName, sender)
holographicDisplays != null -> refreshHologramByHD(spawnerName, sender)
else -> sender.sendLang("dependency-not-found")
Expand All @@ -31,7 +32,7 @@ val CommandRefresh = subCommand {
execute<CommandSender> { sender, context, _ ->
val spawnerName = context["spawner id"]
when {
//adyeshach != null -> refreshHologramByADY(spawnerName, sender)
adyeshach != null -> refreshHologramByADY(spawnerName, sender)
decentHolograms != null -> refreshHologramByDH(spawnerName, sender)
holographicDisplays != null -> refreshHologramByHD(spawnerName, sender)
else -> sender.sendLang("dependency-not-found")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.github.l1an.yuspawnerhologram.internal.command.subcommand

import com.github.l1an.yuspawnerhologram.internal.config.YuSpawnerHologramConfig.isDebug
import com.github.l1an.yuspawnerhologram.internal.config.YuSpawnerHologramConfig
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.AdyeshachHologram
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.DecentHologram
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HologramEnter
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HolographicHologram
import com.github.l1an.yuspawnerhologram.internal.manager.ConfigManager
import com.github.l1an.yuspawnerhologram.util.Utils
import org.bukkit.command.CommandSender
import taboolib.common.platform.command.subCommand
import taboolib.common5.mirrorNow
Expand All @@ -10,11 +15,17 @@ import taboolib.platform.util.sendLang
val CommandReload = subCommand {
execute<CommandSender> {sender, _, _ ->
mirrorNow("Plugin Reload") {
val keys = Utils.getConfigKeys(YuSpawnerHologramConfig.config, "hologramText")
for (spawnerName in keys) {
when {
HologramEnter.adyeshach != null -> AdyeshachHologram.refreshHologramByADY(spawnerName, sender)
HologramEnter.decentHolograms != null -> DecentHologram.refreshHologramByDH(spawnerName, sender)
HologramEnter.holographicDisplays != null -> HolographicHologram.refreshHologramByHD(spawnerName, sender)
else -> sender.sendLang("dependency-not-found")
}
}
sender.sendLang("command-reload")
ConfigManager.reload()
if (isDebug) {
sender.sendLang("debug-mode")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ object YuSpawnerHologramConfig {
@Config("config.yml")
lateinit var config: Configuration
private set

@ConfigNode("debug")
var isDebug = false
private set
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.l1an.yuspawnerhologram.internal.core

import com.github.l1an.yuspawnerhologram.internal.compat.hook.HookMythicMobs.getSpawnerManager
import com.github.l1an.yuspawnerhologram.internal.config.YuSpawnerHologramConfig.config
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.AdyeshachHologram.refreshHologramTextByADY
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.DecentHologram.refreshHologramByDH
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.DecentHologram.refreshHologramTextByDH
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HologramEnter.adyeshach
Expand All @@ -24,7 +25,7 @@ object HologramUpdateSubmit {
@Awake(LifeCycle.ENABLE)
fun hologramUpdateSubmitEnter() {
when {
// adyeshach != null -> hologramUpdateTimeForADY()
adyeshach != null -> hologramUpdateTimeForADY()
decentHolograms != null -> hologramUpdateTimeForDH()
holographicDisplays != null -> hologramUpdateTimeForHD()
}
Expand Down Expand Up @@ -82,6 +83,16 @@ object HologramUpdateSubmit {
}
}

private fun hologramUpdateTimeForADY() {
submit(delay = 40, period = 20) {
mirrorNow("Refresh HologramText") {
for (spawnerName in getConfigKeys(config, "hologramText")) {
refreshHologramTextByADY(spawnerName)
}
}
}
}

val activeMsg : String
get() = Coerce.toString(config["activeMsg"]).replace("&", "§") ?: "§a激活中"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,140 @@
package com.github.l1an.yuspawnerhologram.internal.core.mythichologram

import com.github.l1an.yuspawnerhologram.internal.compat.hook.HookMythicMobs.getSpawnerManager
import com.github.l1an.yuspawnerhologram.internal.config.YuSpawnerHologramConfig.config
import com.github.l1an.yuspawnerhologram.internal.core.HologramUpdateSubmit
import com.github.l1an.yuspawnerhologram.internal.util.MythicHologramUtils.getDisplayNameFromConfigs
import com.github.l1an.yuspawnerhologram.util.TimeUtils
import com.github.l1an.yuspawnerhologram.util.Utils.getConfigKeys
import ink.ptms.adyeshach.core.Adyeshach
import ink.ptms.adyeshach.core.AdyeshachHologram
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.command.CommandSender
import taboolib.common5.mirrorNow
import taboolib.module.configuration.Configuration
import taboolib.platform.util.sendLang

/**
* 处理为 Adyeshach 支持的 Hologram
* @author L1An
* @since 2023/10/24
*/
object AdyeshachHologram {
// 创建一个 map 用于存储 AdyeshachHologram 和其 name
private val holograms = mutableMapOf<String, AdyeshachHologram>()
private val api = Adyeshach.api().getHologramHandler()

/**
* 从配置文件中创建所有 hologram
* @return 创建出 hologram 并将其存入 Map : holograms 中
*/
fun createAllHologramByADY(sender : CommandSender) {
mirrorNow("Initialize Holograms") {
val keys = getConfigKeys(config, "hologramText")
var createdHologramCount = 0 // 用于跟踪成功创建的 hologram 的数量

for (spawnerName in keys) {
val hologram = createHologramByADY(spawnerName, sender)
if (hologram != null) createdHologramCount++
}
sender.sendLang("holo-refresh-all-success", createdHologramCount)
}
}

/**
* 创建 hologram
* @param name hologram 的名字
* @return 创建出 hologram 并将其存入 Map : hologramsByName 中
*/
private fun createHologramByADY(name : String, sender : CommandSender = Bukkit.getConsoleSender(), tip : Boolean = true) : AdyeshachHologram? {
if (holograms.containsKey(name) && tip) {
sender.sendLang("spawner-already-exist", name)
return null
}
val spawner = getSpawnerManager(name)

if (spawner == null) {
sender.sendLang("no-spawner", name)
return null
}

val location = Location(Bukkit.getWorld(spawner.worldName), spawner.location.x, spawner.location.y + 2, spawner.location.z)
val texts = getHologramTextForADY(
config,
name,
getDisplayNameFromConfigs(spawner.typeName)!!,
spawner.remainingWarmupSeconds
)
val hologram = api.createHologram(location, texts)

// 存储并返回 hologram
holograms[name] = hologram
return hologram
}

/**
* 刷新 hologram (删除后重新添加)
* @param spawnerName hologram 的名字
* @return 刷新 hologram 并返回信息
*/
fun refreshHologramByADY(spawnerName : String, sender : CommandSender = Bukkit.getConsoleSender(), tip : Boolean = false) {
mirrorNow("Refresh Hologram") {
val hologram = holograms[spawnerName]
if (hologram != null) {
hologram.remove()
createHologramByADY(spawnerName, sender, tip)
sender.sendLang("holo-refresh-success", spawnerName)
} else {
sender.sendLang("holo-refresh-fail", spawnerName)
}
}
}

/**
* 刷新 hologram 的内容
* @param spawnerName hologram 的名字
*/
fun refreshHologramTextByADY(spawnerName : String) {
val hologram = holograms[spawnerName]
val spawner = getSpawnerManager(spawnerName) ?: return
val texts = getHologramTextForADY(
config,
spawnerName,
getDisplayNameFromConfigs(spawner.typeName)!!,
spawner.remainingWarmupSeconds
)
hologram?.updateSafely(texts)
}

/**
* 从配置文件获取 hologram 的文本
* @param config 配置文件
* @param key hologram 的名字
* @param mobName 怪物的索引名
* @param warmupSeconds 怪物的预热时间
* @return 返回 hologram 的文本
*/
private fun getHologramTextForADY(
config : Configuration,
key : String,
mobName : String,
warmupSeconds : Int
) : List<String> {
val warmup = TimeUtils.secondToFormat(config, warmupSeconds, "durationFormat")
val texts = config.getStringList("hologramText.$key") ?: listOf()
val spawner = getSpawnerManager(key)

return texts.map {
var modifiedText = it.replace("%name%", mobName).replace("&", "§")
if (modifiedText.contains("%warmup%")) {
modifiedText = if (spawner?.isOnWarmup == true) {
modifiedText.replace("%warmup%", warmup)
} else {
modifiedText.replace("%warmup%", HologramUpdateSubmit.activeMsg)
}
}
modifiedText
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ object DecentHologram {
if (hologram != null) {
hologram.delete()
createHologramByDH(spawnerName, sender)
sender.sendLang("holo-refresh-success", spawnerName)
} else {
sender.sendLang("holo-refresh-fail", spawnerName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.l1an.yuspawnerhologram.internal.core.mythichologram

import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.AdyeshachHologram.createAllHologramByADY
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.DecentHologram.createAllHologramByDH
import com.github.l1an.yuspawnerhologram.internal.core.mythichologram.HolographicHologram.createAllHologramByHD
import me.filoghost.holographicdisplays.api.hologram.Hologram
Expand All @@ -21,12 +22,10 @@ object HologramEnter {
@Awake(LifeCycle.ACTIVE)
fun checkPlugin() {
when {
/**
adyeshach != null -> {
console().sendLang("dependency-found", "Adyeshach")
createAllHologramByADY(Bukkit.getConsoleSender())
}
*/
decentHolograms != null -> {
console().sendLang("dependency-found", "DecentHolograms")
createAllHologramByDH(Bukkit.getConsoleSender())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ object HolographicHologram {
fun createAllHologramByHD(sender : CommandSender) {
mirrorNow("Initialize Holograms") {
val keys = getConfigKeys(config, "hologramText")
var createdHologramsCount = 0 // 用于跟踪成功创建的hologram的数量
var createdHologramsCount = 0 // 用于跟踪成功创建的 hologram 的数量

for (spawnerName in keys) {
val hologram = createHologramByHD(spawnerName)
if (hologram != null) {
createdHologramsCount++ // 成功创建hologram,增加计数器
}
if (hologram != null) createdHologramsCount++ // 成功创建hologram,增加计数器
}
sender.sendLang("holo-refresh-all-success", createdHologramsCount)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/config-en.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Translate From ChatGPT, please forgive me for any mistakes
# Translate By ChatGPT, please forgive me for any mistakes

# Choose the plugin that hologram depends on, available options: adyeshach, HolographicDisplays, DecentHolograms
# Please install at least one of the above plugins as a prerequisite dependency
# The priority of the dependency is: adyeshach > DecentHolograms > HolographicDisplays
# The priority of the dependency is: Adyeshach > DecentHolograms > HolographicDisplays
dependency: 'adyeshach'

# Time format, supported placeholders are: %HH% hours %mm% minutes %ss% seconds
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 选择hologram依赖的插件,可选adyeshach, HolographicDisplays, DecentHolograms
# 请至少安装上述任意一种插件作为前置依赖,依赖的优先级为: adyeshach > DecentHolograms > HolographicDisplays
# 请至少安装上述任意一种插件作为前置依赖,依赖的优先级为: Adyeshach > DecentHolograms > HolographicDisplays
dependency: 'adyeshach'

# 时间格式,支持的占位符有: %HH%小时 %mm%分钟 %ss%秒钟
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Translate By ChatGPT, please forgive me for any mistakes
# If you would like to contribute to the translation, please contact me or pull request on GitHub

command-reload: ' &f| &bYuSpawnerHologram &f| &aPlugin has been successfully reloaded'

dependency-found: ' &f| &bYuSpawnerHologram &f| &aDetected &e{0} &aplugin, &e{0} &acompatibility enabled!'
dependency-not-found: ' &f| &bYuSpawnerHologram &f| &cNo dependencies found! Plugin has been shut down!'

holo-refresh-all-success: ' &f| &bYuSpawnerHologram &f| &aSuccess! All Holograms refreshed from the config file, total &e{0}&a'
holo-refresh-success: ' &f| &bYuSpawnerHologram &f| &aSuccess! Hologram &e{0} &arefreshed'
holo-refresh-fail: ' &f| &bYuSpawnerHologram &f| &cFailure! Hologram &e{0} &anot found'
spawner-already-exist: " &f| &bYuSpawnerHologram &f| &cThe Spawner's corresponding Hologram already exists! ({0})"
no-spawner: ' &f| &bYuSpawnerHologram &f| &cSpawner {0} not found!'
13 changes: 13 additions & 0 deletions src/main/resources/lang/fr_FR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Transformer par ChatGPT, veuillez me pardonner pour toute erreur
# Si vous souhaitez contribuer à la traduction, contactez-moi ou demandez un pull sur GitHub SVP

command-reload: ' &f| &bYuSpawnerHologram &f| &aLe plugin a été rechargé avec succès'

dependency-found: ' &f| &bYuSpawnerHologram &f| &aDétection du plugin &e{0} &a, compatibilité avec &e{0} &aactivée!'
dependency-not-found: ' &f| &bYuSpawnerHologram &f| &cAucune dépendance trouvée! Le plugin a été désactivé!'

holo-refresh-all-success: ' &f| &bYuSpawnerHologram &f| &aSuccès! Tous les Hologrammes ont été actualisés à partir du fichier de configuration, total &e{0}&a'
holo-refresh-success: ' &f| &bYuSpawnerHologram &f| &aSuccès! Hologramme &e{0} actualisé'
holo-refresh-fail: ' &f| &bYuSpawnerHologram &f| &cÉchec! Hologramme &e{0} introuvable'
spawner-already-exist: " &f| &bYuSpawnerHologram &f| &cL'Hologramme correspondant au Spawner existe déjà! ({0})"
no-spawner: ' &f| &bYuSpawnerHologram &f| &cSpawner {0} introuvable!'
7 changes: 3 additions & 4 deletions src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
command-reload: ' &f| &bYuSpawnerHologram &f| &a插件已重载成功'
debug-mode: ' &f| &bYuSpawnerHologram &f| &cDebug模式已启动!!!'

dependency-found: ' &f| &bYuSpawnerHologram &f| &a检测到 &e{0} &a插件,已启用 &e{0} &a兼容!'
dependency-not-found: ' &f| &bYuSpawnerHologram &f| &c未检测到任何依赖! 插件已关闭!'

holo-refresh-all-success: ' &f| &bYuSpawnerHologram &f| &a成功! 已从配置文件刷新所有 Hologram, 共&e{0}&a个'
holo-refresh-success: ' &f| &bTOBCore &f| &a成功! 已刷新 Hologram: &e{0}'
holo-refresh-fail: ' &f| &bTOBCore &f| &c失败! 未找到 Hologram: &e{0}'
holo-refresh-success: ' &f| &bYuSpawnerHologram &f| &a成功! 已刷新 Hologram: &e{0}'
holo-refresh-fail: ' &f| &bYuSpawnerHologram &f| &c失败! 未找到 Hologram: &e{0}'
spawner-already-exist: ' &f| &bYuSpawnerHologram &f| &c该 Spawner 对应的 Hologram 已存在! ({0})'
no-spawner: ' &f| &bTOBCore &f| &c未找到 Spawner: {0}!'
no-spawner: ' &f| &bYuSpawnerHologram &f| &c未找到 Spawner: {0}!'
Loading

0 comments on commit 4674fe2

Please sign in to comment.