Skip to content

Commit 25cd580

Browse files
committed
refactor: create SocialList class and use for ignores
1 parent a856ba8 commit 25cd580

File tree

7 files changed

+161
-69
lines changed

7 files changed

+161
-69
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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.SocialList;
78
import org.runejs.client.frame.*;
89
import org.runejs.client.frame.console.Console;
910
import org.runejs.client.input.KeyFocusListener;
@@ -73,6 +74,9 @@ public class Game {
7374
* A customisable cutscene camera.
7475
*/
7576
public static final CutsceneCamera cutsceneCamera = new CutsceneCamera();
77+
78+
public static final SocialList ignoreList = new SocialList(100);
79+
7680
public static int anInt784 = 0;
7781
public static GameInterface chatboxInterface;
7882
public static GameSocket updateServerSocket;

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -393,19 +393,19 @@ public static void updateGameInterface(GameInterface gameInterface) {
393393
gameInterface.disabledText = English.pleaseWait;
394394
gameInterface.actionType = 0;
395395
} else {
396-
int i_4_ = Player.ignoresCount;
396+
int i_4_ = Game.ignoreList.getCount();
397397
if(Player.friendListStatus == 0)
398398
i_4_ = 0;
399399
if(i_4_ <= type) {
400400
gameInterface.actionType = 0;
401401
gameInterface.disabledText = "";
402402
} else {
403-
gameInterface.disabledText = TextUtils.formatName(TextUtils.longToName(Player.ignores[type]));
403+
gameInterface.disabledText = TextUtils.formatName(TextUtils.longToName(Game.ignoreList.getPlayer(type)));
404404
gameInterface.actionType = 1;
405405
}
406406
}
407407
} else if(type == 503) {
408-
gameInterface.scrollHeight = 15 * Player.ignoresCount + 20;
408+
gameInterface.scrollHeight = 15 * Game.ignoreList.getCount() + 20;
409409
if(gameInterface.scrollHeight <= gameInterface.originalHeight)
410410
gameInterface.scrollHeight = gameInterface.originalHeight + 1;
411411
} else if(type == 324) {
@@ -1938,11 +1938,11 @@ public static void manageTextInputs() {
19381938
));
19391939
}
19401940
}
1941-
if(anInt876 == 4 && Player.ignoresCount < 100) {
1941+
if(anInt876 == 4 && !Game.ignoreList.isFull()) {
19421942
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19431943
addIgnore(l);
19441944
}
1945-
if(anInt876 == 5 && Player.ignoresCount > 0) {
1945+
if(anInt876 == 5 && !Game.ignoreList.isEmpty()) {
19461946
long l = MovedStatics.nameToLong(ChatBox.chatMessage);
19471947
removeIgnore(l);
19481948
}
@@ -2106,11 +2106,9 @@ private static void addFriend(long name) {
21062106
return;
21072107
}
21082108
}
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-
}
2109+
if (Game.ignoreList.containsPlayer(name)) {
2110+
ChatBox.addChatMessage("", English.pleaseRemove + username + English.suffixFromYourIgnoreListFirst, 0);
2111+
return;
21142112
}
21152113
if(!username.equals(Player.localPlayer.playerName)) {
21162114
Player.friendUsernames[Player.friendsCount] = username;
@@ -2127,31 +2125,23 @@ private static void addFriend(long name) {
21272125
}
21282126

21292127
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_];
2128+
if (Game.ignoreList.removePlayer(arg1) != -1) {
2129+
redrawTabArea = true;
21362130

2137-
OutgoingPackets.sendMessage(
2138-
new ModifySocialListOutboundMessage(arg1, ModifySocialListOutboundMessage.SocialList.IGNORE, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
2139-
break;
2140-
}
2131+
OutgoingPackets.sendMessage(
2132+
new ModifySocialListOutboundMessage(arg1, ModifySocialListOutboundMessage.SocialList.IGNORE, ModifySocialListOutboundMessage.SocialListAction.REMOVE));
21412133
}
21422134
}
21432135

21442136
private static void addIgnore(long arg1) {
21452137
if(arg1 != 0L) {
2146-
if(Player.ignoresCount >= 100)
2138+
if(Game.ignoreList.isFull())
21472139
ChatBox.addChatMessage("", English.yourIgnoreListIsFull.toString(), 0);
21482140
else {
21492141
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-
}
2142+
if (Game.ignoreList.containsPlayer(arg1)) {
2143+
ChatBox.addChatMessage("", class1 + English.suffixIsAlreadyOnYourIgnoreList, 0);
2144+
return;
21552145
}
21562146
for(int i = 0; Player.friendsCount > i; i++) {
21572147
if(Player.friends[i] == arg1) {
@@ -2160,7 +2150,8 @@ private static void addIgnore(long arg1) {
21602150
}
21612151
}
21622152
if(!class1.equals(Player.localPlayer.playerName)) {
2163-
Player.ignores[Player.ignoresCount++] = arg1;
2153+
Game.ignoreList.addPlayer(arg1);
2154+
21642155
redrawTabArea = true;
21652156

21662157
OutgoingPackets.sendMessage(
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package org.runejs.client.chat;
2+
3+
/**
4+
* A list of players in a social list.
5+
*/
6+
public class SocialList {
7+
/**
8+
* The players in this list.
9+
*/
10+
private long[] players;
11+
12+
/**
13+
* The amount of players currently in this list.
14+
*/
15+
private int count = 0;
16+
17+
/**
18+
* Creates a new social list with the specified size.
19+
*
20+
* @param size The size of the list.
21+
*/
22+
public SocialList(int size) {
23+
this.players = new long[size];
24+
}
25+
26+
/**
27+
* Gets the size of this list.
28+
* @return The size of this list.
29+
*/
30+
public int getSize() {
31+
return this.players.length;
32+
}
33+
34+
/**
35+
* Checks if this list is full.
36+
* @return {@code true} if this list is full, otherwise {@code false}.
37+
*/
38+
public boolean isFull() {
39+
return this.count >= this.players.length;
40+
}
41+
42+
/**
43+
* Checks if this list is empty.
44+
* @return {@code true} if this list is empty, otherwise {@code false}.
45+
*/
46+
public boolean isEmpty() {
47+
return this.count > 0;
48+
}
49+
50+
/**
51+
* Gets the amount of players currently in this list.
52+
* @return The amount of players currently in this list.
53+
*/
54+
public int getCount() {
55+
return this.count;
56+
}
57+
58+
/**
59+
* Checks if this list contains the specified player.
60+
* @param p The player to check for.
61+
* @return {@code true} if this list contains the specified player, otherwise {@code false}.
62+
*/
63+
public boolean containsPlayer(long p) {
64+
return this.getPlayerIndex(p) != -1;
65+
}
66+
67+
/**
68+
* Removes the specified player from this list.
69+
* @param p The player to remove.
70+
* @return The original index of the player that was removed, or {@code -1} if the player was not in this list.
71+
*/
72+
public int removePlayer(long p) {
73+
int index = this.getPlayerIndex(p);
74+
if (index == -1) {
75+
return -1;
76+
}
77+
78+
this.count--;
79+
80+
for (int i = index; i < this.count; i++) {
81+
this.players[i] = this.players[i + 1];
82+
}
83+
84+
return index;
85+
}
86+
87+
/**
88+
* Gets the index of the specified player.
89+
* @param p The player to get the index of.
90+
* @return The index of the specified player, or {@code -1} if the player was not in this list.
91+
*/
92+
private int getPlayerIndex(long p) {
93+
for (int i = 0; i < this.count; i++) {
94+
if (this.players[i] == p) {
95+
return i;
96+
}
97+
}
98+
99+
return -1;
100+
}
101+
102+
/**
103+
* Gets the player at the specified index.
104+
* @param index The index of the player to get.
105+
* @return The player at the specified index.
106+
*/
107+
public long getPlayer(int index) {
108+
return this.players[index];
109+
}
110+
111+
/**
112+
* Adds the specified player to this list.
113+
* @param p The player to add.
114+
*/
115+
public void addPlayer(long p) {
116+
this.players[this.count++] = p;
117+
}
118+
119+
/**
120+
* Sets the players in this list.
121+
* @param p The players to set.
122+
*/
123+
public void setPlayers(long[] p) {
124+
this.count = p.length;
125+
126+
for(int i = 0; i < p.length; i++)
127+
this.players[i] = p[i];
128+
}
129+
}

src/main/java/org/runejs/client/media/renderable/actor/Player.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public class Player extends Actor {
3535
public static int[] nextLevels = new int[25];
3636
public static int[] experienceForLevels = new int[99];
3737
public static long[] privateMessageIds = new long[100];
38-
public static long[] ignores = new long[100];
3938
public static int privateMessageIndex = 0;
4039
public static int[] friendWorlds = new int[200];
4140
public static int friendListStatus = 0;
@@ -44,7 +43,6 @@ public class Player extends Actor {
4443
public static PlayerAppearance activePlayerAppearance = new PlayerAppearance();
4544
public static String[] friendUsernames = new String[200];
4645
public static long[] friends = new long[200];
47-
public static int ignoresCount = 0;
4846
public static int localPlayerId = -1;
4947
public static String[] playerActions = new String[5];
5048
public static boolean[] playerActionsLowPriority = new boolean[5];
@@ -141,15 +139,7 @@ public static void parsePlayerUpdateMasks(PacketBuffer appearanceBuffer, Player
141139
int bufferPosition = appearanceBuffer.currentPosition;
142140
if(player.playerName != null && player.playerAppearance != null) {
143141
long l = MovedStatics.nameToLong(player.playerName);
144-
boolean bool = false;
145-
if(playerRights <= 1) {
146-
for(int i = 0; i < ignoresCount; i++) {
147-
if(l == ignores[i]) {
148-
bool = true;
149-
break;
150-
}
151-
}
152-
}
142+
boolean bool = (playerRights <= 1) && Game.ignoreList.containsPlayer(l);
153143
if(!bool && !inTutorialIsland) {
154144
chatBuffer.currentPosition = 0;
155145
appearanceBuffer.getBytes(0, messageLength, chatBuffer.buffer);

src/main/java/org/runejs/client/message/handler/rs435/chat/ReceiveChatboxMessageHandler.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.runejs.client.message.handler.rs435.chat;
22

3+
import org.runejs.client.Game;
34
import org.runejs.client.MovedStatics;
45
import org.runejs.client.frame.ChatBox;
56
import org.runejs.client.language.English;
@@ -21,37 +22,19 @@ public void handle(ReceiveChatboxMessageInboundMessage message) {
2122
if(chatMessage.endsWith(Native.tradeRequest)) {
2223
String username = chatMessage.substring(0, chatMessage.indexOf(Native.colon));
2324
long l = MovedStatics.nameToLong(username);
24-
boolean bool = false;
25-
for(int i = 0; i < Player.ignoresCount; i++) {
26-
if(l == Player.ignores[i]) {
27-
bool = true;
28-
break;
29-
}
30-
}
25+
boolean bool = Game.ignoreList.containsPlayer(l);
3126
if(!bool && !Player.inTutorialIsland)
3227
ChatBox.addChatMessage(username, "wishes to trade with you.", 4);
3328
} else if(chatMessage.endsWith(Native.duelRequest)) {
3429
String username = chatMessage.substring(0, chatMessage.indexOf(Native.colon));
3530
long l = MovedStatics.nameToLong(username);
36-
boolean bool = false;
37-
for(int i = 0; Player.ignoresCount > i; i++) {
38-
if(l == Player.ignores[i]) {
39-
bool = true;
40-
break;
41-
}
42-
}
31+
boolean bool = Game.ignoreList.containsPlayer(l);
4332
if(!bool && !Player.inTutorialIsland)
4433
ChatBox.addChatMessage(username, English.suffixWishesToDuelWithYou, 8);
4534
} else if(chatMessage.endsWith(Native.challengeRequest)) {
4635
String username = chatMessage.substring(0, chatMessage.indexOf(Native.colon));
4736
long l = MovedStatics.nameToLong(username);
48-
boolean bool = false;
49-
for(int i = 0; i < Player.ignoresCount; i++) {
50-
if(l == Player.ignores[i]) {
51-
bool = true;
52-
break;
53-
}
54-
}
37+
boolean bool = Game.ignoreList.containsPlayer(l);
5538
if(!bool && !Player.inTutorialIsland) {
5639
String challengeMessage = chatMessage.substring(1 + chatMessage.indexOf(Native.colon), -9 + chatMessage.length());
5740
ChatBox.addChatMessage(username, challengeMessage, 8);

src/main/java/org/runejs/client/message/handler/rs435/chat/ReceivePrivateMessageHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.runejs.client.message.handler.rs435.chat;
22

3+
import org.runejs.client.Game;
34
import org.runejs.client.frame.ChatBox;
45
import org.runejs.client.language.Native;
56
import org.runejs.client.media.renderable.actor.Player;
@@ -24,11 +25,8 @@ public void handle(ReceivePrivateMessageInboundMessage message) {
2425
}
2526
}
2627
if (message.fromPlayerRights <= 1) {
27-
for (int ignoreIndex = 0; ignoreIndex < Player.ignoresCount; ignoreIndex++) {
28-
if (message.fromPlayerIndex == Player.ignores[ignoreIndex]) {
29-
hideMessage = true;
30-
break;
31-
}
28+
if (Game.ignoreList.containsPlayer(message.fromPlayerIndex)) {
29+
hideMessage = true;
3230
}
3331
}
3432

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package org.runejs.client.message.handler.rs435.chat;
22

3-
import org.runejs.client.media.renderable.actor.Player;
3+
import org.runejs.client.Game;
44
import org.runejs.client.message.handler.MessageHandler;
55
import org.runejs.client.message.inbound.chat.UpdateIgnoreListInboundMessage;
66

77
public class UpdateIgnoreListMessageHandler implements MessageHandler<UpdateIgnoreListInboundMessage> {
88
@Override
99
public void handle(UpdateIgnoreListInboundMessage message) {
10-
Player.ignoresCount = message.ignores.length;
11-
12-
for(int i = 0; i < message.ignores.length; i++)
13-
Player.ignores[i] = message.ignores[i];
10+
Game.ignoreList.setPlayers(message.ignores);
1411
}
1512
}

0 commit comments

Comments
 (0)