mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
bossbar api
This commit is contained in:
parent
c148102a7a
commit
e9287bbb44
26
src/main/java/de/bixilon/minosoft/data/bossbar/Bossbar.kt
Normal file
26
src/main/java/de/bixilon/minosoft/data/bossbar/Bossbar.kt
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
|
||||
data class Bossbar(
|
||||
var title: ChatComponent = ChatComponent.EMPTY,
|
||||
var value: Float = 0.0f,
|
||||
var color: BossbarColors = BossbarColors.PINK,
|
||||
var notches: BossbarNotches = BossbarNotches.NO_NOTCHES,
|
||||
var shouldDarkenSky: Boolean = false,
|
||||
var dragonBar: Boolean = false,
|
||||
var fog: Boolean = false,
|
||||
)
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
package de.bixilon.minosoft.data.bossbar
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.bossbar
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||
import java.util.*
|
||||
|
||||
class BossbarManager {
|
||||
val bossbars: MutableMap<UUID, Bossbar> = synchronizedMapOf()
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
package de.bixilon.minosoft.data.bossbar
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.registries.ResourceLocation;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
@Deprecated
|
||||
public class Recipes {
|
||||
private final HashSet<Recipe> recipeList = new HashSet<>();
|
||||
private final HashBiMap<Integer, Recipe> recipeIdMap = HashBiMap.create(); // ids for version <= VERSION_1_12_2
|
||||
|
@ -12,7 +12,9 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.data.scoreboard
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||
|
||||
class ScoreboardManager {
|
||||
val teams: MutableMap<String, Team> = mutableMapOf()
|
||||
val objectives: MutableMap<String, ScoreboardObjective> = mutableMapOf()
|
||||
val teams: MutableMap<String, Team> = synchronizedMapOf()
|
||||
val objectives: MutableMap<String, ScoreboardObjective> = synchronizedMapOf()
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarAddEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
abstract class BossbarEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
val uuid: UUID,
|
||||
val bossbar: Bossbar,
|
||||
) : PlayConnectionEvent(connection, initiator)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarFlagsSetEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarRemoveEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarStyleSetEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarTitleSetEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.modding.event.events.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import java.util.*
|
||||
|
||||
class BossbarValueSetEvent(
|
||||
connection: PlayConnection,
|
||||
initiator: EventInitiators,
|
||||
uuid: UUID,
|
||||
bossbar: Bossbar,
|
||||
) : BossbarEvent(connection, initiator, uuid, bossbar)
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.data.ChatTextPositions
|
||||
import de.bixilon.minosoft.data.accounts.Account
|
||||
import de.bixilon.minosoft.data.assets.MultiAssetsManager
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarManager
|
||||
import de.bixilon.minosoft.data.commands.CommandRootNode
|
||||
import de.bixilon.minosoft.data.physics.CollisionDetector
|
||||
import de.bixilon.minosoft.data.player.LocalPlayerEntity
|
||||
@ -66,11 +67,12 @@ class PlayConnection(
|
||||
val account: Account,
|
||||
val version: Version,
|
||||
) : Connection() {
|
||||
val registries = Registries()
|
||||
val recipes = Recipes()
|
||||
val world = World(this)
|
||||
val tabList = TabList()
|
||||
val scoreboardManager = ScoreboardManager()
|
||||
val registries = Registries()
|
||||
val bossbarManager = BossbarManager()
|
||||
|
||||
@Deprecated(message = "PacketSender is deprecated")
|
||||
val sender = PacketSender(this)
|
||||
|
@ -13,8 +13,15 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.Bossbar
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarColors
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarNotches
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarAddEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
|
||||
import de.bixilon.minosoft.util.BitByte.isBitMask
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@ -24,13 +31,43 @@ class BossbarAddS2CP(
|
||||
val uuid: UUID,
|
||||
buffer: InByteBuffer,
|
||||
) : PlayS2CPacket() {
|
||||
val name = buffer.readChatComponent()
|
||||
val health = buffer.readFloat()
|
||||
val title = buffer.readChatComponent()
|
||||
val value = buffer.readFloat()
|
||||
val color = BossbarColors[buffer.readVarInt()]
|
||||
val notches = BossbarNotches[buffer.readVarInt()]
|
||||
val flags = buffer.readUnsignedByte() // ToDo
|
||||
val shouldDarkenSky: Boolean
|
||||
val dragonBar: Boolean
|
||||
val fog: Boolean
|
||||
|
||||
init {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
shouldDarkenSky = flags.isBitMask(BossbarFlags.SHOULD_DARKEN_SKY_MASK)
|
||||
dragonBar = flags.isBitMask(BossbarFlags.DRAGON_BAR_MASK)
|
||||
fog = flags.isBitMask(BossbarFlags.FOG_MASK)
|
||||
}
|
||||
|
||||
override fun check(connection: PlayConnection) {
|
||||
check(value in 0.0f..1.0f) { "Value of of bounds!" }
|
||||
}
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = Bossbar(
|
||||
title = title,
|
||||
value = value,
|
||||
color = color,
|
||||
notches = notches,
|
||||
shouldDarkenSky = shouldDarkenSky,
|
||||
dragonBar = dragonBar,
|
||||
fog = fog,
|
||||
)
|
||||
|
||||
// ToDo: Check if bossbar is already present
|
||||
connection.bossbarManager.bossbars[uuid] = bossbar
|
||||
|
||||
connection.fireEvent(BossbarAddEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar add (uuid=$uuid, name=\"$name\", health=$health, color=$color, notches=$notches, flags=$flags)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar add (uuid=$uuid, title=\"$title\", health=$value, color=$color, notches=$notches, shouldDarkenSky=$shouldDarkenSky, dragonBar=$dragonBar, fog=$fog)" }
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,12 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarFlagsSetEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
|
||||
import de.bixilon.minosoft.util.BitByte.isBitMask
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
@ -24,9 +28,42 @@ class BossbarFlagSetS2CP(
|
||||
val uuid: UUID,
|
||||
buffer: InByteBuffer,
|
||||
) : PlayS2CPacket() {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
val shouldDarkenSky: Boolean
|
||||
val dragonBar: Boolean
|
||||
val fog: Boolean
|
||||
|
||||
init {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
shouldDarkenSky = flags.isBitMask(BossbarFlags.SHOULD_DARKEN_SKY_MASK)
|
||||
dragonBar = flags.isBitMask(BossbarFlags.DRAGON_BAR_MASK)
|
||||
fog = flags.isBitMask(BossbarFlags.FOG_MASK)
|
||||
}
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = connection.bossbarManager.bossbars[uuid] ?: return
|
||||
|
||||
var changes = 0
|
||||
|
||||
if (bossbar.shouldDarkenSky != shouldDarkenSky) {
|
||||
bossbar.shouldDarkenSky = shouldDarkenSky
|
||||
changes++
|
||||
}
|
||||
if (bossbar.dragonBar != dragonBar) {
|
||||
bossbar.dragonBar = dragonBar
|
||||
changes++
|
||||
}
|
||||
if (bossbar.fog != fog) {
|
||||
bossbar.fog = fog
|
||||
changes++
|
||||
}
|
||||
if (changes == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
connection.fireEvent(BossbarFlagsSetEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar flags set (uuid=$uuid, flags=$flags)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar flags set (uuid=$uuid, shouldDarkenSky=$shouldDarkenSky, dragonBar=$dragonBar, fog=$fog)" }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
object BossbarFlags {
|
||||
const val SHOULD_DARKEN_SKY_MASK = 0x01
|
||||
const val DRAGON_BAR_MASK = 0x02
|
||||
const val FOG_MASK = 0x04
|
||||
}
|
@ -13,6 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarRemoveEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
@ -23,6 +26,11 @@ class BossbarRemoveS2CP(
|
||||
val uuid: UUID,
|
||||
) : PlayS2CPacket() {
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = connection.bossbarManager.bossbars.remove(uuid) ?: return
|
||||
connection.fireEvent(BossbarRemoveEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar remove (uuid=$uuid)" }
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ object BossbarS2CPF {
|
||||
return when (BossBarActions[buffer.readVarInt()]) {
|
||||
BossBarActions.ADD -> BossbarAddS2CP(uuid, buffer)
|
||||
BossBarActions.REMOVE -> BossbarRemoveS2CP(uuid)
|
||||
BossBarActions.SET_HEALTH -> BossbarHealthSetS2CP(uuid, buffer)
|
||||
BossBarActions.SET_NAME -> BossbarNameSetS2CP(uuid, buffer)
|
||||
BossBarActions.SET_VALUE -> BossbarValueSetS2CP(uuid, buffer)
|
||||
BossBarActions.SET_TITLE -> BossbarTitleSetS2CP(uuid, buffer)
|
||||
BossBarActions.SET_STYLE -> BossbarStyleSetS2CP(uuid, buffer)
|
||||
BossBarActions.SET_FLAGS -> BossbarFlagSetS2CP(uuid, buffer)
|
||||
}
|
||||
@ -35,8 +35,8 @@ object BossbarS2CPF {
|
||||
enum class BossBarActions {
|
||||
ADD,
|
||||
REMOVE,
|
||||
SET_HEALTH,
|
||||
SET_NAME,
|
||||
SET_VALUE,
|
||||
SET_TITLE,
|
||||
SET_STYLE,
|
||||
SET_FLAGS,
|
||||
;
|
||||
|
@ -13,6 +13,11 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarColors
|
||||
import de.bixilon.minosoft.data.bossbar.BossbarNotches
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarStyleSetEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
@ -27,6 +32,26 @@ class BossbarStyleSetS2CP(
|
||||
val color = BossbarColors[buffer.readVarInt()]
|
||||
val notches = BossbarNotches[buffer.readVarInt()]
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = connection.bossbarManager.bossbars[uuid] ?: return
|
||||
|
||||
var changes = 0
|
||||
|
||||
if (bossbar.color != color) {
|
||||
bossbar.color = color
|
||||
changes++
|
||||
}
|
||||
if (bossbar.notches != notches) {
|
||||
bossbar.notches = notches
|
||||
changes++
|
||||
}
|
||||
if (changes == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
connection.fireEvent(BossbarStyleSetEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar style set (uuid=$uuid, color=$color, notches=$notches)" }
|
||||
}
|
||||
|
@ -14,6 +14,9 @@
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarTitleSetEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
@ -21,16 +24,28 @@ import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import java.util.*
|
||||
|
||||
class BossbarNameSetS2CP(
|
||||
class BossbarTitleSetS2CP(
|
||||
val uuid: UUID,
|
||||
buffer: InByteBuffer,
|
||||
) : PlayS2CPacket() {
|
||||
val name = buffer.readChatComponent()
|
||||
val title = buffer.readChatComponent()
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = connection.bossbarManager.bossbars[uuid] ?: return
|
||||
|
||||
if (bossbar.title == title) {
|
||||
return
|
||||
}
|
||||
bossbar.title = title
|
||||
|
||||
connection.fireEvent(BossbarTitleSetEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
if (Minosoft.config.config.general.reduceProtocolLog) {
|
||||
// servers have sometimes "animated" bossbars
|
||||
return
|
||||
}
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar name set (uuid=$uuid, name=\"$name\")" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar name set (uuid=$uuid, title=\"$title\")" }
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play.bossbar
|
||||
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.modding.event.events.bossbar.BossbarValueSetEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
@ -20,13 +23,28 @@ import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import java.util.*
|
||||
|
||||
class BossbarHealthSetS2CP(
|
||||
class BossbarValueSetS2CP(
|
||||
val uuid: UUID,
|
||||
buffer: InByteBuffer,
|
||||
) : PlayS2CPacket() {
|
||||
val health = buffer.readFloat()
|
||||
val value = buffer.readFloat()
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val bossbar = connection.bossbarManager.bossbars[uuid] ?: return
|
||||
|
||||
if (bossbar.value == value) {
|
||||
return
|
||||
}
|
||||
bossbar.value = value
|
||||
|
||||
connection.fireEvent(BossbarValueSetEvent(connection, EventInitiators.SERVER, uuid, bossbar))
|
||||
}
|
||||
|
||||
override fun check(connection: PlayConnection) {
|
||||
check(value in 0.0f..1.0f) { "Value of of bounds!" }
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar health set (uuid=$uuid, health=$health)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Bossbar value set (uuid=$uuid, value=$value)" }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user