-
-
Notifications
You must be signed in to change notification settings - Fork 847
/
PlayerProfile.java
1205 lines (1135 loc) · 43.6 KB
/
PlayerProfile.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
/*
This file is part of mcMMO.
mcMMO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mcMMO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gmail.nossr50.datatypes;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.events.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
public class PlayerProfile
{
protected final Logger log = Logger.getLogger("Minecraft");
//HUD
private HUDType hud;
//MISC
private String party, invite;
//TOGGLES
private boolean loaded = false, partyhud = true, spoutcraft = false, filling = false, xpbarlocked = false, placedAnvil = false, partyChatMode = false, adminChatMode = false, godMode = false, greenTerraMode, partyChatOnly = false, greenTerraInformed = true, berserkInformed = true, skullSplitterInformed = true, gigaDrillBreakerInformed = true,
superBreakerInformed = true, blastMiningInformed = true, serratedStrikesInformed = true, treeFellerInformed = true, dead, abilityuse = true, treeFellerMode, superBreakerMode, gigaDrillBreakerMode,
serratedStrikesMode, hoePreparationMode = false, shovelPreparationMode = false, swordsPreparationMode = false, fistsPreparationMode = false, pickaxePreparationMode = false, axePreparationMode = false, skullSplitterMode, berserkMode;
//TIMESTAMPS
//ATS = (Time of) Activation Time Stamp
//DATS = (Time of) Deactivation Time Stamp
private int xpGainATS = 0, recentlyHurt = 0, respawnATS, hoePreparationATS, shovelPreparationATS, swordsPreparationATS, fistsPreparationATS, axePreparationATS, pickaxePreparationATS;
private SkillType lastgained = null, skillLock = null;
//MySQL STUFF
private int xpbarinc=0, lastlogin=0, userid = 0, bleedticks = 0;
private String playerName;
//Time to HashMap this shiz
HashMap<SkillType, Integer> skills = new HashMap<SkillType, Integer>(); //Skills and XP
HashMap<SkillType, Integer> skillsXp = new HashMap<SkillType, Integer>(); //Skills and XP
HashMap<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); //Skill ATS
String location = "plugins/mcMMO/FlatFileStuff/mcmmo.users";
public PlayerProfile(String name)
{
hud = LoadProperties.defaulthud;
//Setup the HashMap for ability DATS
for(AbilityType abilityType : AbilityType.values())
{
skillsDATS.put(abilityType, 0);
}
//Setup the HashMap for the skills
for(SkillType skillType : SkillType.values())
{
if(skillType != SkillType.ALL)
{
skills.put(skillType, 0);
skillsXp.put(skillType, 0);
}
}
playerName = name;
if (LoadProperties.useMySQL)
{
if(!loadMySQL()) {
addMySQLPlayer();
loadMySQL();//This is probably not needed anymore, could just delete
}
} else {
if(!load()) { addPlayer();}
}
lastlogin = ((Long) (System.currentTimeMillis()/1000)).intValue();
}
public PlayerProfile(String name, boolean addNew)
{
hud = LoadProperties.defaulthud;
//Setup the HashMap for ability DATS
for(AbilityType abilityType : AbilityType.values())
{
skillsDATS.put(abilityType, 0);
}
//Setup the HashMap for the skills
for(SkillType skillType : SkillType.values())
{
if(skillType != SkillType.ALL)
{
skills.put(skillType, 0);
skillsXp.put(skillType, 0);
}
}
playerName = name;
if (LoadProperties.useMySQL)
{
if(!loadMySQL() && addNew) {
addMySQLPlayer();
loadMySQL();//This is probably not needed anymore, could just delete
}
} else {
if(!load() && addNew) { addPlayer(); loaded = true; }
}
lastlogin = ((Long) (System.currentTimeMillis()/1000)).intValue();
}
public int getLastLogin()
{
return lastlogin;
}
public int getMySQLuserId()
{
return userid;
}
public boolean loadMySQL()
{
Integer id = 0;
id = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
if(id == 0)
return false;
this.userid = id;
if (id > 0) {
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.Read("SELECT hudtype FROM "+LoadProperties.MySQLtablePrefix+"huds WHERE user_id = " + id);
if(huds.get(1) == null)
{
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"huds (user_id) VALUES ("+id+")");
} else {
if(huds.get(1).get(0) != null)
{
for(HUDType x : HUDType.values())
{
if(x.toString().equals(huds.get(1).get(0)))
{
hud = x;
}
}
} else {
hud = LoadProperties.defaulthud;
}
}
HashMap<Integer, ArrayList<String>> users = mcMMO.database.Read("SELECT lastlogin, party FROM "+LoadProperties.MySQLtablePrefix+"users WHERE id = " + id);
//lastlogin = Integer.parseInt(users.get(1).get(0));
party = users.get(1).get(1);
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.Read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes FROM "+LoadProperties.MySQLtablePrefix+"cooldowns WHERE user_id = " + id);
/*
* I'm still learning MySQL, this is a fix for adding a new table
* its not pretty but it works
*/
if(cooldowns.get(1) == null)
{
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
}
else
{
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldowns.get(1).get(0)));
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldowns.get(1).get(1)));
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldowns.get(1).get(2)));
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(cooldowns.get(1).get(3)));
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(cooldowns.get(1).get(4)));
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(cooldowns.get(1).get(5)));
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldowns.get(1).get(6)));
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7)));
}
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.Read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"skills WHERE user_id = " + id);
skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0)));
skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1)));
skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2)));
skills.put(SkillType.WOODCUTTING, Integer.valueOf(stats.get(1).get(3)));
skills.put(SkillType.UNARMED, Integer.valueOf(stats.get(1).get(4)));
skills.put(SkillType.HERBALISM, Integer.valueOf(stats.get(1).get(5)));
skills.put(SkillType.EXCAVATION, Integer.valueOf(stats.get(1).get(6)));
skills.put(SkillType.ARCHERY, Integer.valueOf(stats.get(1).get(7)));
skills.put(SkillType.SWORDS, Integer.valueOf(stats.get(1).get(8)));
skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9)));
skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10)));
skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11)));
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.Read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+LoadProperties.MySQLtablePrefix+"experience WHERE user_id = " + id);
skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0)));
skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1)));
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2)));
skillsXp.put(SkillType.WOODCUTTING, Integer.valueOf(experience.get(1).get(3)));
skillsXp.put(SkillType.UNARMED, Integer.valueOf(experience.get(1).get(4)));
skillsXp.put(SkillType.HERBALISM, Integer.valueOf(experience.get(1).get(5)));
skillsXp.put(SkillType.EXCAVATION, Integer.valueOf(experience.get(1).get(6)));
skillsXp.put(SkillType.ARCHERY, Integer.valueOf(experience.get(1).get(7)));
skillsXp.put(SkillType.SWORDS, Integer.valueOf(experience.get(1).get(8)));
skillsXp.put(SkillType.AXES, Integer.valueOf(experience.get(1).get(9)));
skillsXp.put(SkillType.ACROBATICS, Integer.valueOf(experience.get(1).get(10)));
skillsXp.put(SkillType.FISHING, Integer.valueOf(experience.get(1).get(11)));
loaded = true;
return true;
}
else {
return false;
}
}
public void addMySQLPlayer() {
Integer id = 0;
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 +")");
id = mcMMO.database.GetInt("SELECT id FROM "+LoadProperties.MySQLtablePrefix+"users WHERE user = '" + playerName + "'");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"cooldowns (user_id) VALUES ("+id+")");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"skills (user_id) VALUES ("+id+")");
mcMMO.database.Write("INSERT INTO "+LoadProperties.MySQLtablePrefix+"experience (user_id) VALUES ("+id+")");
this.userid = id;
}
public boolean load()
{
try {
//Open the user file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
String line = "";
while((line = in.readLine()) != null)
{
//Find if the line contains the player we want.
String[] character = line.split(":");
if(!character[0].equals(playerName)){continue;}
//Get Mining
if(character.length > 1 && m.isInt(character[1]))
skills.put(SkillType.MINING, Integer.valueOf(character[1]));
//Party
if(character.length > 3)
party = character[3];
//Mining XP
if(character.length > 4 && m.isInt(character[4]))
skillsXp.put(SkillType.MINING, Integer.valueOf(character[4]));
if(character.length > 5 && m.isInt(character[5]))
skills.put(SkillType.WOODCUTTING, Integer.valueOf(character[5]));
if(character.length > 6 && m.isInt(character[6]))
skillsXp.put(SkillType.WOODCUTTING, Integer.valueOf(character[6]));
if(character.length > 7 && m.isInt(character[7]))
skills.put(SkillType.REPAIR, Integer.valueOf(character[7]));
if(character.length > 8 && m.isInt(character[8]))
skills.put(SkillType.UNARMED, Integer.valueOf(character[8]));
if(character.length > 9 && m.isInt(character[9]))
skills.put(SkillType.HERBALISM, Integer.valueOf(character[9]));
if(character.length > 10 && m.isInt(character[10]))
skills.put(SkillType.EXCAVATION, Integer.valueOf(character[10]));
if(character.length > 11 && m.isInt(character[11]))
skills.put(SkillType.ARCHERY, Integer.valueOf(character[11]));
if(character.length > 12 && m.isInt(character[12]))
skills.put(SkillType.SWORDS, Integer.valueOf(character[12]));
if(character.length > 13 && m.isInt(character[13]))
skills.put(SkillType.AXES, Integer.valueOf(character[13]));
if(character.length > 14 && m.isInt(character[14]))
skills.put(SkillType.ACROBATICS, Integer.valueOf(character[14]));
if(character.length > 15 && m.isInt(character[15]))
skillsXp.put(SkillType.REPAIR, Integer.valueOf(character[15]));
if(character.length > 16 && m.isInt(character[16]))
skillsXp.put(SkillType.UNARMED, Integer.valueOf(character[16]));
if(character.length > 17 && m.isInt(character[17]))
skillsXp.put(SkillType.HERBALISM, Integer.valueOf(character[17]));
if(character.length > 18 && m.isInt(character[18]))
skillsXp.put(SkillType.EXCAVATION, Integer.valueOf(character[18]));
if(character.length > 19 && m.isInt(character[19]))
skillsXp.put(SkillType.ARCHERY, Integer.valueOf(character[19]));
if(character.length > 20 && m.isInt(character[20]))
skillsXp.put(SkillType.SWORDS, Integer.valueOf(character[20]));
if(character.length > 21 && m.isInt(character[21]))
skillsXp.put(SkillType.AXES, Integer.valueOf(character[21]));
if(character.length > 22 && m.isInt(character[22]))
skillsXp.put(SkillType.ACROBATICS, Integer.valueOf(character[22]));
if(character.length > 24 && m.isInt(character[24]))
skills.put(SkillType.TAMING, Integer.valueOf(character[24]));
if(character.length > 25 && m.isInt(character[25]))
skillsXp.put(SkillType.TAMING, Integer.valueOf(character[25]));
if(character.length > 26)
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(character[26]));
if(character.length > 27)
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(character[27]));
if(character.length > 28)
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(character[28]));
if(character.length > 29)
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(character[29]));
if(character.length > 30)
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(character[30]));
if(character.length > 31)
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(character[31]));
if(character.length > 32)
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
if(character.length > 33)
{
for(HUDType x : HUDType.values())
{
if(x.toString().equalsIgnoreCase(character[33]))
{
hud = x;
}
}
}
if(character.length > 34)
skills.put(SkillType.FISHING, Integer.valueOf(character[34]));
if(character.length > 35)
skillsXp.put(SkillType.FISHING, Integer.valueOf(character[35]));
if(character.length > 36)
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(character[36]));
in.close();
loaded = true;
return true;
}
in.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while reading "
+ location + " (Are you sure you formatted it correctly?)", e);
}
return false;
}
public void save()
{
Long timestamp = System.currentTimeMillis()/1000; //Convert to seconds
// if we are using mysql save to database
if (LoadProperties.useMySQL)
{
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"huds SET "
+" hudtype = '"+hud.toString()+"' WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"users SET party = '"+this.party+"' WHERE id = " +this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"cooldowns SET "
+" mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER)
+", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER)
+", unarmed = " + skillsDATS.get(AbilityType.BERSERK)
+", herbalism = " + skillsDATS.get(AbilityType.GREEN_TERRA)
+", excavation = " + skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)
+", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES)
+", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER)
+", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING)
+" WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"skills SET "
+" taming = "+skills.get(SkillType.TAMING)
+", mining = "+skills.get(SkillType.MINING)
+", repair = "+skills.get(SkillType.REPAIR)
+", woodcutting = "+skills.get(SkillType.WOODCUTTING)
+", unarmed = "+skills.get(SkillType.UNARMED)
+", herbalism = "+skills.get(SkillType.HERBALISM)
+", excavation = "+skills.get(SkillType.EXCAVATION)
+", archery = " +skills.get(SkillType.ARCHERY)
+", swords = " +skills.get(SkillType.SWORDS)
+", axes = "+skills.get(SkillType.AXES)
+", acrobatics = "+skills.get(SkillType.ACROBATICS)
+", fishing = "+skills.get(SkillType.FISHING)
+" WHERE user_id = "+this.userid);
mcMMO.database.Write("UPDATE "+LoadProperties.MySQLtablePrefix+"experience SET "
+" taming = "+skillsXp.get(SkillType.TAMING)
+", mining = "+skillsXp.get(SkillType.MINING)
+", repair = "+skillsXp.get(SkillType.REPAIR)
+", woodcutting = "+skillsXp.get(SkillType.WOODCUTTING)
+", unarmed = "+skillsXp.get(SkillType.UNARMED)
+", herbalism = "+skillsXp.get(SkillType.HERBALISM)
+", excavation = "+skillsXp.get(SkillType.EXCAVATION)
+", archery = " +skillsXp.get(SkillType.ARCHERY)
+", swords = " +skillsXp.get(SkillType.SWORDS)
+", axes = "+skillsXp.get(SkillType.AXES)
+", acrobatics = "+skillsXp.get(SkillType.ACROBATICS)
+", fishing = "+skillsXp.get(SkillType.FISHING)
+" WHERE user_id = "+this.userid);
} else
{
// otherwise save to flatfile
try {
//Open the file
FileReader file = new FileReader(location);
BufferedReader in = new BufferedReader(file);
StringBuilder writer = new StringBuilder();
String line = "";
//While not at the end of the file
while((line = in.readLine()) != null)
{
//Read the line in and copy it to the output it's not the player
//we want to edit
if(!line.split(":")[0].equalsIgnoreCase(playerName))
{
writer.append(line).append("\r\n");
//Otherwise write the new player information
} else {
writer.append(playerName + ":");
writer.append(skills.get(SkillType.MINING) + ":");
writer.append("" + ":");
writer.append(party+":");
writer.append(skillsXp.get(SkillType.MINING) + ":");
writer.append(skills.get(SkillType.WOODCUTTING) + ":");
writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":");
writer.append(skills.get(SkillType.REPAIR) + ":");
writer.append(skills.get(SkillType.UNARMED) + ":");
writer.append(skills.get(SkillType.HERBALISM) + ":");
writer.append(skills.get(SkillType.EXCAVATION) + ":");
writer.append(skills.get(SkillType.ARCHERY) + ":");
writer.append(skills.get(SkillType.SWORDS) + ":");
writer.append(skills.get(SkillType.AXES) + ":");
writer.append(skills.get(SkillType.ACROBATICS) + ":");
writer.append(skillsXp.get(SkillType.REPAIR) + ":");
writer.append(skillsXp.get(SkillType.UNARMED) + ":");
writer.append(skillsXp.get(SkillType.HERBALISM) + ":");
writer.append(skillsXp.get(SkillType.EXCAVATION) + ":");
writer.append(skillsXp.get(SkillType.ARCHERY) + ":");
writer.append(skillsXp.get(SkillType.SWORDS) + ":");
writer.append(skillsXp.get(SkillType.AXES) + ":");
writer.append(skillsXp.get(SkillType.ACROBATICS) + ":");
writer.append(""+":");
writer.append(skills.get(SkillType.TAMING) + ":");
writer.append(skillsXp.get(SkillType.TAMING) + ":");
//Need to store the DATS of abilities nao
//Berserk, Gigadrillbreaker, Tree Feller, Green Terra, Serrated Strikes, Skull Splitter, Super Breaker
writer.append(String.valueOf(skillsDATS.get(AbilityType.BERSERK))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.TREE_FELLER))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.GREEN_TERRA))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER))+":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER))+":");
writer.append(hud.toString()+":");
writer.append(skills.get(SkillType.FISHING) + ":");
writer.append(skillsXp.get(SkillType.FISHING) + ":");
writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":");
writer.append("\r\n");
}
}
in.close();
//Write the new file
FileWriter out = new FileWriter(location);
out.write(writer.toString());
out.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
}
}
}
public void resetAllData()
{
//This will reset everything to default values and then save the information to FlatFile/MySQL
for(SkillType skillType : SkillType.values())
{
if(skillType == SkillType.ALL)
continue;
skills.put(skillType, 0);
skillsXp.put(skillType, 0);
}
for(AbilityType abilityType : AbilityType.values())
{
skillsDATS.put(abilityType, 0);
}
//Misc stuff
party = "";
save();
}
public void addPlayer()
{
try {
//Open the file to write the player
FileWriter file = new FileWriter(location, true);
BufferedWriter out = new BufferedWriter(file);
//Add the player to the end
out.append(playerName + ":");
out.append(0 + ":"); //mining
out.append(""+":");
out.append(party+":");
out.append(0+":"); //XP
out.append(0+":"); //woodcutting
out.append(0+":"); //woodCuttingXP
out.append(0+":"); //repair
out.append(0+":"); //unarmed
out.append(0+":"); //herbalism
out.append(0+":"); //excavation
out.append(0+":"); //archery
out.append(0+":"); //swords
out.append(0+":"); //axes
out.append(0+":"); //acrobatics
out.append(0+":"); //repairXP
out.append(0+":"); //unarmedXP
out.append(0+":"); //herbalismXP
out.append(0+":"); //excavationXP
out.append(0+":"); //archeryXP
out.append(0+":"); //swordsXP
out.append(0+":"); //axesXP
out.append(0+":"); //acrobaticsXP
out.append(""+":");
out.append(0+":"); //taming
out.append(0+":"); //tamingXP
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(0+":"); //DATS
out.append(LoadProperties.defaulthud.toString()+":");//HUD
out.append(0+":"); //Fishing
out.append(0+":"); //FishingXP
out.append(0+":"); //Blast Mining
//Add more in the same format as the line above
out.newLine();
out.close();
} catch (Exception e) {
log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e);
}
}
public void togglePartyHUD()
{
partyhud = !partyhud;
}
public boolean isLoaded()
{
return loaded;
}
public boolean getPartyHUD()
{
return partyhud;
}
public void toggleSpoutEnabled()
{
spoutcraft = !spoutcraft;
}
public boolean isFilling()
{
return filling;
}
public void toggleFilling()
{
filling = !filling;
}
public HUDType getHUDType()
{
return hud;
}
public void setHUDType(HUDType type)
{
hud = type;
save();
}
public boolean getXpBarLocked()
{
return xpbarlocked;
}
public void toggleXpBarLocked()
{
xpbarlocked = !xpbarlocked;
}
public int getXpBarInc()
{
return xpbarinc;
}
public void setXpBarInc(int newvalue)
{
xpbarinc = newvalue;
}
public void setSkillLock(SkillType newvalue)
{
skillLock = newvalue;
}
public SkillType getSkillLock()
{
return skillLock;
}
public void setLastGained(SkillType newvalue)
{
lastgained = newvalue;
}
public SkillType getLastGained()
{
return lastgained;
}
public boolean getAdminChatMode() {return adminChatMode;}
public boolean getPartyChatMode() {return partyChatMode;}
public boolean getGodMode() {return godMode;}
public void togglePlacedAnvil()
{
placedAnvil = !placedAnvil;
}
public Boolean getPlacedAnvil()
{
return placedAnvil;
}
public void toggleAdminChat()
{
adminChatMode = !adminChatMode;
}
public void toggleGodMode()
{
godMode = !godMode;
}
public void togglePartyChat()
{
partyChatMode = !partyChatMode;
}
public boolean isPlayer(String player)
{
return player.equals(Bukkit.getPlayer(playerName));
}
public boolean getPartyChatOnlyToggle(){return partyChatOnly;}
public void togglePartyChatOnly(){partyChatOnly = !partyChatOnly;}
public boolean getAbilityUse(){
return abilityuse;
}
public void toggleAbilityUse()
{
abilityuse = !abilityuse;
}
public void decreaseBleedTicks()
{
bleedticks--;
}
public Integer getBleedTicks(){
return bleedticks;
}
public void setBleedTicks(Integer newvalue){
bleedticks = newvalue;
//Cap maximum ticks at 10
if(bleedticks > 10)
bleedticks = 10;
}
public void addBleedTicks(Integer newvalue){
bleedticks+=newvalue;
//Cap maximum ticks at 10
if(bleedticks > 10)
bleedticks = 10;
}
/*
* EXPLOIT PREVENTION
*/
public long getRespawnATS() {return respawnATS;}
public void setRespawnATS(long newvalue) {respawnATS = (int) (newvalue/1000);}
/*
* HOE PREPARATION
*/
public boolean getHoePreparationMode(){
return hoePreparationMode;
}
public void setHoePreparationMode(boolean bool){
hoePreparationMode = bool;
}
public long getHoePreparationATS(){
return hoePreparationATS;
}
public void setHoePreparationATS(long newvalue){
hoePreparationATS = (int) (newvalue/1000);
}
/*
* SWORDS PREPARATION
*/
public boolean getSwordsPreparationMode(){
return swordsPreparationMode;
}
public void setSwordsPreparationMode(boolean bool){
swordsPreparationMode = bool;
}
public long getSwordsPreparationATS(){
return swordsPreparationATS;
}
public void setSwordsPreparationATS(long newvalue){
swordsPreparationATS = (int) (newvalue/1000);
}
/*
* SHOVEL PREPARATION
*/
public boolean getShovelPreparationMode(){
return shovelPreparationMode;
}
public void setShovelPreparationMode(boolean bool){
shovelPreparationMode = bool;
}
public long getShovelPreparationATS(){
return shovelPreparationATS;
}
public void setShovelPreparationATS(long newvalue){
shovelPreparationATS = (int) (newvalue/1000);
}
/*
* FISTS PREPARATION
*/
public boolean getFistsPreparationMode(){
return fistsPreparationMode;
}
public void setFistsPreparationMode(boolean bool){
fistsPreparationMode = bool;
}
public long getFistsPreparationATS(){
return fistsPreparationATS;
}
public void setFistsPreparationATS(long newvalue){
fistsPreparationATS = (int) (newvalue/1000);
}
/*
* AXE PREPARATION
*/
public boolean getAxePreparationMode(){
return axePreparationMode;
}
public void setAxePreparationMode(boolean bool){
axePreparationMode = bool;
}
public long getAxePreparationATS(){
return axePreparationATS;
}
public void setAxePreparationATS(long newvalue){
axePreparationATS = (int) (newvalue/1000);
}
/*
* PICKAXE PREPARATION
*/
public boolean getPickaxePreparationMode(){
return pickaxePreparationMode;
}
public void setPickaxePreparationMode(boolean bool){
pickaxePreparationMode = bool;
}
public long getPickaxePreparationATS(){
return pickaxePreparationATS;
}
public void setPickaxePreparationATS(long newvalue){
pickaxePreparationATS = (int) (newvalue/1000);
}
/*
* GREEN TERRA MODE
*/
public boolean getGreenTerraInformed() {return greenTerraInformed;}
public void setGreenTerraInformed(boolean bool){
greenTerraInformed = bool;
}
public boolean getGreenTerraMode(){
return greenTerraMode;
}
public void setGreenTerraMode(boolean bool){
greenTerraMode = bool;
}
/*
* BERSERK MODE
*/
public boolean getBerserkInformed() {return berserkInformed;}
public void setBerserkInformed(boolean bool){
berserkInformed = bool;
}
public boolean getBerserkMode(){
return berserkMode;
}
public void setBerserkMode(boolean bool){
berserkMode = bool;
}
/*
* SKULL SPLITTER
*/
public boolean getSkullSplitterInformed() {return skullSplitterInformed;}
public void setSkullSplitterInformed(boolean bool){
skullSplitterInformed = bool;
}
public boolean getSkullSplitterMode(){
return skullSplitterMode;
}
public void setSkullSplitterMode(boolean bool){
skullSplitterMode = bool;
}
/*
* SERRATED STRIKES
*/
public boolean getSerratedStrikesInformed() {return serratedStrikesInformed;}
public void setSerratedStrikesInformed(boolean bool){
serratedStrikesInformed = bool;
}
public boolean getSerratedStrikesMode(){
return serratedStrikesMode;
}
public void setSerratedStrikesMode(boolean bool){
serratedStrikesMode = bool;
}
/*
* GIGA DRILL BREAKER
*/
public boolean getGigaDrillBreakerInformed() {return gigaDrillBreakerInformed;}
public void setGigaDrillBreakerInformed(boolean bool){
gigaDrillBreakerInformed = bool;
}
public boolean getGigaDrillBreakerMode(){
return gigaDrillBreakerMode;
}
public void setGigaDrillBreakerMode(boolean bool){
gigaDrillBreakerMode = bool;
}
/*
* TREE FELLER STUFF
*/
public boolean getTreeFellerInformed() {return treeFellerInformed;}
public void setTreeFellerInformed(boolean bool){
treeFellerInformed = bool;
}
public boolean getTreeFellerMode(){
return treeFellerMode;
}
public void setTreeFellerMode(boolean bool){
treeFellerMode = bool;
}
/*
* MINING
*/
public boolean getSuperBreakerInformed() {return superBreakerInformed;}
public void setSuperBreakerInformed(boolean bool){
superBreakerInformed = bool;
}
public boolean getBlastMiningInformed() {return blastMiningInformed;}
public void setBlastMiningInformed(boolean bool){
blastMiningInformed = bool;
}
public boolean getSuperBreakerMode(){
return superBreakerMode;
}
public void setSuperBreakerMode(boolean bool){
superBreakerMode = bool;
}
public long getRecentlyHurt(){
return recentlyHurt;
}
public void setRecentlyHurt(long newvalue){
recentlyHurt = (int) (newvalue/1000);
}
public void skillUp(SkillType skillType, int newvalue)
{
skills.put(skillType, skills.get(skillType)+newvalue);
}
public Integer getSkillLevel(SkillType skillType)
{
return skills.get(skillType);
}
public Integer getSkillXpLevel(SkillType skillType)
{
return skillsXp.get(skillType);
}
public void resetSkillXp(SkillType skillType)
{
skills.put(skillType, 0);
}
public long getSkillDATS(AbilityType abilityType)
{
//Is this actually unused, or should it actually be returning the convertedBack variable?
//It *is* unused, I don't think I put this here so I'm going to comment it out - nossr50
//long convertedBack = skillsDATS.get(abilityType) * 1000;
return skillsDATS.get(abilityType);
}
public void setSkillDATS(AbilityType abilityType, long value)
{
int wearsOff = (int) (value * .001D);
skillsDATS.put(abilityType, wearsOff);
}
public void resetCooldowns()
{
for(AbilityType x : skillsDATS.keySet())
{
skillsDATS.put(x, 0);
}
}
/**
* Adds XP to the player, doesn't calculate for XP Rate
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXPOverrideNoBonus(SkillType skillType, int newvalue)
{
if(skillType == SkillType.ALL)
{
for(SkillType x : SkillType.values())
{
if(x == SkillType.ALL)
continue;
Bukkit.getPluginManager().callEvent(new McMMOPlayerXpGainEvent(Bukkit.getPlayer(playerName), x, newvalue));
skillsXp.put(x, skillsXp.get(x)+newvalue);
}
} else {
int xp = newvalue;
Bukkit.getPluginManager().callEvent(new McMMOPlayerXpGainEvent(Bukkit.getPlayer(playerName), skillType, xp));
skillsXp.put(skillType, skillsXp.get(skillType)+xp);
lastgained = skillType;
}
}
/**
* Adds XP to the player, this ignores skill modifiers
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXPOverride(SkillType skillType, int newvalue)
{
if(skillType == SkillType.ALL)
{
for(SkillType x : SkillType.values())
{
if(x == SkillType.ALL)
continue;
Bukkit.getPluginManager().callEvent(new McMMOPlayerXpGainEvent(Bukkit.getPlayer(playerName), x, newvalue));
skillsXp.put(x, skillsXp.get(x)+newvalue);
}
} else {
int xp = newvalue;
xp=xp*LoadProperties.xpGainMultiplier;
Bukkit.getPluginManager().callEvent(new McMMOPlayerXpGainEvent(Bukkit.getPlayer(playerName), skillType, xp));
skillsXp.put(skillType, skillsXp.get(skillType)+xp);
lastgained = skillType;
}
}
/**
* Adds XP to the player, this is affected by skill modifiers and xp rate
* @param skillType The skill to add XP to
* @param newvalue The amount of XP to add
*/
public void addXP(SkillType skillType, int newvalue, Player thisplayer)
{
if(System.currentTimeMillis() < ((xpGainATS*1000)+250) || thisplayer.getGameMode() == GameMode.CREATIVE)
return;
//Setup a timestamp of when xp was given
xpGainATS = (int) (System.currentTimeMillis()/1000);
double bonusModifier = 0;
//String leaderName = "";
if(inParty())
{
for(Player x : Party.getInstance().getPartyMembers(thisplayer))
{
if(x.isOnline() && !x.getName().equals(thisplayer.getName()) && Party.getInstance().isPartyLeader(x.getName(), this.getParty()))
{
//leaderName = x.getName();
if(m.isNear(thisplayer.getLocation(), x.getLocation(), 25))
{
PlayerProfile PartyLeader = Users.getProfile(x);
if(PartyLeader.getSkillLevel(skillType) >= this.getSkillLevel(skillType))
{
int leaderLevel = PartyLeader.getSkillLevel(skillType);
int difference = leaderLevel - this.getSkillLevel(skillType);
bonusModifier = (difference*0.75D)/100D;
}
}
}
}
}
if(skillType == SkillType.ALL)
{
for(SkillType x : SkillType.values())
{
if(x == SkillType.ALL)
continue;
Bukkit.getPluginManager().callEvent(new McMMOPlayerXpGainEvent(Bukkit.getPlayer(playerName), x, newvalue));
skillsXp.put(x, skillsXp.get(x)+newvalue);
}
} else {