Skip to content

Commit e4cf6b1

Browse files
authored
Merge pull request #196 from runejs/create-social-list-class
refactor: create SocialList class and use for friends/ignores
2 parents 82e7631 + 8d12304 commit e4cf6b1

File tree

11 files changed

+386
-183
lines changed

11 files changed

+386
-183
lines changed

src/main/java/org/runejs/client/Game.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.runejs.client.cache.CacheArchive;
55
import org.runejs.client.cache.CacheFileChannel;
66
import org.runejs.client.cache.cs.ClientScript;
7+
import org.runejs.client.chat.FriendList;
8+
import org.runejs.client.chat.SocialList;
79
import org.runejs.client.frame.*;
810
import org.runejs.client.frame.console.Console;
911
import org.runejs.client.input.KeyFocusListener;
@@ -73,6 +75,11 @@ public class Game {
7375
* A customisable cutscene camera.
7476
*/
7577
public static final CutsceneCamera cutsceneCamera = new CutsceneCamera();
78+
79+
public static FriendList friendList;
80+
81+
public static final SocialList ignoreList = new SocialList(100);
82+
7683
public static int anInt784 = 0;
7784
public static GameInterface chatboxInterface;
7885
public static GameSocket updateServerSocket;
@@ -672,7 +679,11 @@ public static void setConfigToDefaults() {
672679
}
673680
}
674681
MovedStatics.interactiveObjectTemporaryNodeCache = new LinkedList();
675-
Player.friendsCount = 0;
682+
683+
// friends list size depends on membership status
684+
int friendsListSize = MovedStatics.anInt1049 == 1 ? 200 : 100;
685+
Game.friendList = new FriendList(200, friendsListSize);
686+
676687
Player.friendListStatus = 0;
677688
GameInterface.resetInterface(ChatBox.dialogueId);
678689
ChatBox.dialogueId = -1;

src/main/java/org/runejs/client/MovedStatics.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,8 +2972,11 @@ else if(i < 101)
29722972
i--;
29732973
else
29742974
i -= 101;
2975-
addActionRow(English.remove, 0, 0, 0, ActionRowType.REMOVE_FRIEND.getId(), Native.white + Player.friendUsernames[i]);
2976-
addActionRow(English.message, 0, 0, 0, ActionRowType.MESSAGE_FRIEND.getId(), Native.white + Player.friendUsernames[i]);
2975+
2976+
String username = Game.friendList.getPlayerUsername(i);
2977+
2978+
addActionRow(English.remove, 0, 0, 0, ActionRowType.REMOVE_FRIEND.getId(), Native.white + username);
2979+
addActionRow(English.message, 0, 0, 0, ActionRowType.MESSAGE_FRIEND.getId(), Native.white + username);
29772980
return true;
29782981
}
29792982
if(i >= 401 && i <= 500) {

src/main/java/org/runejs/client/cache/media/gameInterface/GameInterface.java

Lines changed: 52 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public static void updateGameInterface(GameInterface gameInterface) {
335335
gameInterface.actionType = 0;
336336
gameInterface.disabledText = English.pleaseWait;
337337
} else {
338-
int fCount = Player.friendsCount;
338+
int fCount = Game.friendList.getCount();
339339
if(type > 700)
340340
type -= 601;
341341
else
@@ -346,7 +346,7 @@ public static void updateGameInterface(GameInterface gameInterface) {
346346
gameInterface.disabledText = "";
347347
gameInterface.actionType = 0;
348348
} else {
349-
gameInterface.disabledText = Player.friendUsernames[type];
349+
gameInterface.disabledText = Game.friendList.getPlayerUsername(type);
350350
gameInterface.actionType = 1;
351351
}
352352
}
@@ -355,30 +355,31 @@ public static void updateGameInterface(GameInterface gameInterface) {
355355
type -= 101;
356356
else
357357
type -= 701;
358-
int count = Player.friendsCount;
358+
int count = Game.friendList.getCount();
359359
if(Player.friendListStatus != 2)
360360
count = 0;
361361
if(type >= count) {
362362
gameInterface.disabledText = "";
363363
gameInterface.actionType = 0;
364364
} else {
365-
if(Player.friendWorlds[type] == 0) {
365+
int world = Game.friendList.getPlayerWorld(type);
366+
if(world == 0) {
366367
gameInterface.disabledText = Native.red + English.offline;
367-
} else if(Player.friendWorlds[type] < 5000) {
368-
if(Player.friendWorlds[type] == Player.worldId) {
369-
gameInterface.disabledText = Native.green + English.world + Player.friendWorlds[type];
368+
} else if(world < 5000) {
369+
if(world == Player.worldId) {
370+
gameInterface.disabledText = Native.green + English.world + world;
370371
} else {
371-
gameInterface.disabledText = Native.yellow + English.world + Player.friendWorlds[type];
372+
gameInterface.disabledText = Native.yellow + English.world + world;
372373
}
373-
} else if(Player.worldId == Player.friendWorlds[type]) {
374-
gameInterface.disabledText = Native.green + English.classic + (-5000 + Player.friendWorlds[type]);
374+
} else if(Player.worldId == world) {
375+
gameInterface.disabledText = Native.green + English.classic + (-5000 + world);
375376
} else {
376-
gameInterface.disabledText = Native.yellow + English.classic + (Player.friendWorlds[type] + -5000);
377+
gameInterface.disabledText = Native.yellow + English.classic + (world + -5000);
377378
}
378379
gameInterface.actionType = 1;
379380
}
380381
} else if(type == 203) {
381-
int count = Player.friendsCount;
382+
int count = Game.friendList.getCount();
382383
if(Player.friendListStatus != 2)
383384
count = 0;
384385
gameInterface.scrollHeight = 20 + 15 * count;
@@ -393,19 +394,19 @@ public static void updateGameInterface(GameInterface gameInterface) {
393394
gameInterface.disabledText = English.pleaseWait;
394395
gameInterface.actionType = 0;
395396
} else {
396-
int i_4_ = Player.ignoresCount;
397+
int i_4_ = Game.ignoreList.getCount();
397398
if(Player.friendListStatus == 0)
398399
i_4_ = 0;
399400
if(i_4_ <= type) {
400401
gameInterface.actionType = 0;
401402
gameInterface.disabledText = "";
402403
} else {
403-
gameInterface.disabledText = TextUtils.formatName(TextUtils.longToName(Player.ignores[type]));
404+
gameInterface.disabledText = TextUtils.formatName(TextUtils.longToName(Game.ignoreList.getPlayer(type)));
404405
gameInterface.actionType = 1;
405406
}
406407
}
407408
} else if(type == 503) {
408-
gameInterface.scrollHeight = 15 * Player.ignoresCount + 20;
409+
gameInterface.scrollHeight = 15 * Game.ignoreList.getCount() + 20;
409410
if(gameInterface.scrollHeight <= gameInterface.originalHeight)
410411
gameInterface.scrollHeight = gameInterface.originalHeight + 1;
411412
} else if(type == 324) {
@@ -949,21 +950,17 @@ public static void processMenuActions(int arg1) {
949950
int i_18_ = class1.indexOf(Native.white);
950951
if(i_18_ != -1) {
951952
long l = TextUtils.nameToLong(class1.substring(i_18_ + 5).trim());
952-
int i_19_ = -1;
953-
for(int i_20_ = 0; i_20_ < Player.friendsCount; i_20_++) {
954-
if(Player.friends[i_20_] == l) {
955-
i_19_ = i_20_;
956-
break;
957-
}
958-
}
959-
if(i_19_ != -1 && Player.friendWorlds[i_19_] > 0) {
953+
954+
int i_19_ = Game.friendList.getPlayerIndex(l);
955+
956+
if(i_19_ != -1 && Game.friendList.getPlayerWorld(i_19_) > 0) {
960957
anInt876 = 3;
961958
ChatBox.redrawChatbox = true;
962959
ChatBox.inputType = 0;
963960
ChatBox.chatMessage = "";
964961
ChatBox.messagePromptRaised = true;
965-
sendingMessageTo = Player.friends[i_19_];
966-
Native.enterPlayerNameHeader = English.prefixEnterMessageToSendTo + Player.friendUsernames[i_19_];
962+
sendingMessageTo = l;
963+
Native.enterPlayerNameHeader = English.prefixEnterMessageToSendTo + Game.friendList.getPlayerUsername(i_19_);
967964
}
968965
}
969966
}
@@ -1855,21 +1852,12 @@ public static void runClientScriptsForInterface(int minY, int arg1, int scrollWi
18551852

18561853
public static void removeFriend(long nameAsLong) {
18571854
if (nameAsLong != 0) {
1858-
int i = 0;
1859-
for (/**/; Player.friendsCount > i; i++) {
1860-
if (Player.friends[i] == nameAsLong) {
1861-
Player.friendsCount--;
1862-
redrawTabArea = true;
1863-
for (int i_13_ = i; i_13_ < Player.friendsCount; i_13_++) {
1864-
Player.friendUsernames[i_13_] = Player.friendUsernames[1 + i_13_];
1865-
Player.friendWorlds[i_13_] = Player.friendWorlds[i_13_ + 1];
1866-
Player.friends[i_13_] = Player.friends[1 + i_13_];
1867-
}
18681855

1869-
OutgoingPackets.sendMessage(
1870-
new ModifySocialListOutboundMessage(nameAsLong, ModifySocialListOutboundMessage.SocialList.FRIEND, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
1871-
break;
1872-
}
1856+
if (Game.friendList.removePlayer(nameAsLong) != -1) {
1857+
redrawTabArea = true;
1858+
1859+
OutgoingPackets.sendMessage(
1860+
new ModifySocialListOutboundMessage(nameAsLong, ModifySocialListOutboundMessage.SocialList.FRIEND, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
18731861
}
18741862
}
18751863
}
@@ -1917,7 +1905,7 @@ public static void manageTextInputs() {
19171905
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19181906
addFriend(l);
19191907
}
1920-
if(anInt876 == 2 && Player.friendsCount > 0) {
1908+
if(anInt876 == 2 && !Game.friendList.isEmpty()) {
19211909
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19221910
removeFriend(l);
19231911
}
@@ -1938,11 +1926,11 @@ public static void manageTextInputs() {
19381926
));
19391927
}
19401928
}
1941-
if(anInt876 == 4 && Player.ignoresCount < 100) {
1929+
if(anInt876 == 4 && !Game.ignoreList.isFull()) {
19421930
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19431931
addIgnore(l);
19441932
}
1945-
if(anInt876 == 5 && Player.ignoresCount > 0) {
1933+
if(anInt876 == 5 && !Game.ignoreList.isEmpty()) {
19461934
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19471935
removeIgnore(l);
19481936
}
@@ -2096,27 +2084,21 @@ public static void manageTextInputs() {
20962084

20972085
private static void addFriend(long name) {
20982086
if(name != 0L) {
2099-
if(Player.friendsCount >= 100 && MovedStatics.anInt1049 != 1 || Player.friendsCount >= 200) {
2087+
if(Game.friendList.isFull()) {
21002088
ChatBox.addChatMessage("", English.friendsListIsFull, 0);
21012089
} else {
21022090
String username = TextUtils.formatName(TextUtils.longToName(name));
2103-
for(int i = 0; Player.friendsCount > i; i++) {
2104-
if(Player.friends[i] == name) {
2105-
ChatBox.addChatMessage("", username + English.isAlreadyOnYourFriendList, 0);
2106-
return;
2107-
}
2091+
if(Game.friendList.containsPlayer(name)) {
2092+
ChatBox.addChatMessage("", username + English.isAlreadyOnYourFriendList, 0);
2093+
return;
21082094
}
2109-
for(int i = 0; Player.ignoresCount > i; i++) {
2110-
if(Player.ignores[i] == name) {
2111-
ChatBox.addChatMessage("", English.pleaseRemove + username + English.suffixFromYourIgnoreListFirst, 0);
2112-
return;
2113-
}
2095+
if (Game.ignoreList.containsPlayer(name)) {
2096+
ChatBox.addChatMessage("", English.pleaseRemove + username + English.suffixFromYourIgnoreListFirst, 0);
2097+
return;
21142098
}
21152099
if(!username.equals(Player.localPlayer.playerName)) {
2116-
Player.friendUsernames[Player.friendsCount] = username;
2117-
Player.friends[Player.friendsCount] = name;
2118-
Player.friendWorlds[Player.friendsCount] = 0;
2119-
Player.friendsCount++;
2100+
Game.friendList.addPlayer(name);
2101+
21202102
redrawTabArea = true;
21212103

21222104
OutgoingPackets.sendMessage(
@@ -2127,40 +2109,31 @@ private static void addFriend(long name) {
21272109
}
21282110

21292111
private static void removeIgnore(long arg1) {
2130-
for (int i = 0; i < Player.ignoresCount; i++) {
2131-
if (Player.ignores[i] == arg1) {
2132-
redrawTabArea = true;
2133-
Player.ignoresCount--;
2134-
for (int i_16_ = i; Player.ignoresCount > i_16_; i_16_++)
2135-
Player.ignores[i_16_] = Player.ignores[1 + i_16_];
2112+
if (Game.ignoreList.removePlayer(arg1) != -1) {
2113+
redrawTabArea = true;
21362114

2137-
OutgoingPackets.sendMessage(
2138-
new ModifySocialListOutboundMessage(arg1, ModifySocialListOutboundMessage.SocialList.IGNORE, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
2139-
break;
2140-
}
2115+
OutgoingPackets.sendMessage(
2116+
new ModifySocialListOutboundMessage(arg1, ModifySocialListOutboundMessage.SocialList.IGNORE, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
21412117
}
21422118
}
21432119

21442120
private static void addIgnore(long arg1) {
21452121
if(arg1 != 0L) {
2146-
if(Player.ignoresCount >= 100)
2122+
if(Game.ignoreList.isFull())
21472123
ChatBox.addChatMessage("", English.yourIgnoreListIsFull.toString(), 0);
21482124
else {
21492125
String class1 = TextUtils.formatName(TextUtils.longToName(arg1));
2150-
for(int i = 0; i < Player.ignoresCount; i++) {
2151-
if(arg1 == Player.ignores[i]) {
2152-
ChatBox.addChatMessage("", class1 + English.suffixIsAlreadyOnYourIgnoreList, 0);
2153-
return;
2154-
}
2126+
if (Game.ignoreList.containsPlayer(arg1)) {
2127+
ChatBox.addChatMessage("", class1 + English.suffixIsAlreadyOnYourIgnoreList, 0);
2128+
return;
21552129
}
2156-
for(int i = 0; Player.friendsCount > i; i++) {
2157-
if(Player.friends[i] == arg1) {
2158-
ChatBox.addChatMessage("", English.pleaseRemove + class1 + English.fromYourFriendListFirst, 0);
2159-
return;
2160-
}
2130+
if(Game.friendList.containsPlayer(arg1)) {
2131+
ChatBox.addChatMessage("", English.pleaseRemove + class1 + English.fromYourFriendListFirst, 0);
2132+
return;
21612133
}
21622134
if(!class1.equals(Player.localPlayer.playerName)) {
2163-
Player.ignores[Player.ignoresCount++] = arg1;
2135+
Game.ignoreList.addPlayer(arg1);
2136+
21642137
redrawTabArea = true;
21652138

21662139
OutgoingPackets.sendMessage(

0 commit comments

Comments
 (0)