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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
|
--- a/net/minecraft/server/players/OldUsersConverter.java
+++ b/net/minecraft/server/players/OldUsersConverter.java
@@ -21,6 +21,9 @@
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.core.UUIDUtil;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtAccounter;
+import net.minecraft.nbt.NbtIo;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.util.StringUtil;
@@ -37,8 +40,8 @@
public OldUsersConverter() {}
- static List<String> readOldListFormat(File file, Map<String, String[]> map) throws IOException {
- List<String> list = Files.readLines(file, StandardCharsets.UTF_8);
+ static List<String> readOldListFormat(File inFile, Map<String, String[]> read) throws IOException {
+ List<String> list = Files.readLines(inFile, StandardCharsets.UTF_8);
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
@@ -48,22 +51,22 @@
if (!s.startsWith("#") && s.length() >= 1) {
String[] astring = s.split("\\|");
- map.put(astring[0].toLowerCase(Locale.ROOT), astring);
+ read.put(astring[0].toLowerCase(Locale.ROOT), astring);
}
}
return list;
}
- private static void lookupPlayers(MinecraftServer minecraftserver, Collection<String> collection, ProfileLookupCallback profilelookupcallback) {
- String[] astring = (String[]) collection.stream().filter((s) -> {
+ private static void lookupPlayers(MinecraftServer server, Collection<String> names, ProfileLookupCallback callback) {
+ String[] astring = (String[]) names.stream().filter((s) -> {
return !StringUtil.isNullOrEmpty(s);
}).toArray((i) -> {
return new String[i];
});
- if (minecraftserver.usesAuthentication()) {
- minecraftserver.getProfileRepository().findProfilesByNames(astring, profilelookupcallback);
+ if (server.usesAuthentication()) {
+ server.getProfileRepository().findProfilesByNames(astring, callback);
} else {
String[] astring1 = astring;
int i = astring.length;
@@ -71,21 +74,21 @@
for (int j = 0; j < i; ++j) {
String s = astring1[j];
- profilelookupcallback.onProfileLookupSucceeded(UUIDUtil.createOfflineProfile(s));
+ callback.onProfileLookupSucceeded(UUIDUtil.createOfflineProfile(s));
}
}
}
- public static boolean convertUserBanlist(final MinecraftServer minecraftserver) {
- final UserBanList userbanlist = new UserBanList(PlayerList.USERBANLIST_FILE);
+ public static boolean convertUserBanlist(final MinecraftServer server) {
+ final UserBanList gameprofilebanlist = new UserBanList(PlayerList.USERBANLIST_FILE);
if (OldUsersConverter.OLD_USERBANLIST.exists() && OldUsersConverter.OLD_USERBANLIST.isFile()) {
- if (userbanlist.getFile().exists()) {
+ if (gameprofilebanlist.getFile().exists()) {
try {
- userbanlist.load();
+ gameprofilebanlist.load();
} catch (IOException ioexception) {
- OldUsersConverter.LOGGER.warn("Could not load existing file {}", userbanlist.getFile().getName(), ioexception);
+ OldUsersConverter.LOGGER.warn("Could not load existing file {}", gameprofilebanlist.getFile().getName()); // CraftBukkit - don't print stacktrace
}
}
@@ -94,9 +97,8 @@
readOldListFormat(OldUsersConverter.OLD_USERBANLIST, map);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
- @Override
public void onProfileLookupSucceeded(GameProfile gameprofile) {
- minecraftserver.getProfileCache().add(gameprofile);
+ server.getProfileCache().add(gameprofile);
String[] astring = (String[]) map.get(gameprofile.getName().toLowerCase(Locale.ROOT));
if (astring == null) {
@@ -108,11 +110,10 @@
Date date1 = astring.length > 3 ? OldUsersConverter.parseDate(astring[3], (Date) null) : null;
String s1 = astring.length > 4 ? astring[4] : null;
- userbanlist.add(new UserBanListEntry(gameprofile, date, s, date1, s1));
+ gameprofilebanlist.add(new UserBanListEntry(gameprofile, date, s, date1, s1));
}
}
- @Override
public void onProfileLookupFailed(String s, Exception exception) {
OldUsersConverter.LOGGER.warn("Could not lookup user banlist entry for {}", s, exception);
if (!(exception instanceof ProfileNotFoundException)) {
@@ -121,15 +122,15 @@
}
};
- lookupPlayers(minecraftserver, map.keySet(), profilelookupcallback);
- userbanlist.save();
+ lookupPlayers(server, map.keySet(), profilelookupcallback);
+ gameprofilebanlist.save();
renameOldFile(OldUsersConverter.OLD_USERBANLIST);
return true;
} catch (IOException ioexception1) {
OldUsersConverter.LOGGER.warn("Could not read old user banlist to convert it!", ioexception1);
return false;
- } catch (OldUsersConverter.ConversionError oldusersconverter_conversionerror) {
- OldUsersConverter.LOGGER.error("Conversion failed, please try again later", oldusersconverter_conversionerror);
+ } catch (OldUsersConverter.ConversionError namereferencingfileconverter_fileconversionexception) {
+ OldUsersConverter.LOGGER.error("Conversion failed, please try again later", namereferencingfileconverter_fileconversionexception);
return false;
}
} else {
@@ -137,7 +138,7 @@
}
}
- public static boolean convertIpBanlist(MinecraftServer minecraftserver) {
+ public static boolean convertIpBanlist(MinecraftServer server) {
IpBanList ipbanlist = new IpBanList(PlayerList.IPBANLIST_FILE);
if (OldUsersConverter.OLD_IPBANLIST.exists() && OldUsersConverter.OLD_IPBANLIST.isFile()) {
@@ -145,7 +146,7 @@
try {
ipbanlist.load();
} catch (IOException ioexception) {
- OldUsersConverter.LOGGER.warn("Could not load existing file {}", ipbanlist.getFile().getName(), ioexception);
+ OldUsersConverter.LOGGER.warn("Could not load existing file {}", ipbanlist.getFile().getName()); // CraftBukkit - don't print stacktrace
}
}
@@ -178,28 +179,26 @@
}
}
- public static boolean convertOpsList(final MinecraftServer minecraftserver) {
- final ServerOpList serveroplist = new ServerOpList(PlayerList.OPLIST_FILE);
+ public static boolean convertOpsList(final MinecraftServer server) {
+ final ServerOpList oplist = new ServerOpList(PlayerList.OPLIST_FILE);
if (OldUsersConverter.OLD_OPLIST.exists() && OldUsersConverter.OLD_OPLIST.isFile()) {
- if (serveroplist.getFile().exists()) {
+ if (oplist.getFile().exists()) {
try {
- serveroplist.load();
+ oplist.load();
} catch (IOException ioexception) {
- OldUsersConverter.LOGGER.warn("Could not load existing file {}", serveroplist.getFile().getName(), ioexception);
+ OldUsersConverter.LOGGER.warn("Could not load existing file {}", oplist.getFile().getName()); // CraftBukkit - don't print stacktrace
}
}
try {
List<String> list = Files.readLines(OldUsersConverter.OLD_OPLIST, StandardCharsets.UTF_8);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
- @Override
public void onProfileLookupSucceeded(GameProfile gameprofile) {
- minecraftserver.getProfileCache().add(gameprofile);
- serveroplist.add(new ServerOpListEntry(gameprofile, minecraftserver.getOperatorUserPermissionLevel(), false));
+ server.getProfileCache().add(gameprofile);
+ oplist.add(new ServerOpListEntry(gameprofile, server.getOperatorUserPermissionLevel(), false));
}
- @Override
public void onProfileLookupFailed(String s, Exception exception) {
OldUsersConverter.LOGGER.warn("Could not lookup oplist entry for {}", s, exception);
if (!(exception instanceof ProfileNotFoundException)) {
@@ -208,15 +207,15 @@
}
};
- lookupPlayers(minecraftserver, list, profilelookupcallback);
- serveroplist.save();
+ lookupPlayers(server, list, profilelookupcallback);
+ oplist.save();
renameOldFile(OldUsersConverter.OLD_OPLIST);
return true;
} catch (IOException ioexception1) {
OldUsersConverter.LOGGER.warn("Could not read old oplist to convert it!", ioexception1);
return false;
- } catch (OldUsersConverter.ConversionError oldusersconverter_conversionerror) {
- OldUsersConverter.LOGGER.error("Conversion failed, please try again later", oldusersconverter_conversionerror);
+ } catch (OldUsersConverter.ConversionError namereferencingfileconverter_fileconversionexception) {
+ OldUsersConverter.LOGGER.error("Conversion failed, please try again later", namereferencingfileconverter_fileconversionexception);
return false;
}
} else {
@@ -224,28 +223,26 @@
}
}
- public static boolean convertWhiteList(final MinecraftServer minecraftserver) {
- final UserWhiteList userwhitelist = new UserWhiteList(PlayerList.WHITELIST_FILE);
+ public static boolean convertWhiteList(final MinecraftServer server) {
+ final UserWhiteList whitelist = new UserWhiteList(PlayerList.WHITELIST_FILE);
if (OldUsersConverter.OLD_WHITELIST.exists() && OldUsersConverter.OLD_WHITELIST.isFile()) {
- if (userwhitelist.getFile().exists()) {
+ if (whitelist.getFile().exists()) {
try {
- userwhitelist.load();
+ whitelist.load();
} catch (IOException ioexception) {
- OldUsersConverter.LOGGER.warn("Could not load existing file {}", userwhitelist.getFile().getName(), ioexception);
+ OldUsersConverter.LOGGER.warn("Could not load existing file {}", whitelist.getFile().getName()); // CraftBukkit - don't print stacktrace
}
}
try {
List<String> list = Files.readLines(OldUsersConverter.OLD_WHITELIST, StandardCharsets.UTF_8);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
- @Override
public void onProfileLookupSucceeded(GameProfile gameprofile) {
- minecraftserver.getProfileCache().add(gameprofile);
- userwhitelist.add(new UserWhiteListEntry(gameprofile));
+ server.getProfileCache().add(gameprofile);
+ whitelist.add(new UserWhiteListEntry(gameprofile));
}
- @Override
public void onProfileLookupFailed(String s, Exception exception) {
OldUsersConverter.LOGGER.warn("Could not lookup user whitelist entry for {}", s, exception);
if (!(exception instanceof ProfileNotFoundException)) {
@@ -254,15 +251,15 @@
}
};
- lookupPlayers(minecraftserver, list, profilelookupcallback);
- userwhitelist.save();
+ lookupPlayers(server, list, profilelookupcallback);
+ whitelist.save();
renameOldFile(OldUsersConverter.OLD_WHITELIST);
return true;
} catch (IOException ioexception1) {
OldUsersConverter.LOGGER.warn("Could not read old whitelist to convert it!", ioexception1);
return false;
- } catch (OldUsersConverter.ConversionError oldusersconverter_conversionerror) {
- OldUsersConverter.LOGGER.error("Conversion failed, please try again later", oldusersconverter_conversionerror);
+ } catch (OldUsersConverter.ConversionError namereferencingfileconverter_fileconversionexception) {
+ OldUsersConverter.LOGGER.error("Conversion failed, please try again later", namereferencingfileconverter_fileconversionexception);
return false;
}
} else {
@@ -271,43 +268,41 @@
}
@Nullable
- public static UUID convertMobOwnerIfNecessary(final MinecraftServer minecraftserver, String s) {
- if (!StringUtil.isNullOrEmpty(s) && s.length() <= 16) {
- Optional<UUID> optional = minecraftserver.getProfileCache().get(s).map(GameProfile::getId);
+ public static UUID convertMobOwnerIfNecessary(final MinecraftServer server, String username) {
+ if (!StringUtil.isNullOrEmpty(username) && username.length() <= 16) {
+ Optional<UUID> optional = server.getProfileCache().get(username).map(GameProfile::getId);
if (optional.isPresent()) {
return (UUID) optional.get();
- } else if (!minecraftserver.isSingleplayer() && minecraftserver.usesAuthentication()) {
+ } else if (!server.isSingleplayer() && server.usesAuthentication()) {
final List<GameProfile> list = Lists.newArrayList();
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
- @Override
public void onProfileLookupSucceeded(GameProfile gameprofile) {
- minecraftserver.getProfileCache().add(gameprofile);
+ server.getProfileCache().add(gameprofile);
list.add(gameprofile);
}
- @Override
public void onProfileLookupFailed(String s1, Exception exception) {
OldUsersConverter.LOGGER.warn("Could not lookup user whitelist entry for {}", s1, exception);
}
};
- lookupPlayers(minecraftserver, Lists.newArrayList(new String[]{s}), profilelookupcallback);
+ lookupPlayers(server, Lists.newArrayList(new String[]{username}), profilelookupcallback);
return !list.isEmpty() ? ((GameProfile) list.get(0)).getId() : null;
} else {
- return UUIDUtil.createOfflinePlayerUUID(s);
+ return UUIDUtil.createOfflinePlayerUUID(username);
}
} else {
try {
- return UUID.fromString(s);
+ return UUID.fromString(username);
} catch (IllegalArgumentException illegalargumentexception) {
return null;
}
}
}
- public static boolean convertPlayers(final DedicatedServer dedicatedserver) {
- final File file = getWorldPlayersDirectory(dedicatedserver);
+ public static boolean convertPlayers(final DedicatedServer server) {
+ final File file = getWorldPlayersDirectory(server);
final File file1 = new File(file.getParentFile(), "playerdata");
final File file2 = new File(file.getParentFile(), "unknownplayers");
@@ -333,15 +328,13 @@
try {
final String[] astring = (String[]) list.toArray(new String[list.size()]);
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
- @Override
public void onProfileLookupSucceeded(GameProfile gameprofile) {
- dedicatedserver.getProfileCache().add(gameprofile);
+ server.getProfileCache().add(gameprofile);
UUID uuid = gameprofile.getId();
this.movePlayerFile(file1, this.getFileNameForProfile(gameprofile.getName()), uuid.toString());
}
- @Override
public void onProfileLookupFailed(String s2, Exception exception) {
OldUsersConverter.LOGGER.warn("Could not lookup user uuid for {}", s2, exception);
if (exception instanceof ProfileNotFoundException) {
@@ -353,13 +346,37 @@
}
}
- private void movePlayerFile(File file4, String s2, String s3) {
- File file5 = new File(file, s2 + ".dat");
- File file6 = new File(file4, s3 + ".dat");
+ private void movePlayerFile(File file, String oldFileName, String newFileName) {
+ File file5 = new File(file, oldFileName + ".dat");
+ File file6 = new File(file, newFileName + ".dat");
- OldUsersConverter.ensureDirectoryExists(file4);
+ // CraftBukkit start - Use old file name to seed lastKnownName
+ CompoundTag root = null;
+
+ try {
+ root = NbtIo.readCompressed(new java.io.FileInputStream(file5), NbtAccounter.unlimitedHeap());
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+
+ if (root != null) {
+ if (!root.contains("bukkit")) {
+ root.put("bukkit", new CompoundTag());
+ }
+ CompoundTag data = root.getCompound("bukkit");
+ data.putString("lastKnownName", oldFileName);
+
+ try {
+ NbtIo.writeCompressed(root, new java.io.FileOutputStream(file2));
+ } catch (Exception exception) {
+ exception.printStackTrace();
+ }
+ }
+ // CraftBukkit end
+
+ OldUsersConverter.ensureDirectoryExists(file);
if (!file5.renameTo(file6)) {
- throw new OldUsersConverter.ConversionError("Could not convert file for " + s2);
+ throw new OldUsersConverter.ConversionError("Could not convert file for " + oldFileName);
}
}
@@ -385,10 +402,10 @@
}
};
- lookupPlayers(dedicatedserver, Lists.newArrayList(astring), profilelookupcallback);
+ lookupPlayers(server, Lists.newArrayList(astring), profilelookupcallback);
return true;
- } catch (OldUsersConverter.ConversionError oldusersconverter_conversionerror) {
- OldUsersConverter.LOGGER.error("Conversion failed, please try again later", oldusersconverter_conversionerror);
+ } catch (OldUsersConverter.ConversionError namereferencingfileconverter_fileconversionexception) {
+ OldUsersConverter.LOGGER.error("Conversion failed, please try again later", namereferencingfileconverter_fileconversionexception);
return false;
}
} else {
@@ -396,20 +413,20 @@
}
}
- static void ensureDirectoryExists(File file) {
- if (file.exists()) {
- if (!file.isDirectory()) {
- throw new OldUsersConverter.ConversionError("Can't create directory " + file.getName() + " in world save directory.");
+ static void ensureDirectoryExists(File dir) {
+ if (dir.exists()) {
+ if (!dir.isDirectory()) {
+ throw new OldUsersConverter.ConversionError("Can't create directory " + dir.getName() + " in world save directory.");
}
- } else if (!file.mkdirs()) {
- throw new OldUsersConverter.ConversionError("Can't create directory " + file.getName() + " in world save directory.");
+ } else if (!dir.mkdirs()) {
+ throw new OldUsersConverter.ConversionError("Can't create directory " + dir.getName() + " in world save directory.");
}
}
- public static boolean serverReadyAfterUserconversion(MinecraftServer minecraftserver) {
+ public static boolean serverReadyAfterUserconversion(MinecraftServer server) {
boolean flag = areOldUserlistsRemoved();
- flag = flag && areOldPlayersConverted(minecraftserver);
+ flag = flag && areOldPlayersConverted(server);
return flag;
}
@@ -463,8 +480,8 @@
}
}
- private static boolean areOldPlayersConverted(MinecraftServer minecraftserver) {
- File file = getWorldPlayersDirectory(minecraftserver);
+ private static boolean areOldPlayersConverted(MinecraftServer server) {
+ File file = getWorldPlayersDirectory(server);
if (file.exists() && file.isDirectory() && (file.list().length > 0 || !file.delete())) {
OldUsersConverter.LOGGER.warn("**** DETECTED OLD PLAYER DIRECTORY IN THE WORLD SAVE");
@@ -476,23 +493,23 @@
}
}
- private static File getWorldPlayersDirectory(MinecraftServer minecraftserver) {
- return minecraftserver.getWorldPath(LevelResource.PLAYER_OLD_DATA_DIR).toFile();
+ private static File getWorldPlayersDirectory(MinecraftServer server) {
+ return server.getWorldPath(LevelResource.PLAYER_OLD_DATA_DIR).toFile();
}
- private static void renameOldFile(File file) {
- File file1 = new File(file.getName() + ".converted");
+ private static void renameOldFile(File convertedFile) {
+ File file1 = new File(convertedFile.getName() + ".converted");
- file.renameTo(file1);
+ convertedFile.renameTo(file1);
}
- static Date parseDate(String s, Date date) {
+ static Date parseDate(String input, Date defaultValue) {
Date date1;
try {
- date1 = BanListEntry.DATE_FORMAT.parse(s);
+ date1 = BanListEntry.DATE_FORMAT.parse(input);
} catch (ParseException parseexception) {
- date1 = date;
+ date1 = defaultValue;
}
return date1;
@@ -500,12 +517,12 @@
private static class ConversionError extends RuntimeException {
- ConversionError(String s, Throwable throwable) {
- super(s, throwable);
+ ConversionError(String message, Throwable cause) {
+ super(message, cause);
}
- ConversionError(String s) {
- super(s);
+ ConversionError(String message) {
+ super(message);
}
}
}
|