forked from bootswithdefer/LogBlock
/
Updater.java
1083 lines (1023 loc) · 59.8 KB
/
Updater.java
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package de.diddiz.LogBlock;
import de.diddiz.LogBlock.blockstate.BlockStateCodecSign;
import de.diddiz.LogBlock.config.Config;
import de.diddiz.LogBlock.config.WorldConfig;
import de.diddiz.util.UUIDFetcher;
import de.diddiz.util.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.*;
import java.util.*;
import java.util.jar.JarFile;
import java.util.logging.Level;
import static de.diddiz.LogBlock.config.Config.getLoggedWorlds;
import static de.diddiz.LogBlock.config.Config.isLogging;
import static de.diddiz.util.BukkitUtils.friendlyWorldname;
import de.diddiz.util.ComparableVersion;
class Updater {
private final LogBlock logblock;
final int UUID_CONVERT_BATCH_SIZE = 100;
final int BLOCKS_CONVERT_BATCH_SIZE = 100000;
final int OTHER_CONVERT_BATCH_SIZE = 20000;
Updater(LogBlock logblock) {
this.logblock = logblock;
}
boolean update() {
final ConfigurationSection config = logblock.getConfig();
String versionString = config.getString("version");
ComparableVersion configVersion = new ComparableVersion(versionString);
// if (configVersion.compareTo(new ComparableVersion(logblock.getDescription().getVersion().replace(" (manually compiled)", ""))) >= 0) {
// return false;
// }
if (configVersion.compareTo(new ComparableVersion("1.2.7")) < 0) {
logblock.getLogger().info("Updating tables to 1.2.7 ...");
if (isLogging(Logging.CHAT)) {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-chat` ADD FULLTEXT message (message)");
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
config.set("version", "1.2.7");
}
if (configVersion.compareTo(new ComparableVersion("1.3")) < 0) {
logblock.getLogger().info("Updating config to 1.3.0 ...");
for (final String tool : config.getConfigurationSection("tools").getKeys(false)) {
if (config.get("tools." + tool + ".permissionDefault") == null) {
config.set("tools." + tool + ".permissionDefault", "OP");
}
}
config.set("version", "1.3.0");
}
if (configVersion.compareTo(new ComparableVersion("1.3.1")) < 0) {
logblock.getLogger().info("Updating tables to 1.3.1 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN lastlogin DATETIME NOT NULL, ADD COLUMN onlinetime TIME NOT NULL, ADD COLUMN ip VARCHAR(255) NOT NULL");
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.3.1");
}
if (configVersion.compareTo(new ComparableVersion("1.3.2")) < 0) {
logblock.getLogger().info("Updating tables to 1.3.2 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD COLUMN firstlogin DATETIME NOT NULL AFTER playername");
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.3.2");
}
if (configVersion.compareTo(new ComparableVersion("1.4")) < 0) {
logblock.getLogger().info("Updating config to 1.4.0 ...");
config.set("clearlog.keepLogDays", null);
config.set("version", "1.4.0");
}
if (configVersion.compareTo(new ComparableVersion("1.4.2")) < 0) {
logblock.getLogger().info("Updating config to 1.4.2 ...");
for (final String world : config.getStringList("loggedWorlds")) {
final File file = new File(logblock.getDataFolder(), friendlyWorldname(world) + ".yml");
final YamlConfiguration wcfg = YamlConfiguration.loadConfiguration(file);
if (wcfg.contains("logBlockCreations")) {
wcfg.set("logging.BLOCKPLACE", wcfg.getBoolean("logBlockCreations"));
}
if (wcfg.contains("logBlockDestroyings")) {
wcfg.set("logging.BLOCKBREAK", wcfg.getBoolean("logBlockDestroyings"));
}
if (wcfg.contains("logSignTexts")) {
wcfg.set("logging.SIGNTEXT", wcfg.getBoolean("logSignTexts"));
}
if (wcfg.contains("logFire")) {
wcfg.set("logging.FIRE", wcfg.getBoolean("logFire"));
}
if (wcfg.contains("logLeavesDecay")) {
wcfg.set("logging.LEAVESDECAY", wcfg.getBoolean("logLeavesDecay"));
}
if (wcfg.contains("logLavaFlow")) {
wcfg.set("logging.LAVAFLOW", wcfg.getBoolean("logLavaFlow"));
}
if (wcfg.contains("logWaterFlow")) {
wcfg.set("logging.WATERFLOW", wcfg.getBoolean("logWaterFlow"));
}
if (wcfg.contains("logChestAccess")) {
wcfg.set("logging.CHESTACCESS", wcfg.getBoolean("logChestAccess"));
}
if (wcfg.contains("logButtonsAndLevers")) {
wcfg.set("logging.SWITCHINTERACT", wcfg.getBoolean("logButtonsAndLevers"));
}
if (wcfg.contains("logKills")) {
wcfg.set("logging.KILL", wcfg.getBoolean("logKills"));
}
if (wcfg.contains("logChat")) {
wcfg.set("logging.CHAT", wcfg.getBoolean("logChat"));
}
if (wcfg.contains("logSnowForm")) {
wcfg.set("logging.SNOWFORM", wcfg.getBoolean("logSnowForm"));
}
if (wcfg.contains("logSnowFade")) {
wcfg.set("logging.SNOWFADE", wcfg.getBoolean("logSnowFade"));
}
if (wcfg.contains("logDoors")) {
wcfg.set("logging.DOORINTERACT", wcfg.getBoolean("logDoors"));
}
if (wcfg.contains("logCakes")) {
wcfg.set("logging.CAKEEAT", wcfg.getBoolean("logCakes"));
}
if (wcfg.contains("logEndermen")) {
wcfg.set("logging.ENDERMEN", wcfg.getBoolean("logEndermen"));
}
if (wcfg.contains("logExplosions")) {
final boolean logExplosions = wcfg.getBoolean("logExplosions");
wcfg.set("logging.TNTEXPLOSION", logExplosions);
wcfg.set("logging.MISCEXPLOSION", logExplosions);
wcfg.set("logging.CREEPEREXPLOSION", logExplosions);
wcfg.set("logging.GHASTFIREBALLEXPLOSION", logExplosions);
}
wcfg.set("logBlockCreations", null);
wcfg.set("logBlockDestroyings", null);
wcfg.set("logSignTexts", null);
wcfg.set("logExplosions", null);
wcfg.set("logFire", null);
wcfg.set("logLeavesDecay", null);
wcfg.set("logLavaFlow", null);
wcfg.set("logWaterFlow", null);
wcfg.set("logChestAccess", null);
wcfg.set("logButtonsAndLevers", null);
wcfg.set("logKills", null);
wcfg.set("logChat", null);
wcfg.set("logSnowForm", null);
wcfg.set("logSnowFade", null);
wcfg.set("logDoors", null);
wcfg.set("logCakes", null);
wcfg.set("logEndermen", null);
try {
wcfg.save(file);
} catch (final IOException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
config.set("clearlog.keepLogDays", null);
config.set("version", "1.4.2");
}
if (configVersion.compareTo(new ComparableVersion("1.5.1")) < 0) {
logblock.getLogger().info("Updating tables to 1.5.1 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.KILL)) {
st.execute("ALTER TABLE `" + wcfg.table + "-kills` ADD (x MEDIUMINT NOT NULL DEFAULT 0, y SMALLINT NOT NULL DEFAULT 0, z MEDIUMINT NOT NULL DEFAULT 0)");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.5.1");
}
if (configVersion.compareTo(new ComparableVersion("1.5.2")) < 0) {
logblock.getLogger().info("Updating tables to 1.5.2 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
final ResultSet rs = st.executeQuery("SHOW COLUMNS FROM `lb-players` WHERE field = 'onlinetime'");
if (rs.next() && rs.getString("Type").equalsIgnoreCase("time")) {
st.execute("ALTER TABLE `lb-players` ADD onlinetime2 INT UNSIGNED NOT NULL");
st.execute("UPDATE `lb-players` SET onlinetime2 = HOUR(onlinetime) * 3600 + MINUTE(onlinetime) * 60 + SECOND(onlinetime)");
st.execute("ALTER TABLE `lb-players` DROP onlinetime");
st.execute("ALTER TABLE `lb-players` CHANGE onlinetime2 onlinetime INT UNSIGNED NOT NULL");
} else {
logblock.getLogger().info("Column lb-players was already modified, skipping it.");
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.5.2");
}
if (configVersion.compareTo(new ComparableVersion("1.8.1")) < 0) {
logblock.getLogger().info("Updating tables to 1.8.1 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.CHESTACCESS)) {
st.execute("ALTER TABLE `" + wcfg.table + "-chest` CHANGE itemdata itemdata SMALLINT NOT NULL");
logblock.getLogger().info("Table " + wcfg.table + "-chest modified");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.8.1");
}
if (configVersion.compareTo(new ComparableVersion("1.9")) < 0) {
logblock.getLogger().info("Updating tables to 1.9.0 ...");
logblock.getLogger().info("Importing UUIDs for large databases may take some time");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-players` ADD `UUID` VARCHAR(36) NOT NULL");
} catch (final SQLException ex) {
// Error 1060 is MySQL error "column already exists". We want to continue with import if we get that error
if (ex.getErrorCode() != 1060) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
String unimportedPrefix = "noimport_";
ResultSet rs;
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
if (config.getBoolean("logging.logPlayerInfo")) {
// Start by assuming anything with no onlinetime is not a player
st.execute("UPDATE `lb-players` SET UUID = CONCAT ('log_',playername) WHERE onlinetime=0 AND LENGTH(UUID) = 0");
} else {
// If we can't assume that, we must assume anything we can't look up is not a player
unimportedPrefix = "log_";
}
// Tell people how many are needing converted
rs = st.executeQuery("SELECT COUNT(playername) FROM `lb-players` WHERE LENGTH(UUID)=0");
rs.next();
String total = Integer.toString(rs.getInt(1));
logblock.getLogger().info(total + " players to convert");
int done = 0;
conn.setAutoCommit(false);
Map<String, Integer> players = new HashMap<String, Integer>();
List<String> names = new ArrayList<String>(UUID_CONVERT_BATCH_SIZE);
Map<String, UUID> response;
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
while (rs.next()) {
do {
players.put(rs.getString(2), rs.getInt(1));
names.add(rs.getString(2));
} while (rs.next());
if (names.size() > 0) {
String theUUID;
response = UUIDFetcher.getUUIDs(names);
for (Map.Entry<String, Integer> entry : players.entrySet()) {
if (response.get(entry.getKey()) == null) {
theUUID = unimportedPrefix + entry.getKey();
logblock.getLogger().warning(entry.getKey() + " not found - giving UUID of " + theUUID);
} else {
theUUID = response.get(entry.getKey()).toString();
}
String thePID = entry.getValue().toString();
st.execute("UPDATE `lb-players` SET UUID = '" + theUUID + "' WHERE playerid = " + thePID);
done++;
}
conn.commit();
players.clear();
names.clear();
logblock.getLogger().info("Processed " + Integer.toString(done) + " out of " + total);
rs.close();
rs = st.executeQuery("SELECT playerid,playername FROM `lb-players` WHERE LENGTH(UUID)=0 LIMIT " + Integer.toString(UUID_CONVERT_BATCH_SIZE));
}
}
rs.close();
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
} catch (Exception ex) {
logblock.getLogger().log(Level.SEVERE, "[UUID importer]", ex);
return false;
}
config.set("version", "1.9.0");
}
if (configVersion.compareTo(new ComparableVersion("1.9.4")) < 0) {
logblock.getLogger().info("Updating tables to 1.9.4 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
// Need to wrap both these next two inside individual try/catch statements in case index does not exist
try {
st.execute("DROP INDEX UUID ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
try {
st.execute("DROP INDEX playername ON `lb-players`");
} catch (final SQLException ex) {
if (ex.getErrorCode() != 1091) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
st.execute("CREATE INDEX UUID ON `lb-players` (UUID);");
st.execute("CREATE INDEX playername ON `lb-players` (playername);");
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.9.4");
}
// Ensure charset for free-text fields is UTF-8, or UTF8-mb4 if possible
// As this may be an expensive operation and the database default may already be this, check on a table-by-table basis before converting
if (configVersion.compareTo(new ComparableVersion("1.10.0")) < 0) {
logblock.getLogger().info("Updating tables to 1.10.0 ...");
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
checkCharset("lb-players", "name", st, false);
if (isLogging(Logging.CHAT)) {
checkCharset("lb-chat", "message", st, false);
}
for (final WorldConfig wcfg : getLoggedWorlds()) {
if (wcfg.isLogging(Logging.SIGNTEXT)) {
// checkCharset(wcfg.table + "-sign","signtext",st);
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.10.0");
}
if (configVersion.compareTo(new ComparableVersion("1.12.0")) < 0) {
logblock.getLogger().info("Updating tables to 1.12.0 ...");
if (isLogging(Logging.CHAT)) {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
st.execute("ALTER TABLE `lb-chat` MODIFY COLUMN `message` VARCHAR(256) NOT NULL");
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
}
config.set("version", "1.12.0");
}
if (configVersion.compareTo(new ComparableVersion("1.13.0")) < 0) {
logblock.getLogger().info("Updating tables to 1.13.0 ...");
try {
MaterialUpdater1_13 materialUpdater = new MaterialUpdater1_13(logblock);
logblock.getLogger().info("Convertig BlockId to BlockData. This can take a while ...");
final Connection conn = logblock.getConnection();
conn.setAutoCommit(false);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
logblock.getLogger().info("Processing world " + wcfg.world + "...");
logblock.getLogger().info("Processing block changes...");
boolean hadRow = true;
long rowsToConvert = 0;
long done = 0;
try {
ResultSet rs = st.executeQuery("SELECT count(*) as rowcount FROM `" + wcfg.table + "`");
if (rs.next()) {
rowsToConvert = rs.getLong(1);
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table);
}
rs.close();
PreparedStatement deleteStatement = conn.prepareStatement("DELETE FROM `" + wcfg.table + "` WHERE id = ?");
PreparedStatement insertStatement = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-blocks` (id, date, playerid, replaced, replacedData, type, typeData, x, y, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
while (hadRow) {
hadRow = false;
ResultSet entries = st.executeQuery("SELECT id, date, playerid, replaced, type, data, x, y, z FROM `" + wcfg.table + "` ORDER BY id ASC LIMIT " + BLOCKS_CONVERT_BATCH_SIZE);
while (entries.next()) {
hadRow = true;
int id = entries.getInt("id");
Timestamp date = entries.getTimestamp("date");
int playerid = entries.getInt("playerid");
int replaced = entries.getInt("replaced");
int type = entries.getInt("type");
int data = entries.getInt("data");
int x = entries.getInt("x");
int y = entries.getInt("y");
int z = entries.getInt("z");
if (data == 16) {
data = 0;
}
try {
String replacedBlockData = materialUpdater.getBlockData(replaced, data).getAsString();
String setBlockData = materialUpdater.getBlockData(type, data).getAsString();
int newReplacedId = MaterialConverter.getOrAddMaterialId(replacedBlockData);
int newReplacedData = MaterialConverter.getOrAddBlockStateId(replacedBlockData);
int newSetId = MaterialConverter.getOrAddMaterialId(setBlockData);
int newSetData = MaterialConverter.getOrAddBlockStateId(setBlockData);
insertStatement.setInt(1, id);
insertStatement.setTimestamp(2, date);
insertStatement.setInt(3, playerid);
insertStatement.setInt(4, newReplacedId);
insertStatement.setInt(5, newReplacedData);
insertStatement.setInt(6, newSetId);
insertStatement.setInt(7, newSetData);
insertStatement.setInt(8, x);
insertStatement.setInt(9, y);
insertStatement.setInt(10, z);
insertStatement.addBatch();
} catch (Exception e) {
logblock.getLogger().info("Exception in entry " + id + " (" + replaced + ":" + data + "->" + type + ":" + data + "): " + e.getMessage());
}
deleteStatement.setInt(1, id);
deleteStatement.addBatch();
done++;
}
entries.close();
int failedRows = 0;
if (hadRow) {
try {
insertStatement.executeBatch();
} catch (BatchUpdateException e) {
for (int result : e.getUpdateCounts()) {
if (result == Statement.EXECUTE_FAILED) {
failedRows++;
}
}
}
deleteStatement.executeBatch();
}
conn.commit();
logblock.getLogger().info("Done: " + done + "/" + rowsToConvert + " " + (failedRows > 0 ? "Duplicates: " + failedRows + " " : "") + "(" + (rowsToConvert > 0 ? (done * 100 / rowsToConvert) : 100) + "%)");
}
insertStatement.close();
deleteStatement.close();
} catch (SQLException e) {
logblock.getLogger().info("Could not convert " + wcfg.table + ": " + e.getMessage());
}
logblock.getLogger().info("Processing chests...");
rowsToConvert = 0;
done = 0;
try {
ResultSet rs = st.executeQuery("SELECT count(*) as rowcount FROM `" + wcfg.table + "-chest`");
if (rs.next()) {
rowsToConvert = rs.getLong(1);
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-chest");
}
rs.close();
PreparedStatement insertChestData = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-chestdata` (id, item, itemremove, itemtype) VALUES (?, ?, ?, ?)");
PreparedStatement deleteChest = conn.prepareStatement("DELETE FROM `" + wcfg.table + "-chest` WHERE id = ?");
while (true) {
rs = st.executeQuery("SELECT id, itemtype, itemamount, itemdata FROM `" + wcfg.table + "-chest` ORDER BY id ASC LIMIT " + OTHER_CONVERT_BATCH_SIZE);
boolean anyRow = false;
while (rs.next()) {
anyRow = true;
int id = rs.getInt("id");
int itemtype = rs.getInt("itemtype");
int itemdata = rs.getInt("itemdata");
int amount = rs.getInt("itemamount");
Material weaponMaterial = materialUpdater.getMaterial(itemtype, itemdata);
if (weaponMaterial == null) {
weaponMaterial = Material.AIR;
}
@SuppressWarnings("deprecation")
ItemStack stack = weaponMaterial.getMaxDurability() > 0 ? new ItemStack(weaponMaterial, Math.abs(amount), (short)itemdata) : new ItemStack(weaponMaterial, Math.abs(amount));
insertChestData.setInt(1, id);
insertChestData.setBytes(2, Utils.saveItemStack(stack));
insertChestData.setInt(3, amount >= 0 ? 0 : 1);
insertChestData.setInt(4, MaterialConverter.getOrAddMaterialId(weaponMaterial.getKey()));
insertChestData.addBatch();
deleteChest.setInt(1, id);
deleteChest.addBatch();
done++;
}
rs.close();
if (!anyRow) {
break;
}
int failedRows = 0;
try {
insertChestData.executeBatch();
} catch (BatchUpdateException e) {
for (int result : e.getUpdateCounts()) {
if (result == Statement.EXECUTE_FAILED) {
failedRows++;
}
}
}
deleteChest.executeBatch();
conn.commit();
logblock.getLogger().info("Done: " + done + "/" + rowsToConvert + " " + (failedRows > 0 ? "Duplicates: " + failedRows + " " : "") + "(" + (rowsToConvert > 0 ? (done * 100 / rowsToConvert) : 100) + "%)");
}
insertChestData.close();
deleteChest.close();
} catch (SQLException e) {
logblock.getLogger().info("Could not convert " + wcfg.table + "-chest: " + e.getMessage());
}
if (wcfg.isLogging(Logging.KILL)) {
logblock.getLogger().info("Processing kills...");
rowsToConvert = 0;
done = 0;
try {
ResultSet rs = st.executeQuery("SELECT count(*) as rowcount FROM `" + wcfg.table + "-kills`");
if (rs.next()) {
rowsToConvert = rs.getLong(1);
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-kills");
}
rs.close();
PreparedStatement updateWeaponStatement = conn.prepareStatement("UPDATE `" + wcfg.table + "-kills` SET weapon = ? WHERE id = ?");
for (int start = 0;; start += OTHER_CONVERT_BATCH_SIZE) {
rs = st.executeQuery("SELECT id, weapon FROM `" + wcfg.table + "-kills` ORDER BY id ASC LIMIT " + start + "," + OTHER_CONVERT_BATCH_SIZE);
boolean anyUpdate = false;
boolean anyRow = false;
while (rs.next()) {
anyRow = true;
int id = rs.getInt("id");
int weapon = rs.getInt("weapon");
Material weaponMaterial = materialUpdater.getMaterial(weapon, 0);
if (weaponMaterial == null) {
weaponMaterial = Material.AIR;
}
int newWeapon = MaterialConverter.getOrAddMaterialId(weaponMaterial.getKey());
if (newWeapon != weapon) {
anyUpdate = true;
updateWeaponStatement.setInt(1, newWeapon);
updateWeaponStatement.setInt(2, id);
updateWeaponStatement.addBatch();
}
done++;
}
rs.close();
if (anyUpdate) {
updateWeaponStatement.executeBatch();
conn.commit();
}
logblock.getLogger().info("Done: " + done + "/" + rowsToConvert + " (" + (rowsToConvert > 0 ? (done * 100 / rowsToConvert) : 100) + "%)");
if (!anyRow) {
break;
}
}
updateWeaponStatement.close();
} catch (SQLException e) {
logblock.getLogger().info("Could not convert " + wcfg.table + "-kills: " + e.getMessage());
}
}
}
st.close();
conn.close();
logblock.getLogger().info("Updating config to 1.13.0 ...");
config.set("logging.hiddenBlocks", materialUpdater.convertMaterials(config.getStringList("logging.hiddenBlocks")));
config.set("rollback.dontRollback", materialUpdater.convertMaterials(config.getStringList("rollback.dontRollback")));
config.set("rollback.replaceAnyway", materialUpdater.convertMaterials(config.getStringList("rollback.replaceAnyway")));
final ConfigurationSection toolsSec = config.getConfigurationSection("tools");
for (final String toolName : toolsSec.getKeys(false)) {
final ConfigurationSection tSec = toolsSec.getConfigurationSection(toolName);
tSec.set("item", materialUpdater.convertMaterial(tSec.getString("item", "OAK_LOG")));
}
} catch (final SQLException | IOException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.13.0");
}
if (configVersion.compareTo(new ComparableVersion("1.13.1")) < 0) {
logblock.getLogger().info("Updating tables to 1.13.1 ...");
try {
final Connection conn = logblock.getConnection();
conn.setAutoCommit(false);
final Statement st = conn.createStatement();
for (final WorldConfig wcfg : getLoggedWorlds()) {
logblock.getLogger().info("Processing world " + wcfg.world + "...");
ResultSet rsCol = st.executeQuery("SHOW COLUMNS FROM `" + wcfg.table + "-chestdata` LIKE 'itemtype'");
if (!rsCol.next()) {
st.execute("ALTER TABLE `" + wcfg.table + "-chestdata` ADD COLUMN `itemtype` SMALLINT NOT NULL DEFAULT '0'");
}
rsCol.close();
conn.commit();
if (wcfg.isLogging(Logging.SIGNTEXT)) {
long rowsToConvert = 0;
long done = 0;
try {
ResultSet rs = st.executeQuery("SELECT count(*) as rowcount FROM `" + wcfg.table + "-sign`");
if (rs.next()) {
rowsToConvert = rs.getLong(1);
logblock.getLogger().info("Converting " + rowsToConvert + " entries in " + wcfg.table + "-sign");
}
rs.close();
PreparedStatement insertSignState = conn.prepareStatement("INSERT INTO `" + wcfg.table + "-state` (id, replacedState, typeState) VALUES (?, ?, ?)");
PreparedStatement deleteSign = conn.prepareStatement("DELETE FROM `" + wcfg.table + "-sign` WHERE id = ?");
while (true) {
rs = st.executeQuery("SELECT id, signtext, replaced, type FROM `" + wcfg.table + "-sign` LEFT JOIN `" + wcfg.table + "-blocks` USING (id) ORDER BY id ASC LIMIT " + OTHER_CONVERT_BATCH_SIZE);
boolean anyRow = false;
while (rs.next()) {
anyRow = true;
int id = rs.getInt("id");
String signText = rs.getString("signtext");
int replaced = rs.getInt("replaced");
boolean nullBlock = rs.wasNull();
int type = rs.getInt("type");
if (!nullBlock && signText != null) {
String[] lines = signText.split("\0", 4);
byte[] bytes = Utils.serializeYamlConfiguration(BlockStateCodecSign.serialize(lines));
Material replacedMaterial = MaterialConverter.getBlockData(replaced, -1).getMaterial();
Material typeMaterial = MaterialConverter.getBlockData(type, -1).getMaterial();
boolean wasSign = replacedMaterial == Material.OAK_SIGN || replacedMaterial == Material.OAK_WALL_SIGN;
boolean isSign = typeMaterial == Material.OAK_SIGN || typeMaterial == Material.OAK_WALL_SIGN;
insertSignState.setInt(1, id);
insertSignState.setBytes(2, wasSign ? bytes : null);
insertSignState.setBytes(3, isSign ? bytes : null);
insertSignState.addBatch();
}
deleteSign.setInt(1, id);
deleteSign.addBatch();
done++;
}
rs.close();
if (!anyRow) {
break;
}
int failedRows = 0;
try {
insertSignState.executeBatch();
} catch (BatchUpdateException e) {
for (int result : e.getUpdateCounts()) {
if (result == Statement.EXECUTE_FAILED) {
failedRows++;
}
}
}
deleteSign.executeBatch();
conn.commit();
logblock.getLogger().info("Done: " + done + "/" + rowsToConvert + " " + (failedRows > 0 ? "Duplicates: " + failedRows + " " : "") + "(" + (rowsToConvert > 0 ? (done * 100 / rowsToConvert) : 100) + "%)");
}
insertSignState.close();
deleteSign.close();
} catch (SQLException e) {
logblock.getLogger().info("Could not convert " + wcfg.table + "-sign: " + e.getMessage());
}
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
config.set("version", "1.13.1");
}
if (configVersion.compareTo(new ComparableVersion("1.13.2")) < 0) {
config.set("version", "1.13.2");
}
if (configVersion.compareTo(new ComparableVersion("1.14.0")) < 0) {
config.set("version", "1.14.0");
}
// this can always be checked
try {
final Connection conn = logblock.getConnection();
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
checkCharset("lb-players", "name", st, true);
if (isLogging(Logging.CHAT)) {
checkCharset("lb-chat", "message", st, true);
}
createIndexIfDoesNotExist("lb-materials", "name", "UNIQUE KEY `name` (`name`(150))", st, true);
createIndexIfDoesNotExist("lb-blockstates", "name", "UNIQUE KEY `name` (`name`(150))", st, true);
st.close();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
return false;
}
logblock.saveConfig();
return true;
}
void createIndexIfDoesNotExist(String table, String indexName, String definition, Statement st, boolean silent) throws SQLException {
final ResultSet rs = st.executeQuery("SHOW INDEX FROM `" + table + "` WHERE Key_name = '" + indexName + "'");
if (!rs.next()) {
st.execute("ALTER TABLE `" + table + "` ADD " + definition);
logblock.getLogger().info("Add index " + indexName + " to table " + table + ": Table modified");
} else if (!silent) {
logblock.getLogger().info("Add index " + indexName + " to table " + table + ": Already fine, skipping it");
}
rs.close();
}
void checkCharset(String table, String column, Statement st, boolean silent) throws SQLException {
final ResultSet rs = st.executeQuery("SHOW FULL COLUMNS FROM `" + table + "` WHERE field = '" + column + "'");
String charset = "utf8";
if (Config.mb4) {
charset = "utf8mb4";
}
if (rs.next() && !rs.getString("Collation").substring(0, charset.length()).equalsIgnoreCase(charset)) {
st.execute("ALTER TABLE `" + table + "` CONVERT TO CHARSET " + charset);
logblock.getLogger().info("Table " + table + " modified");
} else if (!silent) {
logblock.getLogger().info("Table " + table + " already fine, skipping it");
}
rs.close();
}
void checkTables() throws SQLException {
String charset = "utf8";
if (Config.mb4) {
charset = "utf8mb4";
}
final Connection conn = logblock.getConnection();
if (conn == null) {
throw new SQLException("No connection");
}
final Statement state = conn.createStatement();
final DatabaseMetaData dbm = conn.getMetaData();
conn.setAutoCommit(true);
createTable(dbm, state, "lb-players", "(playerid INT UNSIGNED NOT NULL AUTO_INCREMENT, UUID varchar(36) NOT NULL, playername varchar(32) NOT NULL, firstlogin DATETIME NOT NULL, lastlogin DATETIME NOT NULL, onlinetime INT UNSIGNED NOT NULL, ip varchar(255) NOT NULL, PRIMARY KEY (playerid), INDEX (UUID), INDEX (playername)) DEFAULT CHARSET " + charset);
// Players table must not be empty or inserts won't work - bug #492
final ResultSet rs = state.executeQuery("SELECT NULL FROM `lb-players` LIMIT 1;");
if (!rs.next()) {
state.execute("INSERT IGNORE INTO `lb-players` (UUID,playername) VALUES ('log_dummy_record','dummy_record')");
}
if (isLogging(Logging.CHAT)) {
createTable(dbm, state, "lb-chat", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, message VARCHAR(256) NOT NULL, PRIMARY KEY (id), KEY playerid (playerid), FULLTEXT message (message)) DEFAULT CHARSET " + charset);
}
createTable(dbm, state, "lb-materials", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset);
createTable(dbm, state, "lb-blockstates", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset);
createTable(dbm, state, "lb-entitytypes", "(id INT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY (id)) DEFAULT CHARSET " + charset);
for (final WorldConfig wcfg : getLoggedWorlds()) {
createTable(dbm, state, wcfg.table + "-blocks", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, replaced SMALLINT UNSIGNED NOT NULL, replacedData SMALLINT NOT NULL, type SMALLINT UNSIGNED NOT NULL, typeData SMALLINT NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT UNSIGNED NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
createTable(dbm, state, wcfg.table + "-chestdata", "(id INT UNSIGNED NOT NULL, item MEDIUMBLOB, itemremove TINYINT, itemtype SMALLINT NOT NULL DEFAULT '0', PRIMARY KEY (id))");
createTable(dbm, state, wcfg.table + "-state", "(id INT UNSIGNED NOT NULL, replacedState MEDIUMBLOB NULL, typeState MEDIUMBLOB NULL, PRIMARY KEY (id))");
if (wcfg.isLogging(Logging.KILL)) {
createTable(dbm, state, wcfg.table + "-kills", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, killer INT UNSIGNED, victim INT UNSIGNED NOT NULL, weapon SMALLINT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, PRIMARY KEY (id))");
}
createTable(dbm, state, wcfg.table + "-entityids", "(entityid INT UNSIGNED NOT NULL AUTO_INCREMENT, entityuuid VARCHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (entityid), UNIQUE KEY (entityuuid))");
createTable(dbm, state, wcfg.table + "-entities", "(id INT UNSIGNED NOT NULL AUTO_INCREMENT, date DATETIME NOT NULL, playerid INT UNSIGNED NOT NULL, entityid INT UNSIGNED NOT NULL, entitytypeid INT UNSIGNED NOT NULL, x MEDIUMINT NOT NULL, y SMALLINT NOT NULL, z MEDIUMINT NOT NULL, action TINYINT UNSIGNED NOT NULL, data MEDIUMBLOB NULL, PRIMARY KEY (id), KEY coords (x, z, y), KEY date (date), KEY playerid (playerid))");
}
state.close();
conn.close();
}
private void createTable(DatabaseMetaData dbm, Statement state, String table, String query) throws SQLException {
if (!dbm.getTables(null, null, table, null).next()) {
logblock.getLogger().log(Level.INFO, "Creating table " + table + ".");
state.execute("CREATE TABLE `" + table + "` " + query);
if (!dbm.getTables(null, null, table, null).next()) {
throw new SQLException("Table " + table + " not found and failed to create");
}
}
}
/**
* Update materials that were renamed
*/
public void updateMaterialsPost1_13() {
final ConfigurationSection config = logblock.getConfig();
String previousMinecraftVersion = config.getString("previousMinecraftVersion");
if (previousMinecraftVersion == null) {
previousMinecraftVersion = "1.13";
}
ComparableVersion comparablePreviousMinecraftVersion = new ComparableVersion(previousMinecraftVersion);
String currentMinecraftVersion = logblock.getServer().getVersion();
currentMinecraftVersion = currentMinecraftVersion.substring(currentMinecraftVersion.indexOf("(MC: ") + 5);
currentMinecraftVersion = currentMinecraftVersion.substring(0, currentMinecraftVersion.indexOf(" "));
logblock.getLogger().info("[Updater] Current Minecraft Version: '" + currentMinecraftVersion + "'");
ComparableVersion comparableCurrentMinecraftVersion = new ComparableVersion(currentMinecraftVersion);
if (comparablePreviousMinecraftVersion.compareTo("1.14") < 0 && comparableCurrentMinecraftVersion.compareTo("1.14") >= 0) {
logblock.getLogger().info("[Updater] Upgrading Materials to 1.14");
renameMaterial("minecraft:sign", "minecraft:oak_sign", true);
renameMaterial("minecraft:wall_sign", "minecraft:oak_wall_sign", true);
renameMaterial("minecraft:stone_slab", "minecraft:smooth_stone_slab", false);
renameMaterial("minecraft:rose_red", "minecraft:red_dye", true);
renameMaterial("minecraft:dandelion_yellow", "minecraft:yellow_dye", true);
renameMaterial("minecraft:cactus_green", "minecraft:green_dye", true);
}
config.set("previousMinecraftVersion", currentMinecraftVersion);
logblock.saveConfig();
}
private void renameMaterial(String oldName, String newName, boolean mergeOnCollision) {
logblock.getLogger().info("[Updater] Renaming " + oldName + " to " + newName);
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(false);
PreparedStatement stSelectMaterial = conn.prepareStatement("SELECT id FROM `lb-materials` WHERE name = ?");
stSelectMaterial.setString(1, oldName);
ResultSet rs = stSelectMaterial.executeQuery();
if (!rs.next()) {
logblock.getLogger().info("[Updater] Skipped because " + oldName + " does not exist..");
} else {
int oldId = rs.getInt(1);
stSelectMaterial.setString(1, newName);
rs = stSelectMaterial.executeQuery();
if (rs.next()) {
int newId = rs.getInt(1);
if (!mergeOnCollision) {
logblock.getLogger().info("[Updater] Skipped because " + newName + " already exists..");
} else {
Statement st = conn.createStatement();
int rows = 0;
for (final WorldConfig wcfg : getLoggedWorlds()) {
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET replaced = " + newId + " WHERE replaced = " + oldId);
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-blocks` SET type = " + newId + " WHERE type = " + oldId);
rows += st.executeUpdate("UPDATE `" + wcfg.table + "-chestdata` SET itemtype = " + newId + " WHERE itemtype = " + oldId);
}
st.execute("DELETE FROM `lb-materials` WHERE id = " + oldId);
st.close();
logblock.getLogger().info("[Updater] Successfully merged " + rows + " entries..");
}
} else {
PreparedStatement stRenameMaterial = conn.prepareStatement("UPDATE `lb-materials` SET name = ? WHERE id = ?");
stRenameMaterial.setString(1, newName);
stRenameMaterial.setInt(2, oldId);
if (stRenameMaterial.executeUpdate() > 0) {
logblock.getLogger().info("[Updater] Successfully renamed..");
}
stRenameMaterial.close();
}
}
stSelectMaterial.close();
conn.commit();
conn.close();
} catch (final SQLException ex) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: " + ex.getMessage(), ex);
}
}
public static class PlayerCountChecker implements Runnable {
private LogBlock logblock;
public PlayerCountChecker(LogBlock logblock) {
this.logblock = logblock;
}
@Override
public void run() {
final Connection conn = logblock.getConnection();
try {
conn.setAutoCommit(true);
final Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT auto_increment FROM information_schema.columns AS col join information_schema.tables AS tab ON (col.table_schema=tab.table_schema AND col.table_name=tab.table_name) WHERE col.table_name = 'lb-players' AND col.column_name = 'playerid' AND col.data_type = 'smallint' AND col.table_schema = DATABASE() AND auto_increment > 65000;");
if (rs.next()) {
for (int i = 0; i < 6; i++) {
logblock.getLogger().warning("Your server reached 65000 players. You should soon update your database table schema - see FAQ: https://github.com/LogBlock/LogBlock/wiki/FAQ#logblock-your-server-reached-65000-players-");
}
}
st.close();
conn.close();
} catch (final SQLException ex) {
if (logblock.isCompletelyEnabled()) {
logblock.getLogger().log(Level.SEVERE, "[Updater] Error: ", ex);
}
}
}
}
public static class MaterialUpdater1_13 {
BlockData[][] blockDataMapping;
Material[][] itemMapping = new Material[10][];
public MaterialUpdater1_13(LogBlock plugin) throws IOException {
blockDataMapping = new BlockData[256][16];
try (JarFile file = new JarFile(plugin.getFile())) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(file.getInputStream(file.getJarEntry("blockdata.txt"))), "UTF-8"));
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
int splitter1 = line.indexOf(":");
int splitter2 = line.indexOf(",");
if (splitter1 >= 0 && splitter2 >= 0) {
int blockid = Integer.parseInt(line.substring(0, splitter1));
int blockdata = Integer.parseInt(line.substring(splitter1 + 1, splitter2));
BlockData newBlockData = Bukkit.createBlockData(line.substring(splitter2 + 1));
if (blockdata == 0) {
for (int i = 0; i < 16; i++) {
if (blockDataMapping[blockid][i] == null) {
blockDataMapping[blockid][i] = newBlockData;
}
}
} else {
blockDataMapping[blockid][blockdata] = newBlockData;
}
}
}
reader.close();
HashMap<String, Material> materialKeysToMaterial = new HashMap<>();
for (Material material : Material.values()) {
materialKeysToMaterial.put(material.getKey().toString(), material);
}
reader = new BufferedReader(new InputStreamReader(new BufferedInputStream(file.getInputStream(file.getJarEntry("itemdata.txt"))), "UTF-8"));
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
int splitter1 = line.indexOf(":");
int splitter2 = line.indexOf(",");
if (splitter1 >= 0 && splitter2 >= 0) {
int itemid = Integer.parseInt(line.substring(0, splitter1));
int itemdata = Integer.parseInt(line.substring(splitter1 + 1, splitter2));
Material newMaterial = materialKeysToMaterial.get(line.substring(splitter2 + 1));
if (newMaterial == null) {
throw new IOException("Unknown item: " + line.substring(splitter2 + 1));
}
if (itemid >= itemMapping.length) {
itemMapping = Arrays.copyOf(itemMapping, Math.max(itemMapping.length * 3 / 2, itemid + 1));
}