1515import me .nik .combatplus .listeners .FishingRodKnockback ;
1616import me .nik .combatplus .listeners .GoldenApple ;
1717import me .nik .combatplus .listeners .GuiListener ;
18- import me .nik .combatplus .listeners .ItemFrameRotate ;
18+ import me .nik .combatplus .listeners .HealthBar ;
1919import me .nik .combatplus .listeners .Offhand ;
2020import me .nik .combatplus .listeners .PlayerRegen ;
2121import me .nik .combatplus .listeners .fixes .Projectiles ;
2222import me .nik .combatplus .managers .MsgType ;
23+ import me .nik .combatplus .managers .commentedfiles .CommentedFileConfiguration ;
2324import me .nik .combatplus .utils .ACManager ;
2425import me .nik .combatplus .utils .CustomRecipes ;
2526import me .nik .combatplus .utils .MiscUtils ;
3132import org .bukkit .ChatColor ;
3233import org .bukkit .attribute .Attribute ;
3334import org .bukkit .attribute .AttributeInstance ;
34- import org .bukkit .configuration .file .FileConfiguration ;
3535import org .bukkit .event .Listener ;
3636import org .bukkit .plugin .java .JavaPlugin ;
3737import org .bukkit .scheduler .BukkitTask ;
@@ -41,6 +41,7 @@ public final class CombatPlus extends JavaPlugin {
4141 private static CombatPlus instance ;
4242
4343 private Config config ;
44+
4445 private Lang lang ;
4546
4647 public static CombatPlus getInstance () {
@@ -53,8 +54,7 @@ public void onDisable() {
5354 setDefaultStats ();
5455
5556 //Reload Files
56- config .reload ();
57- config .save ();
57+ config .reset ();
5858 lang .reload ();
5959 lang .save ();
6060
@@ -66,7 +66,8 @@ public void onDisable() {
6666 public void onEnable () {
6767 instance = this ;
6868 this .lang = new Lang ();
69- this .config = new Config ();
69+
70+ this .config = new Config (this );
7071
7172 //Load Files
7273 loadFiles ();
@@ -105,41 +106,27 @@ public void onEnable() {
105106 new ACManager ().hookMatrixAC ();
106107 }
107108
108- @ Override
109- public FileConfiguration getConfig () {
110- return config .get ();
109+ public CommentedFileConfiguration getConfiguration () {
110+ return config .getConfig ();
111111 }
112112
113113 public Lang getLang () {
114114 return lang ;
115115 }
116116
117- @ Override
118- public void saveConfig () {
119- config .save ();
120- }
121-
122- @ Override
123- public void reloadConfig () {
124- config .reload ();
125- }
126-
127117 /**
128118 * Load all the built-in files
129119 */
130120 private void loadFiles () {
131- config .setup (this );
132- config .addDefaults ();
133- config .get ().options ().copyDefaults (true );
134- config .save ();
121+ config .setup ();
135122 lang .setup (this );
136123 lang .addDefaults ();
137124 lang .get ().options ().copyDefaults (true );
138125 lang .save ();
139126 }
140127
141128 private void checkForUpdates () {
142- if (isEnabled ( "settings.check_for_updates" )) {
129+ if (Config . Setting . CHECK_FOR_UPDATES . getBoolean ( )) {
143130 BukkitTask updateChecker = new UpdateChecker (this ).runTaskAsynchronously (this );
144131 } else {
145132 consoleMessage (MsgType .CONSOLE_UPDATE_DISABLED .getMessage ());
@@ -151,11 +138,11 @@ private void checkForUpdates() {
151138 */
152139 private void setDefaultStats () {
153140 if (serverVersion ("1.8" )) return ;
154- Bukkit .getOnlinePlayers ().forEach (player -> {
155- final double defaultHealth = config . get (). getDouble ("advanced.settings.base_player_health" );
141+ this . getServer () .getOnlinePlayers ().forEach (player -> {
142+ final double defaultHealth = Config . Setting . ADV_BASE_HEALTH . getDouble ();
156143 final AttributeInstance playerMaxHealth = player .getAttribute (Attribute .GENERIC_MAX_HEALTH );
157144 playerMaxHealth .setBaseValue (defaultHealth );
158- final double defaultAttSpd = config . get (). getDouble ("advanced.settings.new_pvp.attack_speed" );
145+ final double defaultAttSpd = Config . Setting . ADV_NEW_ATTACK_SPEED . getDouble ();
159146 final AttributeInstance playerAttSpeed = player .getAttribute (Attribute .GENERIC_ATTACK_SPEED );
160147 playerAttSpeed .setBaseValue (defaultAttSpd );
161148 player .saveData ();
@@ -168,17 +155,17 @@ private void setDefaultStats() {
168155 */
169156 private void loadStats () {
170157 if (serverVersion ("1.8" )) return ;
171- SetAttackSpeed setAttackSpeed = new SetAttackSpeed (this );
172- ResetStats resetStats = new ResetStats (this );
173- SetCustomHealth setCustomHealth = new SetCustomHealth (this );
158+ SetAttackSpeed setAttackSpeed = new SetAttackSpeed ();
159+ ResetStats resetStats = new ResetStats ();
160+ SetCustomHealth setCustomHealth = new SetCustomHealth ();
174161
175- if (isEnabled ( "combat.settings.old_pvp" )) {
162+ if (Config . Setting . OLD_PVP . getBoolean ( )) {
176163 this .getServer ().getOnlinePlayers ().forEach (setAttackSpeed ::setAttackSpd );
177164 } else {
178165 this .getServer ().getOnlinePlayers ().forEach (resetStats ::resetAttackSpeed );
179166 }
180167
181- if (isEnabled ( "custom.player_health.enabled" )) {
168+ if (Config . Setting . CUSTOM_PLAYER_HEALTH_ENABLED . getBoolean ( )) {
182169 this .getServer ().getOnlinePlayers ().forEach (setCustomHealth ::setHealth );
183170 } else {
184171 this .getServer ().getOnlinePlayers ().forEach (resetStats ::resetMaxHealth );
@@ -191,50 +178,50 @@ private void loadStats() {
191178 private void initialize () {
192179 consoleMessage (MsgType .CONSOLE_INITIALIZE .getMessage ());
193180
194- if (isEnabled ( "combat.settings.old_pvp" ) || isEnabled ( "custom.player_health.enabled" )) {
195- registerEvent (new AttributesSet (this ));
181+ if (Config . Setting . OLD_PVP . getBoolean ( ) || Config . Setting . CUSTOM_PLAYER_HEALTH_ENABLED . getBoolean ( )) {
182+ registerEvent (new AttributesSet ());
196183 }
197- if (isEnabled ( "combat.settings.old_weapon_damage" ) || isEnabled ( "combat.settings.old_tool_damage" ) || isEnabled ( "combat.settings.disable_sweep_attacks.enabled" )) {
198- registerEvent (new DamageModifiers (this ));
184+ if (Config . Setting . OLD_WEAPON_DAMAGE . getBoolean ( ) || Config . Setting . OLD_TOOL_DAMAGE . getBoolean ( ) || Config . Setting . DISABLE_SWEEP_ENABLED . getBoolean ( )) {
185+ registerEvent (new DamageModifiers ());
199186 }
200- if (isEnabled ( "combat.settings.disable_arrow_boost" )) {
201- registerEvent (new BowBoost (this ));
187+ if (Config . Setting . DISABLE_ARROW_BOOST . getBoolean ( )) {
188+ registerEvent (new BowBoost ());
202189 }
203- if (isEnabled ( "combat.settings.old_player_regen" )) {
190+ if (Config . Setting . OLD_REGEN . getBoolean ( )) {
204191 registerEvent (new PlayerRegen (this ));
205192 }
206- if (isEnabled ("disabled_items.enabled" )) {
207- registerEvent (new DisabledItems (this ));
208- }
209- if (isEnabled ("disable_item_frame_rotation.enabled" )) {
210- registerEvent (new ItemFrameRotate (this ));
193+ if (Config .Setting .DISABLED_ITEMS_ENABLED .getBoolean ()) {
194+ registerEvent (new DisabledItems ());
211195 }
212- if (isEnabled ( "disable_offhand.enabled" )) {
213- registerEvent (new Offhand (this ));
196+ if (Config . Setting . DISABLE_OFFHAND_ENABLED . getBoolean ( )) {
197+ registerEvent (new Offhand ());
214198 }
215- if (isEnabled ( "fixes.projectile_fixer" )) {
199+ if (Config . Setting . FIX_PROJECTILES . getBoolean ( )) {
216200 registerEvent (new Projectiles ());
217201 }
218- if (isEnabled ( "golden_apple_cooldown.golden_apple.enabled" )) {
202+ if (Config . Setting . COOLDOWN_GOLDEN_APPLE_ENABLED . getBoolean ( )) {
219203 registerEvent (new GoldenApple (this ));
220204 }
221- if (isEnabled ( "golden_apple_cooldown.enchanted_golden_apple.enabled" )) {
205+ if (Config . Setting . COOLDOWN_ENCHANTED_APPLE_ENABLED . getBoolean ( )) {
222206 registerEvent (new EnchantedGoldenApple (this ));
223207 }
224- if (isEnabled ( "enderpearl_cooldown.enabled" )) {
208+ if (Config . Setting . ENDERPEARL_ENABLED . getBoolean ( )) {
225209 registerEvent (new Enderpearl (this ));
226210 }
227- if (isEnabled ( "recipes.enchanted_golden_apple" )) {
211+ if (Config . Setting . ENCHANTED_APPLE_CRAFTING . getBoolean ( )) {
228212 try {
229213 this .getServer ().addRecipe (new CustomRecipes (this ).enchantedGoldenAppleRecipe ());
230214 } catch (Exception ignored ) {
231215 }
232216 }
233- if (isEnabled ( "knockback.fishing_rod.enabled" )) {
234- registerEvent (new FishingRodKnockback (this ));
217+ if (Config . Setting . FISHING_ROD_ENABLED . getBoolean ( )) {
218+ registerEvent (new FishingRodKnockback ());
235219 }
236- if (isEnabled ("combat.settings.sword_blocking.enabled" )) {
237- registerEvent (new Blocking (this ));
220+ if (Config .Setting .SWORD_BLOCKING_ENABLED .getBoolean ()) {
221+ registerEvent (new Blocking ());
222+ }
223+ if (Config .Setting .HEALTHBAR_ENABLED .getBoolean ()) {
224+ registerEvent (new HealthBar ());
238225 }
239226 //GUI Listener (Do not remove this, idiot nik)
240227 registerEvent (new GuiListener ());
@@ -245,50 +232,37 @@ private void initialize() {
245232 */
246233 private void checkSupported () {
247234 if (serverVersion ("1.8" )) {
248- setFalse ("combat.settings.old_pvp" );
249- setFalse ("combat.settings.old_weapon_damage" );
250- setFalse ("combat.settings.old_tool_damage" );
251- setFalse ("combat.settings.old_sharpness" );
252- setFalse ("combat.settings.disable_sweep_attacks.enabled" );
253- setFalse ("combat.settings.old_player_regen" );
254- setFalse ("custom.player_health.enabled" );
255- setFalse ("disable_offhand.enabled" );
256- setFalse ("recipes.enchanted_golden_apple" );
257- setFalse ("knockback.fishing_rod.enabled" );
258- setFalse ("golden_apple_cooldown.golden_apple.actionbar" );
259- setFalse ("golden_apple_cooldown.enchanted_golden_apple.actionbar" );
260- setFalse ("enderpearl_cooldown.actionbar" );
261- setFalse ("combat.settings.sword_blocking.enabled" );
262- config .save ();
263- config .reload ();
264- consoleMessage (MsgType .CONSOLE_UNSUPPORTED_VERSION .getMessage ());
265- } else if (serverVersion ("1.9" )) {
266- setFalse ("combat.settings.disable_sweep_attacks.enabled" );
267- setFalse ("recipes.enchanted_golden_apple" );
268- setFalse ("knockback.fishing_rod.enabled" );
269- config .save ();
270- config .reload ();
235+ setFalse (Config .Setting .OLD_PVP .getKey ());
236+ setFalse (Config .Setting .OLD_WEAPON_DAMAGE .getKey ());
237+ setFalse (Config .Setting .OLD_TOOL_DAMAGE .getKey ());
238+ setFalse (Config .Setting .OLD_SHARPNESS .getKey ());
239+ setFalse (Config .Setting .DISABLE_SWEEP_ENABLED .getKey ());
240+ setFalse (Config .Setting .OLD_REGEN .getKey ());
241+ setFalse (Config .Setting .CUSTOM_PLAYER_HEALTH_ENABLED .getKey ());
242+ setFalse (Config .Setting .DISABLE_OFFHAND_ENABLED .getKey ());
243+ setFalse (Config .Setting .ENCHANTED_APPLE_CRAFTING .getKey ());
244+ setFalse (Config .Setting .FISHING_ROD_ENABLED .getKey ());
245+ setFalse (Config .Setting .COOLDOWN_GOLDEN_APPLE_ACTIONBAR .getKey ());
246+ setFalse (Config .Setting .COOLDOWN_ENCHANTED_APPLE_ACTIONBAR .getKey ());
247+ setFalse (Config .Setting .ENDERPEARL_ACTIONBAR .getKey ());
248+ setFalse (Config .Setting .SWORD_BLOCKING_ENABLED .getKey ());
249+ setFalse (Config .Setting .HEALTHBAR_ENABLED .getKey ());
250+ getConfiguration ().save ();
251+ getConfiguration ().reloadConfig ();
271252 consoleMessage (MsgType .CONSOLE_UNSUPPORTED_VERSION .getMessage ());
272- consoleMessage (MsgType .CONSOLE_UNSUPPORTED_SWEEP_ATTACK .getMessage ());
273- } else if (serverVersion ("1.10" )) {
274- setFalse ("combat.settings.disable_sweep_attacks.enabled" );
275- setFalse ("recipes.enchanted_golden_apple" );
276- setFalse ("knockback.fishing_rod.enabled" );
277- config .save ();
278- config .reload ();
253+ } else if (serverVersion ("1.9" ) || serverVersion ("1.10" )) {
254+ setFalse (Config .Setting .DISABLE_SWEEP_ENABLED .getKey ());
255+ setFalse (Config .Setting .ENCHANTED_APPLE_CRAFTING .getKey ());
256+ setFalse (Config .Setting .FISHING_ROD_ENABLED .getKey ());
257+ getConfiguration ().save ();
258+ getConfiguration ().reloadConfig ();
279259 consoleMessage (MsgType .CONSOLE_UNSUPPORTED_VERSION .getMessage ());
280260 consoleMessage (MsgType .CONSOLE_UNSUPPORTED_SWEEP_ATTACK .getMessage ());
281- } else if (serverVersion ("1.11" )) {
282- setFalse ("recipes.enchanted_golden_apple" );
283- setFalse ("knockback.fishing_rod.enabled" );
284- config .save ();
285- config .reload ();
286- consoleMessage (MsgType .CONSOLE_UNSUPPORTED_VERSION .getMessage ());
287- } else if (serverVersion ("1.12" )) {
288- setFalse ("recipes.enchanted_golden_apple" );
289- setFalse ("knockback.fishing_rod.enabled" );
290- config .save ();
291- config .reload ();
261+ } else if (serverVersion ("1.11" ) || serverVersion ("1.12" )) {
262+ setFalse (Config .Setting .ENCHANTED_APPLE_CRAFTING .getKey ());
263+ setFalse (Config .Setting .FISHING_ROD_ENABLED .getKey ());
264+ getConfiguration ().save ();
265+ getConfiguration ().reloadConfig ();
292266 consoleMessage (MsgType .CONSOLE_UNSUPPORTED_VERSION .getMessage ());
293267 }
294268 }
@@ -310,25 +284,14 @@ public void registerEvent(Listener listener) {
310284 Bukkit .getServer ().getPluginManager ().registerEvents (listener , this );
311285 }
312286
313- /**
314- * @param path The path to the boolean
315- * @return Whether or not the config boolean is true
316- */
317- private boolean isEnabled (String path ) {
318- return config .get ().getBoolean (path );
319- }
320-
321- /**
322- * @param path Path to the boolean
323- */
324- private void setFalse (String path ) {
325- config .get ().set (path , false );
326- }
327-
328287 /**
329288 * @param message The console message to send to the Server (ChatColor Friendly)
330289 */
331290 public void consoleMessage (String message ) {
332291 this .getServer ().getConsoleSender ().sendMessage (message );
333292 }
334- }
293+
294+ private void setFalse (String path ) {
295+ getConfiguration ().set (path , false );
296+ }
297+ }
0 commit comments