1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

Centralizing event listener register to avoid issues

Fixing issue with chat entry no longer being recognized after plugin
reload
This commit is contained in:
Zrips 2022-06-22 12:41:35 +03:00
parent f9ba65d56b
commit f70027708e
6 changed files with 31 additions and 54 deletions

View File

@ -751,22 +751,8 @@ public final class Jobs extends JavaPlugin {
new YmlMaker(getFolder(), "Signs.yml").saveDefaultConfig();
}
// register the listeners
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) {
getServer().getPluginManager().registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), getInstance());
}
getServer().getPluginManager().registerEvents(new JobsListener(this), this);
getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this);
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
getServer().getPluginManager().registerEvents(new JobsPayment14Listener(), this);
}
HookManager.loadHooks();
if (getGCManager().useBlockProtection) {
getServer().getPluginManager().registerEvents(new PistonProtectionListener(), this);
}
registerListeners();
if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) {
complement = new Complement2();
@ -774,7 +760,6 @@ public final class Jobs extends JavaPlugin {
} else {
complement = new Complement1();
}
getServer().getPluginManager().registerEvents(new JobsChatEvent(this), this);
// register economy
getServer().getScheduler().runTask(this, new HookEconomyTask(this));
@ -794,17 +779,10 @@ public final class Jobs extends JavaPlugin {
CMIMessages.consoleMessage(suffix);
}
public static void reload() {
reload(false);
}
private static void registerListeners() {
public static void reload(boolean startup) {
// unregister all registered listeners by this plugin and register again
if (!startup) {
org.bukkit.plugin.PluginManager pm = getInstance().getServer().getPluginManager();
HandlerList.unregisterAll(getInstance());
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) {
pm.registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), getInstance());
}
@ -819,6 +797,8 @@ public final class Jobs extends JavaPlugin {
pm.registerEvents(new PistonProtectionListener(), getInstance());
}
pm.registerEvents(new JobsChatEvent(getInstance()), getInstance());
if (HookManager.getMcMMOManager().CheckmcMMO()) {
HookManager.setMcMMOlistener();
}
@ -827,6 +807,17 @@ public final class Jobs extends JavaPlugin {
}
}
public static void reload() {
reload(false);
}
public static void reload(boolean startup) {
// unregister all registered listeners by this plugin and register again
if (!startup) {
HandlerList.unregisterAll(getInstance());
registerListeners();
}
if (saveTask != null) {
saveTask.shutdown();
}

View File

@ -16,7 +16,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
@ -33,7 +32,6 @@ import com.gamingmesh.jobs.stuff.TimeManage;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
public class Placeholder {

View File

@ -15,8 +15,6 @@ import com.gamingmesh.jobs.hooks.WorldGuard.WorldGuardManager;
import com.gamingmesh.jobs.hooks.stackMob.StackMobHandler;
import com.gamingmesh.jobs.hooks.wildStacker.WildStackerHandler;
import net.Zrips.CMILib.Logs.CMIDebug;
public class HookManager {
private static McMMOManager McMMOManager;
@ -33,18 +31,11 @@ public class HookManager {
public static void loadHooks() {
pm = PLUGIN.getServer().getPluginManager();
if (getMcMMOManager().CheckmcMMO())
setMcMMOlistener();
setMyPetManager();
setWorldGuard();
setMythicManager();
setStackMobHandler();
setWildStackerHandler();
if (checkMythicMobs()) {
MythicManager.registerListener();
}
}
public static StackMobHandler getStackMobHandler() {

View File

@ -16,7 +16,6 @@ import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
public class McMMO1_X_listener implements Listener {

View File

@ -14,10 +14,8 @@ import com.gamingmesh.jobs.actions.ItemActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.hooks.HookManager;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent;
import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent;
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent;
public class McMMO2_X_listener implements Listener {