forked from TheChef1337/PircBot2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannel.java
More file actions
275 lines (249 loc) · 6.8 KB
/
Copy pathChannel.java
File metadata and controls
275 lines (249 loc) · 6.8 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package PircBot;
import java.util.concurrent.*;
import java.util.*;
/**
* Defines a channel object.
*
* @author Michael
* @created 1/15/2016 @ 7:42am
*/
//broadcaster-lang=;r9k=0;slow=0;subs-only=0
public class Channel implements Iterable<User> {
private ConcurrentHashMap<String, User> users;
private String name;
private String server;
private String broadcasterLanguage = "";
private boolean r9k = false;
private int slow = 0;
private boolean subsOnly = false;
/**
* Constructs a new Channel Object with only the name and server. This
* constructor will make a blank Userlist.
*
* @param name Name of the channel, prefixed with #
* @param server Server IP
*/
public Channel(String name, String server) {
this.name = name;
this.server = server;
users = new ConcurrentHashMap<>();
}
/**
* Constructs a new Channel Object with a list of Users, the Channel Name,
* and the Server.
*
* @param users ConcurrentHashMap of the userlist
* @param name Channel Name, prefixed with #
* @param server Server IP
*/
public Channel(ConcurrentHashMap<String, User> users, String name, String server) {
this.users = users;
this.name = name;
this.server = server;
}
/**
* Constructs a new Channel Object with a list of Users, the Channel Name,
* and the Server.
*
* @param users User array for the Userlist
* @param name Channel Name, prefixed with #
* @param server Server IP
*/
public Channel(User[] users, String name, String server) {
this.name = name;
this.server = server;
this.users = new ConcurrentHashMap<>();
for (User el : users) {
this.users.put(el.getNick(), el);
}
}
/**
* Constructs a new Channel Object with a list of Users, the Channel Name,
* and the Server.
*
* @param users Userlist
* @param name Channel Name, prefixed with #
* @param server Server IP
*/
public Channel(List<User> users, String name, String server) {
this(users.toArray(new User[users.size()]), name, server);
}
/**
* Returns a single user object.
*
* @param user Name of the user to look for
* @return User requested, null if not found.
*/
public User getUser(String user) {
user = user.toLowerCase();
return users.get(user);
}
/**
* Adds a user to the userlist.
*
* @param user User object to add
*/
public void addUser(User user) {
users.put(user.getNick().toLowerCase(), user);
}
/**
* Updates a user object. It's recommended that you call the getUser(user)
* method before calling this method, so that you can update the user
* correctly.
*
* @param user User Object to update
*/
public void updateUser(User user) {
this.addUser(user);
}
/**
* Removes a user from the userlist.
*
* @param user User object to remove
*/
public void removeUser(User user) {
users.remove(user.getNick().toLowerCase());
}
/**
* Removes a user from the userlist.
*
* @param nick Username to remove
*/
public void removeUser(String nick) {
nick = nick.toLowerCase();
users.remove(nick);
}
public boolean containsUser(String nick) {
return users.containsKey(nick);
}
public boolean containsUser(User user) {
return users.containsValue(user);
}
/**
* Gets the current userlist.
*
* @return ArrayList containing user objects representing the userlist
*/
public ArrayList<User> getUserlist() {
ArrayList<User> toReturn = new ArrayList<>();
users.values().stream().forEach((el) -> {
toReturn.add(el);
});
Collections.sort(toReturn);
return toReturn;
}
/**
* Returns the size of the Userlist.
*
* @return Count of the users in the channel
*/
public int getUserCount() {
return users.size();
}
/**
* Returns the channel name.
*
* @return Current Channel Name
*/
public String getChannelName() {
return name;
}
/**
* Returns the current server IP
*
* @return Server IP
*/
public String getServer() {
return server;
}
/**
* Returns the broadcasting language of the channel. This will only return a
* value if the tags are enabled and a language is set.
*
* @return Broadcasting Language of the channel
*/
public String getBroadcasterLanguage() {
return broadcasterLanguage;
}
/**
* Sets the broadcast language of the channel.
*
* @param broadcasterLanguage Language
*/
public void setBroadcasterLanguage(String broadcasterLanguage) {
this.broadcasterLanguage = broadcasterLanguage;
}
/**
* Checks if the Channel is in R9K mode.
*
* @return True if in R9K, false if not
*/
public boolean isR9k() {
return r9k;
}
/**
* Sets the R9K Status of the channel.
* @param r9k R9K Status
*/
public void setR9k(boolean r9k) {
this.r9k = r9k;
}
/**
* Returns the status of Slow Mode on the channel.
* @return True if Slow Mode > 0, false if Slow Mode = 0.
*/
public boolean isSlow() {
return slow == 0;
}
/**
* Sets the slow mode for the channel.
* @param slow Integer for number of seconds between messages.
*/
public void setSlow(int slow) {
this.slow = slow;
}
/**
* Checks the Sub-Only chat status.
* @return True if the channel is in Sub-Only mode, false otherwise
*/
public boolean isSubsOnly() {
return subsOnly;
}
/**
* Sets the Sub-Only status in the channel.
* @param subsOnly Sub-Only status.
*/
public void setSubsOnly(boolean subsOnly) {
this.subsOnly = subsOnly;
}
@Override
public Iterator<User> iterator() {
return getUserlist().iterator();
}
@Override
public int hashCode() {
int hash = 3;
hash = 97 * hash + Objects.hashCode(this.users);
hash = 97 * hash + Objects.hashCode(this.name);
hash = 97 * hash + Objects.hashCode(this.server);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Channel other = (Channel) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
return Objects.equals(this.server, other.server);
}
@Override
public String toString() {
return name;
}
}