From 4f40bcec01257e7f90c7f56271135e0470893268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 10 Jul 2023 19:15:26 +0800 Subject: [PATCH] [6.0.11][publish] Experimental > update porticus & bossbar language type --- .../porticus/bungeeside/MissionBungee.java | 7 ++ .../java/taboolib/platform/BukkitPlugin.java | 7 ++ .../taboolib/platform/lang/TypeBossBar.kt | 72 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 platform/platform-bukkit/src/main/kotlin/taboolib/platform/lang/TypeBossBar.kt diff --git a/module/module-porticus/src/main/java/taboolib/module/porticus/bungeeside/MissionBungee.java b/module/module-porticus/src/main/java/taboolib/module/porticus/bungeeside/MissionBungee.java index 763829c29..df5ea82e9 100644 --- a/module/module-porticus/src/main/java/taboolib/module/porticus/bungeeside/MissionBungee.java +++ b/module/module-porticus/src/main/java/taboolib/module/porticus/bungeeside/MissionBungee.java @@ -1,6 +1,7 @@ package taboolib.module.porticus.bungeeside; import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.plugin.Plugin; @@ -36,6 +37,8 @@ public void run(@NotNull Object target) { super.run(target); if (target instanceof Server) { sendBungeeMessage((Server) target, command); + } else if (target instanceof ServerInfo) { + sendBungeeMessage((ServerInfo) target, command); } else if (target instanceof ProxiedPlayer) { sendBungeeMessage((ProxiedPlayer) target, command); } else { @@ -48,6 +51,10 @@ public static void sendBungeeMessage(ProxiedPlayer player, String... args) { } public static void sendBungeeMessage(Server server, String... args) { + sendBungeeMessage(server.getInfo(), args); + } + + public static void sendBungeeMessage(ServerInfo server, String... args) { BungeeCord.getInstance().getScheduler().runAsync(plugin, () -> { try { for (byte[] bytes : MessageBuilder.create(args)) { diff --git a/platform/platform-bukkit/src/main/java/taboolib/platform/BukkitPlugin.java b/platform/platform-bukkit/src/main/java/taboolib/platform/BukkitPlugin.java index 7e2f45110..f7e46a0a8 100644 --- a/platform/platform-bukkit/src/main/java/taboolib/platform/BukkitPlugin.java +++ b/platform/platform-bukkit/src/main/java/taboolib/platform/BukkitPlugin.java @@ -15,6 +15,8 @@ import taboolib.common.platform.PlatformSide; import taboolib.common.platform.Plugin; import taboolib.common.platform.function.ExecutorKt; +import taboolib.module.lang.Language; +import taboolib.platform.lang.TypeBossBar; import java.io.File; import java.net.URL; @@ -56,6 +58,11 @@ public class BukkitPlugin extends JavaPlugin { if (TabooLibCommon.isKotlinEnvironment()) { pluginInstance = Project1Kt.findImplementation(Plugin.class); } + // 注册语言文件 + try { + Language.INSTANCE.getLanguageType().put("boss", TypeBossBar.class); + } catch (Throwable ignored) { + } } } diff --git a/platform/platform-bukkit/src/main/kotlin/taboolib/platform/lang/TypeBossBar.kt b/platform/platform-bukkit/src/main/kotlin/taboolib/platform/lang/TypeBossBar.kt new file mode 100644 index 000000000..e3a404e3f --- /dev/null +++ b/platform/platform-bukkit/src/main/kotlin/taboolib/platform/lang/TypeBossBar.kt @@ -0,0 +1,72 @@ +package taboolib.platform.lang + +import org.bukkit.Bukkit +import org.bukkit.boss.BarColor +import org.bukkit.boss.BarStyle +import taboolib.common.platform.ProxyCommandSender +import taboolib.common.platform.ProxyPlayer +import taboolib.common.platform.function.submit +import taboolib.common.platform.function.warning +import taboolib.common.util.replaceWithOrder +import taboolib.common5.cdouble +import taboolib.common5.clong +import taboolib.module.lang.Type + +/** + * TabooLib + * taboolib.module.lang.TypeBossBar + * + * @author sky + * @since 2021/6/20 10:55 下午 + */ +class TypeBossBar : Type { + + var text: String? = null + var color = BarColor.WHITE + var style = BarStyle.SOLID + var step = 0.01 + var period = 2L + var method = "INCREASE" + + override fun init(source: Map) { + text = source["text"]?.toString() + color = BarColor.values().find { it.name == source["color"].toString().uppercase() } ?: BarColor.WHITE + style = BarStyle.values().find { it.name == source["style"].toString().uppercase() } ?: BarStyle.SOLID + step = source["step"]?.cdouble ?: 0.01 + period = source["period"]?.clong ?: 2L + method = source["method"]?.toString()?.uppercase() ?: "INCREASE" + // 合法性检查 + if (text == null) { + warning("Missing BossBar text.") + } + if (method != "INCREASE" && method != "DECREASE") { + warning("Unknown method $method, use INCREASE or DECREASE.") + } + } + + override fun send(sender: ProxyCommandSender, vararg args: Any) { + if (text == null) { + return + } + if (sender is ProxyPlayer) { + val bossBar = Bukkit.createBossBar(text!!.translate(sender, *args).replaceWithOrder(*args), color, style) + bossBar.progress = if (method == "INCREASE") 0.0 else 1.0 + bossBar.addPlayer(sender.cast()) + submit(period = period) { + val progress = bossBar.progress + if (method == "INCREASE") step else -step + if (progress in 0.0..1.0) { + bossBar.progress = progress + } else { + bossBar.removeAll() + cancel() + } + } + } else { + sender.sendMessage(toString()) + } + } + + override fun toString(): String { + return "TypeBossBar(text=$text, color=$color, style=$style, step=$step, period=$period, method='$method')" + } +} \ No newline at end of file