PacketStopSound (with previous plugin channels)

This commit is contained in:
Bixilon 2020-07-18 22:11:16 +02:00
parent 01de49d88a
commit 6e8228b941
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 85 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public enum DefaultPluginChannels {
MC_BRAND(new ChangeableIdentifier("MC|Brand", "minecraft:brand")),
STOP_SOUND(new ChangeableIdentifier("MC|StopSound")),
REGISTER(new ChangeableIdentifier("REGISTER", "minecraft:register")),
UNREGISTER(new ChangeableIdentifier("UNREGISTER", "minecraft:unregister"));

View File

@ -22,6 +22,7 @@ import de.bixilon.minosoft.protocol.modding.channels.DefaultPluginChannels;
import de.bixilon.minosoft.protocol.modding.channels.PluginChannelHandler;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketStopSound;
import de.bixilon.minosoft.protocol.packets.serverbound.handshaking.PacketHandshake;
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketLoginStart;
import de.bixilon.minosoft.protocol.packets.serverbound.status.PacketStatusPing;
@ -215,6 +216,14 @@ public class Connection {
getPluginChannelHandler().sendRawData(DefaultPluginChannels.MC_BRAND.getChangeableIdentifier().get(version), toSend);
});
// MC|StopSound
getPluginChannelHandler().registerClientHandler(DefaultPluginChannels.STOP_SOUND.getChangeableIdentifier().get(version), (handler, buffer) -> {
// it is basically a packet, handle it like a packet:
PacketStopSound packet = new PacketStopSound();
packet.read(buffer);
handle(packet);
});
}
public boolean isConnected() {

View File

@ -0,0 +1,71 @@
/*
* Codename 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.protocol.packets.clientbound.play;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.util.BitByte;
public class PacketStopSound implements ClientboundPacket {
Integer soundId;
String soundIdentifier;
@Override
public boolean read(InByteBuffer buffer) {
switch (buffer.getVersion()) {
case VERSION_1_9_4:
case VERSION_1_10:
case VERSION_1_11_2:
buffer.readString(); // category
soundIdentifier = buffer.readString();
return true;
case VERSION_1_12_2:
soundIdentifier = buffer.readString();
buffer.readString(); // category
return true;
case VERSION_1_13_2:
byte flags = buffer.readByte();
if (BitByte.isBitMask(flags, 0x01)) {
soundId = buffer.readVarInt();
}
if (BitByte.isBitMask(flags, 0x02)) {
soundIdentifier = buffer.readString();
}
return true;
}
return false;
}
@Override
public void log() {
Log.protocol(String.format("Received stop sound (soundId=%d, soundIdentifier=%s)", soundId, soundIdentifier));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public Integer getSoundId() {
return soundId;
}
public String getSoundIdentifier() {
return soundIdentifier;
}
}

View File

@ -600,4 +600,7 @@ public class PacketHandler {
public void handle(PacketDeclareRecipes pkg) {
}
public void handle(PacketStopSound pkg) {
}
}

View File

@ -149,6 +149,7 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_FACE_PLAYER, PacketFacePlayer.class);
packetClassMapping.put(Packets.Clientbound.PLAY_TAGS, PacketTags.class);
packetClassMapping.put(Packets.Clientbound.PLAY_DECLARE_RECIPES, PacketDeclareRecipes.class);
packetClassMapping.put(Packets.Clientbound.PLAY_STOP_SOUND, PacketStopSound.class);
}
public static ProtocolVersion getLowestVersionSupported() {