Java Code Examples for com.nukkitx.protocol.bedrock.packet.SetTitlePacket#setFadeOutTime()

The following examples show how to use com.nukkitx.protocol.bedrock.packet.SetTitlePacket#setFadeOutTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CooldownUtils.java    From Geyser with MIT License 6 votes vote down vote up
/**
 * Keeps updating the cooldown until the bar is complete.
 * @param session GeyserSession
 * @param lastHitTime The time of the last hit. Used to gauge how long the cooldown is taking.
 */
private static void computeCooldown(GeyserSession session, long lastHitTime) {
    if (session.isClosed()) return; // Don't run scheduled tasks if the client left
    if (lastHitTime != session.getLastHitTime()) return; // Means another cooldown has started so there's no need to continue this one
    SetTitlePacket titlePacket = new SetTitlePacket();
    titlePacket.setType(SetTitlePacket.Type.SET_SUBTITLE);
    titlePacket.setText(getTitle(session));
    titlePacket.setFadeInTime(0);
    titlePacket.setFadeOutTime(5);
    titlePacket.setStayTime(2);
    session.sendUpstreamPacket(titlePacket);
    if (hasCooldown(session)) {
        session.getConnector().getGeneralThreadPool().schedule(() -> computeCooldown(session, lastHitTime), 50, TimeUnit.MILLISECONDS); // Updated per tick. 1000 divided by 20 ticks equals 50
    } else {
        SetTitlePacket removeTitlePacket = new SetTitlePacket();
        removeTitlePacket.setType(SetTitlePacket.Type.SET_SUBTITLE);
        removeTitlePacket.setText(" ");
        session.sendUpstreamPacket(removeTitlePacket);
    }
}
 
Example 2
Source File: JavaTitleTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerTitlePacket packet, GeyserSession session) {
    SetTitlePacket titlePacket = new SetTitlePacket();

    switch (packet.getAction()) {
        case TITLE:
            titlePacket.setType(SetTitlePacket.Type.SET_TITLE);
            titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle()));
            break;
        case SUBTITLE:
            titlePacket.setType(SetTitlePacket.Type.SET_SUBTITLE);
            titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle()));
            break;
        case CLEAR:
        case RESET:
            titlePacket.setType(SetTitlePacket.Type.RESET_TITLE);
            titlePacket.setText("");
            break;
        case ACTION_BAR:
            titlePacket.setType(SetTitlePacket.Type.SET_ACTIONBAR_MESSAGE);
            titlePacket.setText(MessageUtils.getBedrockMessage(packet.getTitle()));
            break;
        case TIMES:
            titlePacket.setFadeInTime(packet.getFadeIn());
            titlePacket.setFadeOutTime(packet.getFadeOut());
            titlePacket.setStayTime(packet.getStay());
            break;
    }

    session.sendUpstreamPacket(titlePacket);
}
 
Example 3
Source File: SetTitleSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 4
Source File: SetTitleSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 5
Source File: SetTitleSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 6
Source File: SetTitleSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 7
Source File: SetTitleSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 8
Source File: SetTitleSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}
 
Example 9
Source File: SetTitleSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetTitlePacket packet) {
    packet.setType(SetTitlePacket.Type.values()[VarInts.readInt(buffer)]);
    packet.setText(BedrockUtils.readString(buffer));
    packet.setFadeInTime(VarInts.readInt(buffer));
    packet.setStayTime(VarInts.readInt(buffer));
    packet.setFadeOutTime(VarInts.readInt(buffer));
}