Skip to content

Commit

Permalink
Fixes packet issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Mar 22, 2024
1 parent 90c8556 commit a7132bf
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 17 deletions.
1 change: 1 addition & 0 deletions api/src/main/java/kr/toxicity/hud/api/BetterHud.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void onLoad() {
public abstract @NotNull HudScheduler getScheduler();
public abstract @NotNull BedrockAdapter getBedrockAdapter();
public abstract boolean isFolia();
public abstract boolean isMergeBossBar();
public abstract void loadAssets(@NotNull String prefix, @NotNull File dir);
public abstract int getWidth(char target);
public abstract @NotNull HudPlayer getHudPlayer(@NotNull Player player);
Expand Down
1 change: 1 addition & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class BetterHudImpl: BetterHud() {

override fun getScheduler(): HudScheduler = scheduler
override fun isFolia(): Boolean = isFolia
override fun isMergeBossBar(): Boolean = ConfigManager.mergeBossBar
override fun getPlaceholderManager(): PlaceholderManager = PlaceholderManagerImpl
override fun getListenerManager(): ListenerManager = ListenerManagerImpl
override fun getPopupManager(): PopupManager = PopupManagerImpl
Expand Down
4 changes: 4 additions & 0 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ object ConfigManager: BetterHudManager {
var separateResourcePackNameSpace = false
private set

var mergeBossBar = true
private set

override fun start() {

}
Expand Down Expand Up @@ -65,6 +68,7 @@ object ConfigManager: BetterHudManager {
yaml.getString("build-folder-location")?.let {
buildFolderLocation = it
}
mergeBossBar = yaml.getBoolean("merge-boss-bar", true)
}.onFailure { e ->
warn("Unable to load config.yml")
warn("Reason: ${e.message}")
Expand Down
1 change: 1 addition & 0 deletions dist/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tick-speed: 1

default-font-name: "font.ttf"

merge-boss-bar: true
disable-to-bedrock-player: true
build-folder-location: "BetterHud/build"
separate-resource-pack-namespace: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_17_R1

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -321,8 +322,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -331,6 +332,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_18_R1

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -322,8 +323,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -332,6 +333,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_18_R2

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -325,8 +326,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -335,6 +336,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_19_R1

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -325,8 +326,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -335,6 +336,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_19_R2

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -325,8 +326,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -335,6 +336,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_19_R3

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -324,8 +325,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -334,6 +335,11 @@ class NMSImpl: NMS {
}
}
}
private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}

private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.toxicity.hud.nms.v1_20_R1

import com.mojang.authlib.GameProfile
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelDuplexHandler
import io.netty.channel.ChannelHandlerContext
Expand Down Expand Up @@ -324,8 +325,8 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = HudByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
writeBossBar(buf, ctx, msg, promise)
Expand All @@ -334,7 +335,11 @@ class NMSImpl: NMS {
}
}
}

private class HudByteBuf(val source: ByteBuf): FriendlyByteBuf(source) {
override fun unwrap(): ByteBuf {
return source
}
}
private class HudBossBar(uuid: UUID, component: Component, color: BarColor): BossEvent(uuid, fromAdventure(component), getColor(color), BossBarOverlay.PROGRESS) {
override fun getProgress(): Float {
return 0F
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class NMSImpl: NMS {
}

override fun write(ctx: ChannelHandlerContext?, msg: Any?, promise: ChannelPromise?) {
if (msg is ClientboundBossEventPacket) {
if (BetterHud.getInstance().isMergeBossBar && msg is ClientboundBossEventPacket) {
val buf = FriendlyByteBuf(Unpooled.buffer(1 shl 4)).apply {
msg.write(this)
}
Expand Down

0 comments on commit a7132bf

Please sign in to comment.