/
ActionSender.java
93 lines (82 loc) · 2.46 KB
/
ActionSender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package info.jupiter.net;
import info.Constants;
import info.jupiter.Player;
import info.jupiter.net.Packet.Type;
/**
* Utility class that deals with building packets to send packets from the server -> client.
* @author Advocatus <davidcntt@hotmail.com>
*
*/
public class ActionSender {
/**
* The player to instance this class for.
*/
private Player player;
/**
* Sets the player object for this instance
* @param player the player to set.
*/
public ActionSender(Player player) {
this.player = player;
}
/**
* Sends login from the server to the client.
* @return the instance for chaining.
*/
public ActionSender sendLogin() {
sendDetails();
sendMessage("Welcome to RuneScape.");
sendMapRegion();
sendSidebarInterfaces();
return this;
}
/**
* Sends all the sidebar interfaces.
* @return The action sender instance, for chaining.
*/
public ActionSender sendSidebarInterfaces() {
final int[] icons = Constants.SIDEBAR_INTERFACES[0];
final int[] interfaces = Constants.SIDEBAR_INTERFACES[1];
for(int i = 0; i < icons.length; i++) {
sendSidebarInterface(icons[i], interfaces[i]);
}
return this;
}
/**
* Sends a specific sidebar interface.
* @param icon The sidebar icon.
* @param interfaceId The interface id.
* @return The action sender instance, for chaining.
*/
public ActionSender sendSidebarInterface(int icon, int interfaceId) {
player.write(new PacketBuilder(71).putShort(interfaceId).putByteA(icon).toPacket());
return this;
}
/**
* Sends a message.
* @param message The message to send.
* @return The action sender instance, for chaining.
*/
public ActionSender sendMessage(String message) {
player.write(new PacketBuilder(253, Type.VARIABLE).putRS2String(message).toPacket());
return this;
}
/**
* Sends the map region load command.
* @return The action sender instance, for chaining.
*/
public ActionSender sendMapRegion() {
player.setLastKnownRegion(player.getLocation());
player.write(new PacketBuilder(73).putShortA(player.getLocation().getRegionX() + 6).putShort(player.getLocation().getRegionY() + 6).toPacket());
return this;
}
/**
* Sends the initial login packet (e.g. members, player id).
* @return The action sender instance, for chaining.
*/
public ActionSender sendDetails() {
player.write(new PacketBuilder(249).putByteA(player.isMembers() ? 1 : 0).putLEShortA(player.getIndex()).toPacket());
player.write(new PacketBuilder(107).toPacket());
return this;
}
}