mirror of
https://github.com/Zrips/Jobs.git
synced 2025-01-04 23:37:49 +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:
parent
bc97d2aaf6
commit
cf44caa2aa
Binary file not shown.
4
pom.xml
4
pom.xml
@ -23,9 +23,9 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.Keyle.MyPet</groupId>
|
<groupId>de.Keyle.MyPet</groupId>
|
||||||
<artifactId>MyPet</artifactId>
|
<artifactId>MyPet</artifactId>
|
||||||
<version>3.4</version>
|
<version>3.5</version>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${basedir}/libs/MyPet-3.4.jar</systemPath>
|
<systemPath>${basedir}/libs/MyPet-3.5.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- McMMO -->
|
<!-- McMMO -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -37,6 +37,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -648,11 +649,36 @@ public class Jobs extends JavaPlugin {
|
|||||||
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
((int) (((System.currentTimeMillis() - time) / 1000d) * 100) / 100D));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void reload() throws IOException {
|
||||||
|
reload(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads all data
|
* 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) {
|
if (saveTask != null) {
|
||||||
saveTask.shutdown();
|
saveTask.shutdown();
|
||||||
saveTask = null;
|
saveTask = null;
|
||||||
@ -717,6 +743,8 @@ public class Jobs extends JavaPlugin {
|
|||||||
if (dao != null) {
|
if (dao != null) {
|
||||||
dao.closeConnections();
|
dao.closeConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HandlerList.unregisterAll(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -867,9 +895,6 @@ public class Jobs extends JavaPlugin {
|
|||||||
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
YmlMaker jobConfig = new YmlMaker(this, "jobConfig.yml");
|
||||||
jobConfig.saveDefaultConfig();
|
jobConfig.saveDefaultConfig();
|
||||||
|
|
||||||
YmlMaker jobSchedule = new YmlMaker(this, "schedule.yml");
|
|
||||||
jobSchedule.saveDefaultConfig();
|
|
||||||
|
|
||||||
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
|
YmlMaker jobShopItems = new YmlMaker(this, "shopItems.yml");
|
||||||
jobShopItems.saveDefaultConfig();
|
jobShopItems.saveDefaultConfig();
|
||||||
|
|
||||||
@ -892,7 +917,7 @@ public class Jobs extends JavaPlugin {
|
|||||||
setActionBar();
|
setActionBar();
|
||||||
|
|
||||||
getCommand("jobs").setExecutor(cManager);
|
getCommand("jobs").setExecutor(cManager);
|
||||||
this.getCommand("jobs").setTabCompleter(new TabComplete());
|
getCommand("jobs").setTabCompleter(new TabComplete());
|
||||||
|
|
||||||
startup();
|
startup();
|
||||||
|
|
||||||
|
@ -49,8 +49,9 @@ public class MyPetManager {
|
|||||||
|
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Plugin pl = Bukkit.getPluginManager().getPlugin("MyPet");
|
Plugin pl = Bukkit.getPluginManager().getPlugin("MyPet");
|
||||||
if (pl == null)
|
if (pl == null || !Bukkit.getPluginManager().isPluginEnabled("MyPet"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mp = MyPetApi.getPlayerManager();
|
mp = MyPetApi.getPlayerManager();
|
||||||
mppm = MyPetApi.getMyPetManager();
|
mppm = MyPetApi.getMyPetManager();
|
||||||
enabled = true;
|
enabled = true;
|
||||||
|
@ -11,7 +11,7 @@ public class reload implements Cmd {
|
|||||||
@JobCommand(2900)
|
@JobCommand(2900)
|
||||||
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
|
||||||
try {
|
try {
|
||||||
Jobs.reload();
|
Jobs.reload(true);
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.gamingmesh.jobs.config;
|
package com.gamingmesh.jobs.config;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -168,8 +167,10 @@ public class ScheduleManager {
|
|||||||
* loads from Jobs/schedule.yml
|
* loads from Jobs/schedule.yml
|
||||||
*/
|
*/
|
||||||
public void load() {
|
public void load() {
|
||||||
File f = new File(Jobs.getFolder(), "schedule.yml");
|
YmlMaker jobSchedule = new YmlMaker(plugin, "schedule.yml");
|
||||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
|
jobSchedule.saveDefaultConfig();
|
||||||
|
|
||||||
|
YamlConfiguration conf = YamlConfiguration.loadConfiguration(jobSchedule.getConfigFile());
|
||||||
|
|
||||||
conf.options().copyDefaults(true);
|
conf.options().copyDefaults(true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user