Skip to content

Commit

Permalink
Add method to hide hud elements (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Jun 19, 2024
1 parent 118f6c1 commit a82f451
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5523,4 +5523,16 @@ public void onCompletion(Server server) {
this.server.getScheduler().scheduleAsyncTask(this.preLoginEventTask);
this.processLogin();
}

/**
* Show or hide hud elements for the player
* @param visible whether the listed elements will be visible
* @param elements elements
*/
public void setHudElementVisibility(boolean visible, HudElement... elements) {
SetHudPacket pk = new SetHudPacket();
pk.elements.addAll(Arrays.asList(elements));
pk.visible = visible;
this.dataPacket(pk);
}
}
11 changes: 10 additions & 1 deletion src/main/java/cn/nukkit/network/protocol/ProtocolInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,14 @@ public interface ProtocolInfo {
// MC packet IDs continue from 300 (0x12c)
// Hack: 100 is added to the IDs below on encode
// TODO: New pid() function (int) while trying not to break too many plugins
byte __INTERNAL__OPEN_SIGN_PACKET = (byte) 203; // 303
byte __INTERNAL__CAMERA_INSTRUCTION_PACKET = (byte) 200;
byte __INTERNAL__COMPRESSED_BIOME_DEFINITIONS_LIST_PACKET = (byte) 201;
byte __INTERNAL__TRIM_DATA_PACKET = (byte) 202;
byte __INTERNAL__OPEN_SIGN_PACKET = (byte) 203;
byte __INTERNAL__AGENT_ANIMATION_PACKET = (byte) 204;
byte __INTERNAL__REFRESH_ENTITLEMENTS_PACKET = (byte) 205;
byte __INTERNAL__TOGGLE_CRAFTER_SLOT_REQUEST_PACKET = (byte) 206;
byte __INTERNAL__SET_PLAYER_INVENTORY_OPTIONS_PACKET = (byte) 207;
byte __INTERNAL__SET_HUD_PACKET = (byte) 208;
byte __INTERNAL__AWARD_ACHIEVEMENT_PACKET = (byte) 209;
}
35 changes: 35 additions & 0 deletions src/main/java/cn/nukkit/network/protocol/SetHudPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cn.nukkit.network.protocol;

import cn.nukkit.network.protocol.types.HudElement;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.ToString;

import java.util.List;

@ToString
public class SetHudPacket extends DataPacket {

public static final byte NETWORK_ID = ProtocolInfo.__INTERNAL__SET_HUD_PACKET;

public final List<HudElement> elements = new ObjectArrayList<>();
public boolean visible;

@Override
public byte pid() {
return NETWORK_ID;
}

@Override
public void decode() {
}

@Override
public void encode() {
this.reset();
this.putUnsignedVarInt(this.elements.size());
for (HudElement element : this.elements) {
this.putUnsignedVarInt(element.ordinal());
}
this.putBoolean(this.visible);
}
}
24 changes: 24 additions & 0 deletions src/main/java/cn/nukkit/network/protocol/types/HudElement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.nukkit.network.protocol.types;

public enum HudElement {

PAPER_DOLL,
ARMOR,
TOOL_TIPS,
TOUCH_CONTROLS,
CROSSHAIR,
HOTBAR,
HEALTH,
PROGRESS_BAR,
FOOD_BAR,
AIR_BUBBLES_BAR,
VEHICLE_HEALTH,
/**
* @since v671
*/
EFFECTS_BAR,
/**
* @since v671
*/
ITEM_TEXT_POPUP
}
1 change: 0 additions & 1 deletion src/main/java/cn/nukkit/scoreboard/Scoreboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cn.nukkit.network.protocol.RemoveObjectivePacket;
import cn.nukkit.network.protocol.SetDisplayObjectivePacket;
import cn.nukkit.network.protocol.SetScorePacket;
import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down

0 comments on commit a82f451

Please sign in to comment.