33import org .bukkit .configuration .file .FileConfiguration ;
44import simplexity .simplenicks .SimpleNicks ;
55
6+ import java .util .logging .Logger ;
67import java .util .regex .Pattern ;
78import java .util .regex .PatternSyntaxException ;
89
@@ -12,16 +13,22 @@ public String getRegexString() {
1213 return regexString ;
1314 }
1415
16+ public String getNickPrefix () {
17+ return nickPrefix ;
18+ }
19+
1520 public enum SAVING_TYPE {PDC , FILE }
1621
1722 private static ConfigHandler instance ;
1823
24+ private final Logger logger = SimpleNicks .getSimpleNicksLogger ();
1925 private Pattern regex = Pattern .compile ("[A-Za-z0-9_]+" );
2026 private SAVING_TYPE savingType = SAVING_TYPE .FILE ;
2127 private int maxLength = 25 ;
2228 private int maxSaves = 5 ;
2329 private boolean tablistNick = false ;
2430 private String regexString = "[A-Za-z0-9_]+" ;
31+ private String nickPrefix ;
2532 private long usernameProtectionTime = 0 ;
2633
2734 private ConfigHandler () {
@@ -36,39 +43,30 @@ public static ConfigHandler getInstance() {
3643 public void reloadConfig () {
3744 SimpleNicks .getInstance ().reloadConfig ();
3845 LocaleHandler .getInstance ().loadLocale ();
46+ FileConfiguration config = SimpleNicks .getInstance ().getConfig ();
3947 // Check the validity of the regex.
4048 try {
41- String regexSetting = SimpleNicks . getInstance (). getConfig (). getString ("nickname-regex" );
49+ String regexSetting = config . getString ("nickname-regex" , "[A-Za-z0-9_]+ " );
4250 regexString = regexSetting ;
43- assert regexSetting != null ;
4451 assert !regexSetting .isBlank ();
4552 regex = Pattern .compile (regexSetting );
46- } catch (AssertionError | PatternSyntaxException e ) {
47- SimpleNicks . getSimpleNicksLogger () .severe (LocaleHandler .getInstance ().getInvalidConfigRegex ());
53+ } catch (PatternSyntaxException e ) {
54+ logger .severe (LocaleHandler .getInstance ().getInvalidConfigRegex ());
4855 }
4956 // Check validity of saving-type.
5057 try {
51- String savingTypeSetting = SimpleNicks .getInstance ().getConfig ().getString ("saving-type" );
52- assert savingTypeSetting != null ;
58+ String savingTypeSetting = config .getString ("saving-type" , "file" );
5359 savingType = SAVING_TYPE .valueOf (savingTypeSetting .toUpperCase ());
54- } catch (AssertionError | IllegalArgumentException e ) {
55- SimpleNicks . getInstance (). getLogger () .severe ("INVALID SAVING TYPE" );
60+ } catch (IllegalArgumentException e ) {
61+ logger .severe ("INVALID SAVING TYPE" );
5662 }
57- maxLength = SimpleNicks .getInstance ().getConfig ().getInt ("max-nickname-length" );
58- maxSaves = SimpleNicks .getInstance ().getConfig ().getInt ("max-saves" );
59- tablistNick = SimpleNicks .getInstance ().getConfig ().getBoolean ("tablist-nick" );
60- usernameProtectionTime = SimpleNicks .getInstance ().getConfig ().getLong ("username-protection" ) * 86400000 ;
63+ maxLength = config .getInt ("max-nickname-length" , 25 );
64+ maxSaves = config .getInt ("max-saves" , 5 );
65+ tablistNick = config .getBoolean ("tablist-nick" , false );
66+ usernameProtectionTime = config .getLong ("username-protection" , 30 ) * 86400000 ;
67+ nickPrefix = config .getString ("nickname-prefix" , "" );
6168 }
6269
63- public void setConfigDefaults () {
64- FileConfiguration config = SimpleNicks .getInstance ().getConfig ();
65- config .addDefault ("saving-type" , "file" );
66- config .addDefault ("max-nickname-length" , 25 );
67- config .addDefault ("max-saves" , 5 );
68- config .addDefault ("nickname-regex" , "[A-Za-z0-9_]+" );
69- config .addDefault ("tablist-nick" , false );
70- config .addDefault ("username-protection" , 30 );
71- }
7270
7371 public Pattern getRegex () {
7472 return regex ;
0 commit comments