-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ 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
Showing
17 changed files
with
222 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...otlin/com/github/l1an/yuspawnerhologram/internal/core/mythichologram/AdyeshachHologram.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}!' |
Oops, something went wrong.