1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Implement code to unregister all listeners on reload

This reduces the memory leak issue sometimes
- Schedule file now generated when option is enabled in configuration
- Make sure MyPet is enabled when starting plugin
This commit is contained in:
montlikadani 2019-07-23 21:32:32 +02:00
parent bc97d2aaf6
commit cf44caa2aa
6 changed files with 40 additions and 13 deletions

View File

@ -23,9 +23,9 @@
<dependency>
<groupId>de.Keyle.MyPet</groupId>
<artifactId>MyPet</artifactId>
<version>3.4</version>
<version>3.5</version>
<scope>system</scope>
<systemPath>${basedir}/libs/MyPet-3.4.jar</systemPath>
<systemPath>${basedir}/libs/MyPet-3.5.jar</systemPath>
</dependency>
<!-- McMMO -->
<dependency>

View File

@ -37,6 +37,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -648,11 +649,36 @@ public class Jobs extends JavaPlugin {
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
}
public static void reload() throws IOException {
reload(true);
}
/**
* Reloads all data
* @throws IOException
* @throws IOException
*/
public static void reload() throws IOException {
public static void reload(boolean startup) throws IOException {
// unregister all registered listeners by this plugin and register again
// this reduces the server memory leak
if (!startup) {
HandlerList.unregisterAll(instance);
getInstance().getServer().getPluginManager().registerEvents(new JobsListener(instance), instance);
getInstance().getServer().getPluginManager().registerEvents(new JobsPaymentListener(instance), instance);
if (GconfigManager.useBlockProtection)
getInstance().getServer().getPluginManager().registerEvents(PistonProtectionListener, instance);
if (getMcMMOManager().CheckmcMMO()) {
try {
Class.forName("com.gmail.nossr50.datatypes.skills.SuperAbilityType");
getInstance().getServer().getPluginManager().registerEvents(new McMMO2_X_listener(instance), instance);
} catch (Exception e) {
getInstance().getServer().getPluginManager().registerEvents(new McMMO1_X_listener(instance), instance);
}
}
}
if (saveTask != null) {
saveTask.shutdown();
saveTask = null;
@ -717,6 +743,8 @@ public class Jobs extends JavaPlugin {
if (dao != null) {
dao.closeConnections();
}
HandlerList.unregisterAll(instance);
}
/**
@ -867,9 +895,6 @@ public class Jobs extends JavaPlugin {
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
jobConfig.saveDefaultConfig();
YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml");
jobSchedule.saveDefaultConfig();
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
jobShopItems.saveDefaultConfig();
@ -892,7 +917,7 @@ public class Jobs extends JavaPlugin {
setActionBar();
getCommand("jobs").setExecutor(cManager);
this.getCommand("jobs").setTabCompleter(new TabComplete());
getCommand("jobs").setTabCompleter(new TabComplete());
startup();

View File

@ -49,8 +49,9 @@ public class MyPetManager {
public void setup() {
Plugin pl = Bukkit.getPluginManager().getPlugin("MyPet");
if (pl == null)
if (pl == null || !Bukkit.getPluginManager().isPluginEnabled("MyPet"))
return;
mp = MyPetApi.getPlayerManager();
mppm = MyPetApi.getMyPetManager();
enabled = true;

View File

@ -11,7 +11,7 @@ public class reload implements Cmd {
@JobCommand(2900)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
try {
Jobs.reload();
Jobs.reload(true);
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
} catch (Throwable e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));

View File

@ -1,6 +1,5 @@
package com.gamingmesh.jobs.config;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -168,8 +167,10 @@ public class ScheduleManager {
* loads from Jobs/schedule.yml
*/
public void load() {
File f = new File(Jobs.getFolder(), "schedule.yml");
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
YmlMaker jobSchedule = new YmlMaker(plugin, "schedule.yml");
jobSchedule.saveDefaultConfig();
YamlConfiguration conf = YamlConfiguration.loadConfiguration(jobSchedule.getConfigFile());
conf.options().copyDefaults(true);