Skip to content

Commit

Permalink
[6.0.11][publish] Experimental > update porticus & bossbar language type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bkm016 committed Jul 10, 2023
1 parent 2682eea commit 4f40bce
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Any>) {
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')"
}
}

0 comments on commit 4f40bce

Please sign in to comment.