diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/DefaultRegistries.kt b/src/main/java/de/bixilon/minosoft/data/mappings/DefaultRegistries.kt index bea608a68..fbed3af4c 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/DefaultRegistries.kt +++ b/src/main/java/de/bixilon/minosoft/data/mappings/DefaultRegistries.kt @@ -16,7 +16,7 @@ package de.bixilon.minosoft.data.mappings import de.bixilon.minosoft.Minosoft import de.bixilon.minosoft.data.entities.meta.EntityMetaData import de.bixilon.minosoft.data.inventory.InventorySlots -import de.bixilon.minosoft.protocol.packets.clientbound.play.title.PacketTitle +import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitlePacketFactory import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap object DefaultRegistries { @@ -30,7 +30,7 @@ object DefaultRegistries { val ENTITY_META_DATA_DATA_TYPES_REGISTRY = PerVersionRegistry(EntityMetaData.EntityMetaDataDataTypes) - val TITLE_ACTIONS_REGISTRY = PerVersionRegistry(PacketTitle.TitleActions) + val TITLE_ACTIONS_REGISTRY = PerVersionRegistry(TitlePacketFactory.TitleActions) fun load() { diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.kt b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.kt index 783abe457..cd5d7e6e2 100644 --- a/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.kt +++ b/src/main/java/de/bixilon/minosoft/data/mappings/versions/VersionMapping.kt @@ -40,7 +40,7 @@ import de.bixilon.minosoft.data.mappings.statistics.Statistic import de.bixilon.minosoft.gui.rendering.chunk.VoxelShape import de.bixilon.minosoft.gui.rendering.chunk.models.AABB import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel -import de.bixilon.minosoft.protocol.packets.clientbound.play.title.PacketTitle +import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitlePacketFactory import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.collections.Clearable import de.bixilon.minosoft.util.json.ResourceLocationJsonMap.toResourceLocationMap @@ -67,7 +67,7 @@ class VersionMapping(var version: Version?) { val entityMetaDataDataDataTypesRegistry: EnumRegistry = EnumRegistry(values = EntityMetaData.EntityMetaDataDataTypes) - val titleActionsRegistry: EnumRegistry = EnumRegistry(values = PacketTitle.TitleActions) + val titleActionsRegistry: EnumRegistry = EnumRegistry(values = TitlePacketFactory.TitleActions) val creativeModeTabRegistry: FakeEnumRegistry = FakeEnumRegistry() diff --git a/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java b/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java deleted file mode 100644 index b1e089d13..000000000 --- a/src/main/java/de/bixilon/minosoft/modding/event/events/TitleChangeEvent.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.modding.event.events; - -import de.bixilon.minosoft.data.text.ChatComponent; -import de.bixilon.minosoft.protocol.network.Connection; -import de.bixilon.minosoft.protocol.packets.clientbound.play.title.PacketTitle; - -public class TitleChangeEvent extends CancelableEvent { - private final PacketTitle.TitleActions action; - - // fields depend on action - private final ChatComponent text; - private final ChatComponent subText; - private final int fadeInTime; - private final int stayTime; - private final int fadeOutTime; - - public TitleChangeEvent(Connection connection, PacketTitle.TitleActions action, ChatComponent text, ChatComponent subText, int fadeInTime, int stayTime, int fadeOutTime) { - super(connection); - this.action = action; - this.text = text; - this.subText = subText; - this.fadeInTime = fadeInTime; - this.stayTime = stayTime; - this.fadeOutTime = fadeOutTime; - } - - public TitleChangeEvent(Connection connection, PacketTitle pkg) { - super(connection); - this.action = pkg.getAction(); - this.text = pkg.getText(); - this.subText = pkg.getSubText(); - this.fadeInTime = pkg.getFadeInTime(); - this.stayTime = pkg.getStayTime(); - this.fadeOutTime = pkg.getFadeOutTime(); - } - - public PacketTitle.TitleActions getAction() { - return this.action; - } - - public ChatComponent getText() { - return this.text; - } - - public ChatComponent getSubText() { - return this.subText; - } - - public int getFadeInTime() { - return this.fadeInTime; - } - - public int getStayTime() { - return this.stayTime; - } - - public int getFadeOutTime() { - return this.fadeOutTime; - } -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/HideTitlePacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/HideTitlePacket.kt new file mode 100644 index 000000000..93609b24b --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/HideTitlePacket.kt @@ -0,0 +1,25 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class HideTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { + + override fun log() { + Log.protocol("[IN] Received hide title") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/PacketTitle.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/PacketTitle.kt deleted file mode 100644 index 40f16ac42..000000000 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/PacketTitle.kt +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ -package de.bixilon.minosoft.protocol.packets.clientbound.play.title - -import de.bixilon.minosoft.data.text.ChatComponent -import de.bixilon.minosoft.modding.event.events.TitleChangeEvent -import de.bixilon.minosoft.protocol.network.Connection -import de.bixilon.minosoft.protocol.packets.ClientboundPacket -import de.bixilon.minosoft.protocol.protocol.InByteBuffer -import de.bixilon.minosoft.util.KUtil -import de.bixilon.minosoft.util.enum.ValuesEnum -import de.bixilon.minosoft.util.logging.Log - -class PacketTitle(buffer: InByteBuffer) : ClientboundPacket() { - val action: TitleActions - - // fields depend on action - var text: ChatComponent? = null - var subText: ChatComponent? = null - var fadeInTime = 0 - var stayTime = 0 - var fadeOutTime = 0 - - init { - action = buffer.connection.mapping.titleActionsRegistry.get(buffer.readVarInt())!! - when (action) { - TitleActions.SET_TITLE -> this.text = buffer.readChatComponent() - TitleActions.SET_SUBTITLE -> this.subText = buffer.readChatComponent() - TitleActions.SET_TIMES_AND_DISPLAY -> { - this.fadeInTime = buffer.readInt() - this.stayTime = buffer.readInt() - this.fadeOutTime = buffer.readInt() - } - else -> { - } - } - } - - override fun handle(connection: Connection) { - if (connection.fireEvent(TitleChangeEvent(connection, this))) { - return - } - } - - override fun log() { - when (this.action) { - TitleActions.SET_TITLE -> Log.protocol(String.format("[IN] Received title (action=%s, text=%s)", this.action, this.text?.ansiColoredMessage)) - TitleActions.SET_SUBTITLE -> Log.protocol(String.format("[IN] Received title (action=%s, subText=%s)", this.action, this.subText?.ansiColoredMessage)) - TitleActions.SET_TIMES_AND_DISPLAY -> Log.protocol(String.format("[IN] Received title (action=%s, fadeInTime=%d, stayTime=%d, fadeOutTime=%d)", this.action, this.fadeInTime, this.stayTime, this.fadeOutTime)) - TitleActions.HIDE, TitleActions.RESET -> Log.protocol(String.format("[IN] Received title (action=%s)", this.action)) - } - } - - enum class TitleActions { - SET_TITLE, - SET_SUBTITLE, - SET_ACTION_BAR, - SET_TIMES_AND_DISPLAY, - HIDE, - RESET, - ; - - companion object : ValuesEnum { - override val VALUES = values() - override val NAME_MAP = KUtil.getEnumValues(VALUES) - } - } -} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/ResetTitlePacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/ResetTitlePacket.kt new file mode 100644 index 000000000..fb838d559 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/ResetTitlePacket.kt @@ -0,0 +1,25 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class ResetTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { + + override fun log() { + Log.protocol("[IN] Received reset title") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetActionBarTextPacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetActionBarTextPacket.kt new file mode 100644 index 000000000..23cdc30c8 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetActionBarTextPacket.kt @@ -0,0 +1,31 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.network.Connection +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class SetActionBarTextPacket(buffer: InByteBuffer) : ClientboundPacket() { + val actionBarText = buffer.readChatComponent() + + override fun log() { + Log.protocol("[IN] Received set action bar title (actionBarText=$actionBarText)") + } + + override fun handle(connection: Connection) { + Log.game("[ACTION] $actionBarText") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetSubTitlePacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetSubTitlePacket.kt new file mode 100644 index 000000000..0b36059ea --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetSubTitlePacket.kt @@ -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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class SetSubTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { + val subTtitle = buffer.readChatComponent() + + override fun log() { + Log.protocol("[IN] Received title (subText=$subTtitle)") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTimesAndDisplayPacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTimesAndDisplayPacket.kt new file mode 100644 index 000000000..72dbdfe99 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTimesAndDisplayPacket.kt @@ -0,0 +1,28 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class SetTimesAndDisplayPacket(buffer: InByteBuffer) : ClientboundPacket() { + val fadeInTime = buffer.readInt() + val stayTime = buffer.readInt() + val fadeOutTime = buffer.readInt() + + override fun log() { + Log.protocol("[IN] Received set time and display title (fadeInTime=$fadeInTime, stayTime=$stayTime, fadeOutTime=$fadeOutTime)") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTitlePacket.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTitlePacket.kt new file mode 100644 index 000000000..bdd52eb8d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/SetTitlePacket.kt @@ -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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.logging.Log + +class SetTitlePacket(buffer: InByteBuffer) : ClientboundPacket() { + val text = buffer.readChatComponent() + + override fun log() { + Log.protocol("[IN] Received set title (text=$text)") + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/TitlePacketFactory.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/TitlePacketFactory.kt new file mode 100644 index 000000000..8a334fd51 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/title/TitlePacketFactory.kt @@ -0,0 +1,48 @@ +/* + * 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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.clientbound.play.title + +import de.bixilon.minosoft.protocol.packets.ClientboundPacket +import de.bixilon.minosoft.protocol.protocol.InByteBuffer +import de.bixilon.minosoft.util.KUtil +import de.bixilon.minosoft.util.enum.ValuesEnum + +object TitlePacketFactory { + + fun createPacket(buffer: InByteBuffer): ClientboundPacket { + return when (buffer.connection.mapping.titleActionsRegistry.get(buffer.readVarInt())!!) { + TitleActions.SET_TITLE -> SetTitlePacket(buffer) + TitleActions.SET_SUBTITLE -> SetSubTitlePacket(buffer) + TitleActions.SET_ACTION_BAR -> SetActionBarTextPacket(buffer) + TitleActions.SET_TIMES_AND_DISPLAY -> SetTimesAndDisplayPacket(buffer) + TitleActions.HIDE -> HideTitlePacket(buffer) + TitleActions.RESET -> ResetTitlePacket(buffer) + } + } + + enum class TitleActions { + SET_TITLE, + SET_SUBTITLE, + SET_ACTION_BAR, + SET_TIMES_AND_DISPLAY, + HIDE, + RESET, + ; + + companion object : ValuesEnum { + override val VALUES = values() + override val NAME_MAP = KUtil.getEnumValues(VALUES) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketTypes.kt b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketTypes.kt index f9da50964..d835a0f8f 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketTypes.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketTypes.kt @@ -21,7 +21,7 @@ import de.bixilon.minosoft.protocol.ErrorHandler import de.bixilon.minosoft.protocol.packets.ClientboundPacket import de.bixilon.minosoft.protocol.packets.clientbound.login.* import de.bixilon.minosoft.protocol.packets.clientbound.play.* -import de.bixilon.minosoft.protocol.packets.clientbound.play.title.PacketTitle +import de.bixilon.minosoft.protocol.packets.clientbound.play.title.TitlePacketFactory import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusPong import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusResponse @@ -198,7 +198,7 @@ class PacketTypes { PLAY_UPDATE_SIGN({ PacketUpdateSignReceiving(it) }), PLAY_STATISTICS({ PacketStatistics(it) }), PLAY_SPAWN_ENTITY({ PacketSpawnObject(it) }, false), - PLAY_TITLE({ PacketTitle(it) }), + PLAY_TITLE({ TitlePacketFactory.createPacket(it) }), PLAY_ENTITY_INITIALISATION({ PacketEntityInitialisation(it) }, false), PLAY_SET_COMPRESSION({ PacketSetCompression(it) }, false), PLAY_ADVANCEMENT_PROGRESS({ TODO() }),