Boss bar
This commit is contained in:
@@ -82,6 +82,7 @@ public enum State {
|
|||||||
.put(0x1D, AnimationPacket.class)
|
.put(0x1D, AnimationPacket.class)
|
||||||
.build(),
|
.build(),
|
||||||
ImmutableMap.<Class<? extends SCPacket>, Integer>builder()
|
ImmutableMap.<Class<? extends SCPacket>, Integer>builder()
|
||||||
|
.put(BossBarPacket.class, 0x0C)
|
||||||
.put(ChatMessageServerPacket.class, 0x0F)
|
.put(ChatMessageServerPacket.class, 0x0F)
|
||||||
.put(PluginMessagePacket.class, 0x18)
|
.put(PluginMessagePacket.class, 0x18)
|
||||||
.put(KeepAlivePacket.class, 0x1F)
|
.put(KeepAlivePacket.class, 0x1F)
|
||||||
|
|||||||
@@ -4,5 +4,88 @@
|
|||||||
*/
|
*/
|
||||||
package mc.core.network.proto_1_12_2.packets;
|
package mc.core.network.proto_1_12_2.packets;
|
||||||
|
|
||||||
public class BossBarPacket {
|
import lombok.Data;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import mc.core.network.NetStream;
|
||||||
|
import mc.core.network.SCPacket;
|
||||||
|
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
||||||
|
import mc.core.text.Text;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class BossBarPacket implements SCPacket {
|
||||||
|
public static final int ACTION_ADD = 0,
|
||||||
|
ACTION_REMOVE = 1,
|
||||||
|
ACTION_UPDATE_HEALTH = 2,
|
||||||
|
ACTION_UPDATE_TITLE = 3,
|
||||||
|
ACTION_UPDATE_STYLE = 4,
|
||||||
|
ACTION_UPDATE_FLAGS = 5;
|
||||||
|
|
||||||
|
public static final int COLOR_PINK = 0,
|
||||||
|
COLOR_BLUE = 1,
|
||||||
|
COLOR_RED = 2,
|
||||||
|
COLOR_GREEN = 3,
|
||||||
|
COLOR_YELLOW = 4,
|
||||||
|
COLOR_PURPLE = 5,
|
||||||
|
COLOR_WHITE = 6;
|
||||||
|
|
||||||
|
public static final int DIVISION_NO = 0,
|
||||||
|
DIVISION_0 = DIVISION_NO,
|
||||||
|
DIVISION_6 = 1,
|
||||||
|
DIVISION_10 = 2,
|
||||||
|
DIVISION_12 = 3,
|
||||||
|
DIVISION_20 = 4;
|
||||||
|
|
||||||
|
public static final byte FLAG_NO = 0x00,
|
||||||
|
FLAG_DAKR_SKY = 0x01,
|
||||||
|
FLAG_DRAGON_BAR = 0x02;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BarData {
|
||||||
|
private Text title;
|
||||||
|
/*
|
||||||
|
* From 0 to 1.
|
||||||
|
* Values greater than 1 do not crash a Notchian client,
|
||||||
|
* and start rendering part of a second health bar at around 1.5.
|
||||||
|
* (https://i.johni0702.de/nA.png)
|
||||||
|
*/
|
||||||
|
private float health;
|
||||||
|
private int color;
|
||||||
|
private int division;
|
||||||
|
private byte flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID uuid; // Unique ID for this bar
|
||||||
|
private int action;
|
||||||
|
private BarData barData;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelf(NetStream netStream) {
|
||||||
|
netStream.writeUUID(uuid);
|
||||||
|
netStream.writeVarInt(action);
|
||||||
|
|
||||||
|
if (action == ACTION_REMOVE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == ACTION_ADD || action == ACTION_UPDATE_TITLE) {
|
||||||
|
netStream.writeString(TextSerializer.serialize(barData.title).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == ACTION_ADD || action == ACTION_UPDATE_HEALTH) {
|
||||||
|
netStream.writeFloat(barData.health);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == ACTION_ADD || action == ACTION_UPDATE_STYLE) {
|
||||||
|
netStream.writeVarInt(barData.color);
|
||||||
|
netStream.writeVarInt(barData.division);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == ACTION_ADD || action == ACTION_UPDATE_FLAGS) {
|
||||||
|
netStream.writeUnsignedByte(barData.flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER;
|
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_PLAYER;
|
||||||
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE;
|
import static mc.core.network.proto_1_12_2.netty.NettyServer.ATTR_STATE;
|
||||||
@@ -105,13 +106,26 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
|||||||
pkt5.getListPlayers().add(playerData);
|
pkt5.getListPlayers().add(playerData);
|
||||||
channel.writeAndFlush(pkt5);
|
channel.writeAndFlush(pkt5);
|
||||||
|
|
||||||
// Send header/footer БЕфиЮ list
|
// Send header/footer <Tab> list
|
||||||
PlayerListHeaderAndFooterPacket pkt6 = new PlayerListHeaderAndFooterPacket();
|
PlayerListHeaderAndFooterPacket pkt6 = new PlayerListHeaderAndFooterPacket();
|
||||||
Text text = Text.of(TextColor.GOLD, "=============================");
|
Text text = Text.of(TextColor.GOLD, "=============================");
|
||||||
pkt6.setHeader(text);
|
pkt6.setHeader(text);
|
||||||
pkt6.setFooter(text);
|
pkt6.setFooter(text);
|
||||||
channel.writeAndFlush(pkt6);
|
channel.writeAndFlush(pkt6);
|
||||||
|
|
||||||
|
// Send Boss bar
|
||||||
|
BossBarPacket pkt7 = new BossBarPacket();
|
||||||
|
BossBarPacket.BarData barData = new BossBarPacket.BarData();
|
||||||
|
barData.setTitle(Text.of(TextColor.GREEN, TextStyle.BOLD, "FORWOLK"));
|
||||||
|
barData.setColor(BossBarPacket.COLOR_WHITE);
|
||||||
|
barData.setDivision(BossBarPacket.DIVISION_12);
|
||||||
|
barData.setHealth(1.0f);
|
||||||
|
barData.setFlags(BossBarPacket.FLAG_NO);
|
||||||
|
pkt7.setUuid(UUID.randomUUID());
|
||||||
|
pkt7.setAction(BossBarPacket.ACTION_ADD);
|
||||||
|
pkt7.setBarData(barData);
|
||||||
|
channel.writeAndFlush(pkt7);
|
||||||
|
|
||||||
playerManager.joinServer(player);
|
playerManager.joinServer(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user