55import me .nik .combatplus .files .Config ;
66import me .nik .combatplus .files .Lang ;
77import me .nik .combatplus .files .commentedfiles .CommentedFileConfiguration ;
8- import me .nik .combatplus .handlers .PapiHook ;
9- import me .nik .combatplus .handlers .UpdateChecker ;
108import me .nik .combatplus .listeners .GuiListener ;
11- import me .nik .combatplus .managers .CustomRecipes ;
129import me .nik .combatplus .managers .MsgType ;
10+ import me .nik .combatplus .managers .PapiHook ;
11+ import me .nik .combatplus .managers .UpdateChecker ;
1312import me .nik .combatplus .metrics .MetricsLite ;
1413import me .nik .combatplus .modules .Module ;
1514import me .nik .combatplus .modules .impl .Blocking ;
16- import me .nik .combatplus .modules .impl .BowBoost ;
1715import me .nik .combatplus .modules .impl .CombatLog ;
16+ import me .nik .combatplus .modules .impl .CustomAttackSpeed ;
1817import me .nik .combatplus .modules .impl .CustomHealth ;
18+ import me .nik .combatplus .modules .impl .CustomPlayerRegeneration ;
1919import me .nik .combatplus .modules .impl .DamageModifiers ;
20- import me .nik .combatplus .modules .impl .DisabledItems ;
21- import me .nik .combatplus .modules .impl .EnchantedGoldenApple ;
22- import me .nik .combatplus .modules .impl .Enderpearl ;
20+ import me .nik .combatplus .modules .impl .DisableBowBoost ;
21+ import me .nik .combatplus .modules .impl .DisableOffhand ;
22+ import me .nik .combatplus .modules .impl .EnchantedGoldenAppleCooldown ;
23+ import me .nik .combatplus .modules .impl .EnderpearlCooldown ;
2324import me .nik .combatplus .modules .impl .FishingRodKnockback ;
24- import me .nik .combatplus .modules .impl .GoldenApple ;
25+ import me .nik .combatplus .modules .impl .GoldenAppleCooldown ;
2526import me .nik .combatplus .modules .impl .HealthBar ;
26- import me .nik .combatplus .modules .impl .Offhand ;
27- import me .nik .combatplus .modules .impl .OldPvP ;
28- import me .nik .combatplus .modules .impl .PlayerRegen ;
27+ import me .nik .combatplus .utils .Messenger ;
2928import org .bukkit .Bukkit ;
3029import org .bukkit .ChatColor ;
3130import org .bukkit .attribute .Attribute ;
32- import org .bukkit .attribute . AttributeInstance ;
31+ import org .bukkit .event . HandlerList ;
3332import org .bukkit .plugin .PluginManager ;
3433import org .bukkit .plugin .java .JavaPlugin ;
3534
3635import java .util .ArrayList ;
36+ import java .util .Arrays ;
3737import java .util .List ;
3838
3939public final class CombatPlus extends JavaPlugin {
@@ -60,34 +60,39 @@ public static CombatPlus getInstance() {
6060
6161 @ Override
6262 public void onDisable () {
63+
6364 //Load Default Stats to avoid server damage
64- setDefaultStats ();
65+ Bukkit .getOnlinePlayers ().forEach (player -> {
66+ player .getAttribute (Attribute .GENERIC_MAX_HEALTH ).setBaseValue (Config .Setting .CUSTOM_PLAYER_HEALTH_DEFAULT_MAX_HEALTH .getDouble ());
67+ player .getAttribute (Attribute .GENERIC_ATTACK_SPEED ).setBaseValue (Config .Setting .CUSTOM_ATTACK_SPEED_DEFAULT_ATTACK_SPEED .getDouble ());
68+ player .saveData ();
69+ });
6570
66- this .modules .forEach (Module ::disInit );
71+ this .modules .forEach (Module ::shutdown );
6772
6873 config .reset ();
6974 lang .reload ();
7075 lang .save ();
7176
77+ HandlerList .unregisterAll (this );
78+ this .getServer ().getScheduler ().cancelTasks (this );
79+
7280 instance = null ;
7381 }
7482
75- /**
76- * This needs a re-code, i might do it once im not so lazy
77- * Right now it's the definition of spaghetti code.
78- */
79-
8083 @ Override
8184 public void onEnable () {
85+
8286 instance = this ;
87+
8388 this .lang = new Lang ();
8489
8590 this .config = new Config (this );
8691
8792 //Load Files
8893 loadFiles ();
8994
90- this .getServer ().getConsoleSender ().sendMessage (this . STARTUP_MESSAGE );
95+ this .getServer ().getConsoleSender ().sendMessage (STARTUP_MESSAGE );
9196
9297 //Load Commands
9398 getCommand ("combatplus" ).setExecutor (new CommandManager (this ));
@@ -105,7 +110,6 @@ public void onEnable() {
105110 new MetricsLite (this , 6982 );
106111
107112 //Hook PlaceholderAPI
108-
109113 if (this .getServer ().getPluginManager ().getPlugin ("PlaceholderAPI" ) != null ) {
110114 new PapiHook (this ).register ();
111115 }
@@ -146,52 +150,32 @@ private void checkForUpdates() {
146150 if (Config .Setting .CHECK_FOR_UPDATES .getBoolean ()) {
147151 new UpdateChecker (this ).runTaskAsynchronously (this );
148152 } else {
149- consoleMessage (MsgType .CONSOLE_UPDATE_DISABLED .getMessage ());
153+ Messenger . consoleMessage (MsgType .CONSOLE_UPDATE_DISABLED .getMessage ());
150154 }
151155 }
152156
153- /**
154- * Default Stats to avoid Server Damage
155- */
156- private void setDefaultStats () {
157- Bukkit .getOnlinePlayers ().forEach (player -> {
158- final double defaultHealth = Config .Setting .ADV_BASE_HEALTH .getDouble ();
159- final AttributeInstance playerMaxHealth = player .getAttribute (Attribute .GENERIC_MAX_HEALTH );
160- playerMaxHealth .setBaseValue (defaultHealth );
161- final double defaultAttSpd = Config .Setting .ADV_NEW_ATTACK_SPEED .getDouble ();
162- final AttributeInstance playerAttSpeed = player .getAttribute (Attribute .GENERIC_ATTACK_SPEED );
163- playerAttSpeed .setBaseValue (defaultAttSpd );
164- player .saveData ();
165- });
166- }
167-
168157 private void initModules () {
158+
169159 this .modules .clear ();
170160
171- //add modules
172- this .modules .add (new PlayerRegen ());
173- this .modules .add (new OldPvP ());
174- this .modules .add (new Offhand ());
175- this .modules .add (new HealthBar ());
176- this .modules .add (new GoldenApple ());
177- this .modules .add (new FishingRodKnockback ());
178- this .modules .add (new Enderpearl ());
179- this .modules .add (new EnchantedGoldenApple ());
180- this .modules .add (new DisabledItems ());
181- this .modules .add (new DamageModifiers ());
182- this .modules .add (new CustomHealth ());
183- this .modules .add (new CombatLog ());
184- this .modules .add (new BowBoost ());
185- this .modules .add (new Blocking ());
186-
187- this .modules .forEach (Module ::init );
188-
189- if (Config .Setting .ENCHANTED_APPLE_CRAFTING .getBoolean ()) {
190- try {
191- this .getServer ().addRecipe (new CustomRecipes (this ).enchantedGoldenAppleRecipe ());
192- } catch (Exception ignored ) {
193- }
194- }
161+ //Add modules
162+ this .modules .addAll (Arrays .asList (
163+ new CustomPlayerRegeneration (),
164+ new CustomAttackSpeed (),
165+ new DisableOffhand (),
166+ new HealthBar (),
167+ new GoldenAppleCooldown (),
168+ new EnchantedGoldenAppleCooldown (),
169+ new FishingRodKnockback (),
170+ new EnderpearlCooldown (),
171+ new DamageModifiers (),
172+ new CustomHealth (),
173+ new CombatLog (),
174+ new DisableBowBoost (),
175+ new Blocking ()
176+ ));
177+
178+ this .modules .forEach (Module ::load );
195179 }
196180
197181 /**
@@ -204,11 +188,4 @@ private void initListeners() {
204188 //GUI Listener (Do not remove this, idiot nik)
205189 pm .registerEvents (new GuiListener (), this );
206190 }
207-
208- /**
209- * @param message The console message to send to the Server (ChatColor Friendly)
210- */
211- public void consoleMessage (String message ) {
212- this .getServer ().getConsoleSender ().sendMessage (message );
213- }
214191}
0 commit comments