RuneHive-Game
Loading...
Searching...
No Matches
SendPlayerOption.java
Go to the documentation of this file.
1package com.runehive.net.packet.out;
2
3import com.runehive.net.packet.OutgoingPacket;
4import com.runehive.net.packet.PacketType;
5import com.runehive.net.codec.ByteModification;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.entity.mob.player.PlayerOption;
8
9/**
10 * Shows a player options such as right clicking a player.
11
12 * @author Daniel
13 */
14public final class SendPlayerOption extends OutgoingPacket {
15
17 private boolean top;
18 private boolean disable;
19
21 this(option, top, false);
22 }
23
24 public SendPlayerOption(PlayerOption option, boolean top, boolean disable) {
25 super(104, PacketType.VAR_BYTE);
26 this.option = option;
27 this.top = top;
28 this.disable = disable;
29 }
30
31 @Override
32 public boolean encode(Player player) {
33 if (player.contextMenus.contains(option) && !disable) {
34 return false;
35 }
36
37 builder.writeByte(option.getIndex(), ByteModification.NEG)
38 .writeByte(top ? 1 : 0, ByteModification.ADD)
39 .writeString(disable ? "null" : option.getName());
40
41 if (disable) {
42 player.contextMenus.remove(option);
43 } else {
44 player.contextMenus.add(option);
45 }
46 return true;
47 }
48
49}
This class represents a character controlled by a player.
Definition Player.java:125
OutgoingPacket(int opcode, int capacity)
SendPlayerOption(PlayerOption option, boolean top)
SendPlayerOption(PlayerOption option, boolean top, boolean disable)
Represents the options for right-clicking players.
Represents RuneScape's custom value types.
ADD
Adds 128 to the value when written, subtracts 128 from the rarity when read.
Represents a type of packet.
VAR_BYTE
A variable packet where the size is indicated by a byte.