PacketCombatEvent

This commit is contained in:
Bixilon 2020-06-26 22:36:16 +02:00
parent 0bfe2f6f9c
commit aaf6841b30
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 129 additions and 4 deletions

View File

@ -0,0 +1,97 @@
/*
* 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.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketCombatEvent implements ClientboundPacket {
CombatEvent action;
int duration;
int playerId;
int entityId;
String message;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_8:
action = CombatEvent.byId(buffer.readVarInt());
switch (action) {
case END_COMBAT:
duration = buffer.readVarInt();
entityId = buffer.readVarInt();
break;
case ENTITY_DEAD:
playerId = buffer.readVarInt();
entityId = buffer.readVarInt();
message = buffer.readString();
break;
}
break;
}
}
@Override
public void log() {
switch (action) {
case ENTER_COMBAT:
Log.protocol(String.format("Received combat packet (action=%s)", action.name()));
break;
case END_COMBAT:
Log.protocol(String.format("Received combat packet (action=%s, duration=%d, entityId=%d)", action.name(), duration, entityId));
break;
case ENTITY_DEAD:
Log.protocol(String.format("Received combat packet (action=%s, playerId=%d, entityId=%d, message=\"%s\")", action.name(), playerId, entityId, message));
break;
}
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public enum CombatEvent {
ENTER_COMBAT(0),
END_COMBAT(1),
ENTITY_DEAD(2);
final int id;
CombatEvent(int id) {
this.id = id;
}
public static CombatEvent byId(int id) {
for (CombatEvent a : values()) {
if (a.getId() == id) {
return a;
}
}
return null;
}
public int getId() {
return id;
}
}
}

View File

@ -57,17 +57,17 @@ public class PacketTitle implements ClientboundPacket {
public void log() {
switch (action) {
case SET_TITLE:
Log.protocol(String.format("Received title (action=%s, text=%s)", action, text.getColoredMessage()));
Log.protocol(String.format("Received title (action=%s, text=%s)", action.name(), text.getColoredMessage()));
break;
case SET_SUBTITLE:
Log.protocol(String.format("Received title (action=%s, subText=%s)", action, subText.getColoredMessage()));
Log.protocol(String.format("Received title (action=%s, subText=%s)", action.name(), subText.getColoredMessage()));
break;
case SET_TIMES_AND_DISPLAY:
Log.protocol(String.format("Received title (action=%s, fadeInTime=%d, stayTime=%d, fadeOutTime=%d)", action, fadeInTime, stayTime, fadeOutTime));
Log.protocol(String.format("Received title (action=%s, fadeInTime=%d, stayTime=%d, fadeOutTime=%d)", action.name(), fadeInTime, stayTime, fadeOutTime));
break;
case HIDE:
case RESET:
Log.protocol(String.format("Received title (action=%s)", action));
Log.protocol(String.format("Received title (action=%s)", action.name()));
break;
}
}
@ -77,6 +77,29 @@ public class PacketTitle implements ClientboundPacket {
h.handle(this);
}
public int getFadeInTime() {
return fadeInTime;
}
public int getFadeOutTime() {
return fadeOutTime;
}
public int getStayTime() {
return stayTime;
}
public TextComponent getSubText() {
return subText;
}
public TextComponent getText() {
return text;
}
public TitleAction getAction() {
return action;
}
public enum TitleAction {
SET_TITLE(0),

View File

@ -511,4 +511,8 @@ public class PacketHandler {
public void handle(PacketTitle pkg) {
//ToDo
}
public void handle(PacketCombatEvent pkg) {
//ToDo
}
}

View File

@ -119,6 +119,7 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_PROPERTIES, PacketEntityProperties.class);
packetClassMapping.put(Packets.Clientbound.PLAY_WORLD_BORDER, PacketWorldBorder.class);
packetClassMapping.put(Packets.Clientbound.PLAY_TITLE, PacketTitle.class);
packetClassMapping.put(Packets.Clientbound.PLAY_COMBAT_EVENT, PacketCombatEvent.class);
}
public static ProtocolVersion getLowestVersionSupported() {