14
14
import java .util .logging .Level ;
15
15
import java .util .logging .Logger ;
16
16
import net .ess3 .api .IEssentials ;
17
+ import org .bukkit .BanList ;
17
18
import org .bukkit .Bukkit ;
18
19
import org .bukkit .Location ;
19
20
import org .bukkit .World ;
@@ -24,6 +25,8 @@ public class EssentialsUpgrade
24
25
private final static Logger LOGGER = Logger .getLogger ("Essentials" );
25
26
private final transient IEssentials ess ;
26
27
private final transient EssentialsConf doneFile ;
28
+ private String banReason ;
29
+ private Long banTimeout ;
27
30
28
31
EssentialsUpgrade (final IEssentials essentials )
29
32
{
@@ -659,6 +662,75 @@ public static void uuidFileConvert(IEssentials ess, Boolean ignoreUFCache)
659
662
ess .getLogger ().info ("To rerun the conversion type /essentials uuidconvert" );
660
663
}
661
664
665
+ public void banFormatChange ()
666
+ {
667
+ if (doneFile .getBoolean ("banFormatChange" , false ))
668
+ {
669
+ return ;
670
+ }
671
+
672
+ ess .getLogger ().info ("Starting Essentials ban format conversion" );
673
+
674
+ final File userdir = new File (ess .getDataFolder (), "userdata" );
675
+ if (!userdir .exists ())
676
+ {
677
+ return ;
678
+ }
679
+ File [] playerFiles = userdir .listFiles ();
680
+
681
+ for (File pFile : playerFiles )
682
+ {
683
+ EssentialsConf conf = new EssentialsConf (pFile );
684
+ conf .load ();
685
+ try
686
+ {
687
+ banReason = conf .getConfigurationSection ("ban" ).getString ("reason" );
688
+ }
689
+ catch (NullPointerException n )
690
+ {
691
+ //No ban in userfile
692
+ banReason = "" ;
693
+ }
694
+
695
+ String playerName = conf .getString ("lastAccountName" );
696
+ if (!banReason .equals ("" ))
697
+ {
698
+ try
699
+ {
700
+ banTimeout = Long .parseLong (conf .getConfigurationSection ("ban" ).getString ("timeout" ));
701
+ }
702
+ catch (NumberFormatException n )
703
+ {
704
+ //No ban timeout set, or malformed timeout.
705
+ banTimeout = 0L ;
706
+ }
707
+ org .bukkit .OfflinePlayer player = ess .getServer ().getOfflinePlayer (playerName );
708
+ if (player .isBanned ())
709
+ {
710
+ updateBan (playerName , banReason , banTimeout );
711
+ }
712
+ }
713
+ conf .removeProperty ("ban" );
714
+ conf .save ();
715
+ }
716
+
717
+ doneFile .setProperty ("banFormatChange" , true );
718
+ doneFile .save ();
719
+ ess .getLogger ().info ("Ban format update complete." );
720
+ }
721
+
722
+ private void updateBan (String playerName , String banReason , Long banTimeout )
723
+ {
724
+ if (banTimeout == 0 )
725
+ {
726
+ Bukkit .getBanList (BanList .Type .NAME ).addBan (playerName , banReason , null , Console .NAME );
727
+ }
728
+ else
729
+ {
730
+ Bukkit .getBanList (BanList .Type .NAME ).addBan (playerName , banReason , new Date (banTimeout ), Console .NAME );
731
+ }
732
+ }
733
+
662
734
public void beforeSettings ()
663
735
{
664
736
if (!ess .getDataFolder ().exists ())
@@ -678,6 +750,7 @@ public void afterSettings()
678
750
updateSpawnsToNewSpawnsConfig ();
679
751
updateJailsToNewJailsConfig ();
680
752
uuidFileChange ();
753
+ banFormatChange ();
681
754
warnMetrics ();
682
755
}
683
756
}
0 commit comments