@@ -166,15 +166,10 @@ private File getUserDirectory(String steamPath) {
166
166
Set <Player > getAdmins () {
167
167
Set <Player > admins = new HashSet <Player >();
168
168
try {
169
- for (String steamId : FileUtilities .getLines (ADMINS_PATH , false )) {
170
- if (steamId .matches ("[0-9]+(\\ s*//.*)?" )) {
171
- admins .add (Player .getPlayerFromSteamId (steamId .split ("\\ s*//" )[0 ]));
172
- }
173
- }
169
+ admins = getPlayers (ADMINS_PATH );
174
170
} catch (IOException e ) {
175
- new IOException ("Error: Failed to read the admins list at " + ADMINS_PATH + "." , e ).printStackTrace ();
171
+ new IOException ("Error: Failed to read the admins list from " + ADMINS_PATH + "." , e ).printStackTrace ();
176
172
}
177
- admins .add (getOwner ());
178
173
return admins ;
179
174
}
180
175
@@ -186,17 +181,46 @@ Set<Player> getAdmins() {
186
181
Set <Player > getBannedPlayers () {
187
182
Set <Player > bannedPlayers = new HashSet <Player >();
188
183
try {
189
- for (String line : FileUtilities .getLines (BANNED_PLAYERS_PATH , false )) {
190
- if (line .matches ("[0-9]+(\\ s*//.*)?" )) {
191
- bannedPlayers .add (Player .getPlayerFromSteamId (line .split ("\\ s*//" )[0 ]));
192
- }
193
- }
184
+ bannedPlayers = getPlayers (BANNED_PLAYERS_PATH );
194
185
} catch (IOException e ) {
195
- new IOException ("Error: Failed to read the banned players list from " + BANNED_PLAYERS_PATH + "." , e );
186
+ String message = "Error: Failed to read the banned players list from " + BANNED_PLAYERS_PATH + "." ;
187
+ new IOException (message , e ).printStackTrace ();
196
188
}
197
189
return bannedPlayers ;
198
190
}
199
191
192
+ private Set <Player > getPlayers (String path ) throws IOException {
193
+ Set <Player > players = new HashSet <Player >();
194
+ boolean rewriteFile = false ;
195
+ String [] lines = FileUtilities .getLines (path , false );
196
+ for (int i = 0 ; i < lines .length ; i ++) {
197
+ lines [i ] = lines [i ].replaceAll ("http(?:s?)://" , "" ).trim ();
198
+ String steamId = lines [i ].split ("\\ s*//" )[0 ];
199
+ String profileId = Player .getSteamProfileId (steamId ); // if line is a profile URL
200
+ try {
201
+ if (profileId != null ) {
202
+ rewriteFile = true ;
203
+ int commentPosition = lines [i ].indexOf ("//" );
204
+ String comment = commentPosition == -1 ? steamId : lines [i ].split ("//" )[1 ].trim ();
205
+ if (lines [i ].contains ("profiles" )) {
206
+ steamId = profileId ;
207
+ } else {
208
+ steamId = Player .getSteamId3FromProfile (profileId );
209
+ }
210
+ lines [i ] = steamId + " // " + comment ;
211
+ }
212
+ players .add (Player .getPlayerFromSteamId (steamId ));
213
+ } catch (Exception e ) {
214
+ String message = "Error: Failed while converting Steam profile URL to SteamID." ;
215
+ new Exception (message , e ).printStackTrace ();
216
+ }
217
+ }
218
+ if (rewriteFile ) {
219
+ FileUtilities .writeFile (path , lines );
220
+ }
221
+ return players ;
222
+ }
223
+
200
224
Set <String > getBlockedSongs () {
201
225
Set <String > blockedSongs = new HashSet <String >();
202
226
try {
@@ -256,10 +280,7 @@ void writeProperty(String property, String value) {
256
280
if (!foundProperty ) {
257
281
fileText += property + DELIMITER + " " + value + System .lineSeparator ();
258
282
}
259
- File file = new File (PROPERTIES_PATH );
260
- file .delete ();
261
- Files .write (Paths .get (PROPERTIES_PATH ), fileText .getBytes (), StandardOpenOption .CREATE );
262
- FileUtilities .trimFile (PROPERTIES_PATH );
283
+ FileUtilities .writeFile (PROPERTIES_PATH , fileText );
263
284
} catch (IOException e ) {
264
285
String message = "Error: Failed to write \" " + property + "\" property to " + PROPERTIES_PATH + "." ;
265
286
new IOException (message , e ).printStackTrace ();
@@ -400,10 +421,7 @@ private void updateAndSyncProperties(Map<String, String> newProperties) {
400
421
fileText += propertyNames [i ] + DELIMITER + " " + properties .get (propertyNames [i ]) + seperator ;
401
422
}
402
423
try {
403
- File file = new File (PROPERTIES_PATH );
404
- file .delete ();
405
- Files .write (Paths .get (PROPERTIES_PATH ), fileText .getBytes (), StandardOpenOption .CREATE );
406
- FileUtilities .trimFile (PROPERTIES_PATH );
424
+ FileUtilities .writeFile (PROPERTIES_PATH , fileText );
407
425
} catch (IOException e ) {
408
426
e .printStackTrace ();
409
427
}
@@ -434,8 +452,8 @@ private Map<String, String> readProperties(String path, String[] propertiesToRea
434
452
for (String property : properties .keySet ()) {
435
453
if (line .toLowerCase ().startsWith (property + DELIMITER )) {
436
454
if (propertiesRead .contains (property )) {
437
- throw new IOException ("The property \" " + property
438
- + " \" is listed more than once in \" " + filename + "\" ." );
455
+ throw new IOException ("The property \" " + property + " \" is listed more than once in \" "
456
+ + filename + "\" ." );
439
457
}
440
458
if (line .matches (".*//.*" )) {
441
459
line = line .replaceAll ("\\ s*//.*" , "" );
0 commit comments