From 149a71e5da4fb51d97e82abb3e48a18ede0331bf Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 29 Mar 2021 17:08:22 +0200 Subject: [PATCH] Fix further issue when an event is not existent in 1.8 servers --- src/main/java/com/gamingmesh/jobs/Jobs.java | 8 ++++++++ .../com/gamingmesh/jobs/PlayerManager.java | 7 ++----- .../gamingmesh/jobs/commands/list/join.java | 19 ++++++++++++++----- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 12 +++--------- .../jobs/listeners/JobsListener.java | 14 ++++---------- .../jobs/listeners/Listener1_9.java | 15 +++++++++++++++ 6 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 11365624..751da0de 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -708,6 +708,10 @@ public class Jobs extends JavaPlugin { } // register the listeners + if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { + getServer().getPluginManager().registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), instance); + } + getServer().getPluginManager().registerEvents(new JobsListener(this), this); getServer().getPluginManager().registerEvents(new JobsPaymentListener(this), this); if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { @@ -764,6 +768,10 @@ public class Jobs extends JavaPlugin { com.gamingmesh.jobs.CMIGUI.GUIManager.registerListener(); + if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) { + pm.registerEvents(new com.gamingmesh.jobs.listeners.Listener1_9(), instance); + } + pm.registerEvents(new JobsListener(instance), instance); pm.registerEvents(new JobsPaymentListener(instance), instance); if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) { diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 0408f532..cd25ece1 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -245,14 +245,11 @@ public class PlayerManager { jPlayer = Jobs.getJobsDAO().loadFromDao(player); if (Jobs.getGCManager().MultiServerCompatability()) { - ArchivedJobs archivedJobs = Jobs.getJobsDAO().getArchivedJobs(jPlayer); - if (archivedJobs != null) { - jPlayer.setArchivedJobs(archivedJobs); - } - + jPlayer.setArchivedJobs(Jobs.getJobsDAO().getArchivedJobs(jPlayer)); jPlayer.setPaymentLimit(Jobs.getJobsDAO().getPlayersLimits(jPlayer)); jPlayer.setPoints(Jobs.getJobsDAO().getPlayerPoints(jPlayer)); } + // Lets load quest progression PlayerInfo info = Jobs.getJobsDAO().loadPlayerData(player.getUniqueId()); if (info != null) { diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/join.java b/src/main/java/com/gamingmesh/jobs/commands/list/join.java index a3b68153..618e527c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/join.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/join.java @@ -30,21 +30,30 @@ public class join implements Cmd { return true; } - Player pSender = (Player) sender; Job job = Jobs.getJob(args[0]); if (job == null) { // job does not exist - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - if (!Jobs.getCommandManager().hasJobPermission(pSender, job)) { - // you do not have permission to join the job - pSender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); + if (!Jobs.getCommandManager().hasJobPermission(sender, job)) { + // The player do not have permission to join the job + sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission")); return true; } + Player pSender = (Player) sender; JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + if (jPlayer == null) { // Load player into cache + Jobs.getPlayerManager().playerJoin(pSender); + jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender); + } + + if (jPlayer == null) { + return true; + } + if (jPlayer.isInJob(job)) { // already in job message pSender.sendMessage(Jobs.getLanguage().getMessage("command.join.error.alreadyin", "%jobname%", job.getNameWithColor())); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 52600833..7f62671b 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -785,7 +785,7 @@ public abstract class JobsDAO { while (res.next()) { String jobName = res.getString(ArchiveTableFields.job.getCollumn()); - Double exp = res.getDouble(ArchiveTableFields.experience.getCollumn()); + double exp = res.getDouble(ArchiveTableFields.experience.getCollumn()); int lvl = res.getInt(ArchiveTableFields.level.getCollumn()); Long left = res.getLong(ArchiveTableFields.left.getCollumn()); int jobid = res.getInt(ArchiveTableFields.jobid.getCollumn()); @@ -1820,14 +1820,8 @@ public abstract class JobsDAO { // add the job Job job = Jobs.getJob(jobdata.getJobName()); - if (job == null) - continue; - - // create the progression object - JobProgression jobProgression = new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience()); - // calculate the max level - // add the progression level. - jPlayer.progression.add(jobProgression); + if (job != null) + jPlayer.progression.add(new JobProgression(job, jPlayer, jobdata.getLevel(), jobdata.getExperience())); } jPlayer.reloadMaxExperience(); jPlayer.reloadLimits(); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index a0b500c4..edbf3524 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -56,7 +56,6 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.inventory.ItemStack; @@ -627,27 +626,22 @@ public class JobsListener implements Listener { } @EventHandler - public void JobsArmorChangeEvent(JobsArmorChangeEvent event) { + public void jobsArmorChangeEvent(JobsArmorChangeEvent event) { Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler - public void PlayerItemHeldEvent(PlayerItemHeldEvent event) { + public void playerItemHeldEvent(PlayerItemHeldEvent event) { Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler - public void PlayerItemBreakEvent(PlayerItemBreakEvent event) { + public void playerItemBreakEvent(PlayerItemBreakEvent event) { Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); } @EventHandler - public void PlayerItemBreakEvent(InventoryClickEvent event) { + public void playerItemBreakEvent(InventoryClickEvent event) { Jobs.getPlayerManager().resetItemBonusCache(((Player) event.getWhoClicked()).getUniqueId()); } - - @EventHandler - public void onPlayerHandSwap(PlayerSwapHandItemsEvent event) { - Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); - } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java b/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java new file mode 100644 index 00000000..9f88fbf5 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/listeners/Listener1_9.java @@ -0,0 +1,15 @@ +package com.gamingmesh.jobs.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; + +import com.gamingmesh.jobs.Jobs; + +public class Listener1_9 implements Listener { + + @EventHandler + public void onPlayerHandSwap(PlayerSwapHandItemsEvent event) { + Jobs.getPlayerManager().resetItemBonusCache(event.getPlayer().getUniqueId()); + } +}