@@ -15,9 +15,14 @@ public class Config {
1515
1616 private volatile static boolean configSetUp ;
1717 private volatile static int configParkourStartHeight ;
18+ private final static int configParkourStartHeightDefault = 100 ;
1819 private volatile static int configParkourLength ;
20+ private final static int configParkourLengthDefault = 10 ;
1921 private volatile static int configCostToLowerTheDifficulty ;
22+ private final static int configCostToLowerTheDifficultyDefault = 6 ;
2023 private volatile static int configTimeToDecideWhenRespawning ;
24+ private final static int configTimeToDecideWhenRespawningDefault = 10 ;
25+
2126 private volatile static Location configWaitingListPosition ;
2227
2328 private Config (){}
@@ -74,37 +79,46 @@ public void initializeConfig() {
7479 */
7580 public void cloneConfigToPlugin () {
7681 FileConfiguration config = Main .getPlugin ().getConfig ();
77- if (config .contains ("SetUp" )) {
78- setSetUp (config .getBoolean ("SetUp" ));
79- }
80- else {
81- setSetUp (false );
82- }
82+ handleCloneSetUp (config );
83+ handleCloneDatabase (config );
84+ handleCloneTablist (config );
85+ handleCloneCustomEnchants (config );
86+ }
87+
88+ private void handleCloneSetUp (FileConfiguration config ) {
89+ boolean setUp = true ;
8390 if (config .contains ("ParkourStartHeight" )) {
8491 setParkourStartHeight (config .getInt ("ParkourStartHeight" ));
8592 }
8693 else {
87- setParkourStartHeight (100 );
94+ setParkourStartHeight (configParkourStartHeightDefault );
95+ setUp = false ;
8896 }
8997 if (config .contains ("ParkourLength" )) {
9098 setParkourLength (config .getInt ("ParkourLength" ));
9199 }
92100 else {
93- setParkourLength (10 );
101+ setParkourLength (configParkourLengthDefault );
102+ setUp = false ;
94103 }
95104 if (config .contains ("CostToLowerTheDifficulty" )) {
96105 setCostToLowerTheDifficulty (config .getInt ("CostToLowerTheDifficulty" ));
97106 }
98107 else {
99- setCostToLowerTheDifficulty (6 );
108+ setCostToLowerTheDifficulty (configCostToLowerTheDifficultyDefault );
109+ setUp = false ;
100110 }
101111 if (config .contains ("TimeToDecideWhenRespawning" )) {
102112 setTimeToDecideWhenRespawning (config .getInt ("TimeToDecideWhenRespawning" ));
103113 }
104114 else {
105- setTimeToDecideWhenRespawning (10 );
115+ setTimeToDecideWhenRespawning (configTimeToDecideWhenRespawningDefault );
116+ setUp = false ;
106117 }
107- // Database
118+ configSetUp = setUp ;
119+ }
120+
121+ private void handleCloneDatabase (FileConfiguration config ) {
108122 if (!config .contains ("Database" )) {
109123 config .set ("Database.host" , "default" );
110124 config .set ("Database.port" , "default" );
@@ -115,7 +129,9 @@ public void cloneConfigToPlugin() {
115129 config .set ("Database.schema" , "public" );
116130 Main .getPlugin ().saveConfig ();
117131 }
118- //Tablist
132+ }
133+
134+ private void handleCloneTablist (FileConfiguration config ) {
119135 if (config .contains ("Tablist" )) {
120136 if (config .contains ("Tablist.ServerName" ) && config .get ("Tablist.ServerName" ) != null ) {
121137 Tablist .setServerName (config .getString ("Tablist.ServerName" ));
@@ -129,6 +145,31 @@ public void cloneConfigToPlugin() {
129145 }
130146 }
131147
148+ private void handleCloneCustomEnchants (FileConfiguration config ) {
149+ if (config .contains ("CustomEnchants" )) {
150+ boolean customEnchantBool ;
151+ for (CustomEnchantsEnum customEnchantsEnum : CustomEnchantsEnum .values () ) {
152+ try {
153+ customEnchantBool = config .getBoolean ("CustomEnchants." + customEnchantsEnum .name ());
154+ customEnchantsEnum .setEnabled (customEnchantBool );
155+ }
156+ catch (Exception e ) {
157+ Main .getMainLogger ().warning ("Setting value for custom enchantment " + customEnchantsEnum .name () + " failed. Falling back to default true value." );
158+ e .printStackTrace ();
159+ customEnchantsEnum .setEnabled (true );
160+ }
161+ }
162+ }
163+ else {
164+ config .createSection ("CustomEnchants" );
165+ for (CustomEnchantsEnum customEnchantsEnum : CustomEnchantsEnum .values () ) {
166+ config .set ("CustomEnchants." + customEnchantsEnum .name (), true );
167+ customEnchantsEnum .setEnabled (true );
168+ }
169+ Main .getPlugin ().saveConfig ();
170+ }
171+ }
172+
132173 public void cloneWaitingListLocationToPlugin (World world ) {
133174 if (world == null ) {
134175 Main .getMainLogger ().severe ("Ca not set waitingListLocation because world is null!" );
@@ -145,16 +186,6 @@ public void cloneWaitingListLocationToPlugin(World world) {
145186 }
146187 }
147188
148- /**
149- * Sets whether the plugin is set up or not.
150- * @param bool Whether the plugin is set up.
151- */
152- public synchronized void setSetUp (boolean bool ) {
153- configSetUp = bool ;
154- Main .getPlugin ().getConfig ().set ("SetUp" , bool );
155- Main .getPlugin ().saveConfig ();
156- }
157-
158189 /**
159190 * Sets the height at which the parkour minigame starts.
160191 * @param height The height at which the parkour minigame starts.
0 commit comments