diff --git a/com/gamingmesh/jobs/Jobs.java b/com/gamingmesh/jobs/Jobs.java index 19f45d83..a618e192 100644 --- a/com/gamingmesh/jobs/Jobs.java +++ b/com/gamingmesh/jobs/Jobs.java @@ -52,8 +52,10 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobInfo; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.dao.JobsDAO; import com.gamingmesh.jobs.economy.BufferedEconomy; +import com.gamingmesh.jobs.economy.BufferedPayment; import com.gamingmesh.jobs.economy.Economy; import com.gamingmesh.jobs.economy.PaymentData; import com.gamingmesh.jobs.i18n.Language; @@ -114,6 +116,8 @@ public class Jobs { public final static HashMap ExpLimit = new HashMap(); public final static HashMap PointLimit = new HashMap(); + public final static HashMap FastPayment = new HashMap(); + private static NMS nms; private static ActionBar actionbar; @@ -947,7 +951,33 @@ public class Jobs { if (prog.addExperience(expAmount)) Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); + + FastPayment.put(jPlayer.getUserName(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), amount, points, exp), prog.getJob())); } } } + + public static void perform(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) { + // JobsPayment event + JobsExpGainEvent JobsExpGainEvent = new JobsExpGainEvent(payment.getOfflinePlayer(), job, payment.getExp()); + Bukkit.getServer().getPluginManager().callEvent(JobsExpGainEvent); + double expAmount; + // If event is canceled, don't do anything + if (JobsExpGainEvent.isCancelled()) + expAmount = 0D; + else + expAmount = JobsExpGainEvent.getExp(); + + Jobs.getEconomy().pay(jPlayer, payment.getAmount(), payment.getPoints(), expAmount); + + JobProgression prog = jPlayer.getJobProgression(job); + + int oldLevel = prog.getLevel(); + + if (Jobs.getGCManager().LoggingUse) + Jobs.getLoging().recordToLog(jPlayer, info, payment.getAmount(), expAmount); + + if (prog.addExperience(expAmount)) + Jobs.getPlayerManager().performLevelUp(jPlayer, prog.getJob(), oldLevel); + } } diff --git a/com/gamingmesh/jobs/JobsPlugin.java b/com/gamingmesh/jobs/JobsPlugin.java index f69b90bd..5c6f044c 100644 --- a/com/gamingmesh/jobs/JobsPlugin.java +++ b/com/gamingmesh/jobs/JobsPlugin.java @@ -27,8 +27,6 @@ import org.bukkit.ChatColor; import com.gamingmesh.jobs.listeners.JobsListener; import com.gamingmesh.jobs.listeners.JobsPaymentListener; -import com.gamingmesh.jobs.listeners.McMMOlistener; -import com.gamingmesh.jobs.listeners.MythicMobsListener; import com.gamingmesh.jobs.stuff.ActionBar; import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.config.YmlMaker; @@ -106,12 +104,12 @@ public class JobsPlugin extends JavaPlugin { Jobs.setMcMMOlistener(this); if (Jobs.getMcMMOlistener().CheckmcMMO()) { - getServer().getPluginManager().registerEvents(new McMMOlistener(this), this); + getServer().getPluginManager().registerEvents(Jobs.getMcMMOlistener(), this); } Jobs.setMythicManager(this); if (Jobs.getMythicManager().Check() && Jobs.getGCManager().MythicMobsEnabled) { - getServer().getPluginManager().registerEvents(new MythicMobsListener(this), this); + getServer().getPluginManager().registerEvents(Jobs.getMythicManager(), this); } Jobs.setPistonProtectionListener(this); diff --git a/com/gamingmesh/jobs/PlayerManager.java b/com/gamingmesh/jobs/PlayerManager.java index 599ee2c0..507db09f 100644 --- a/com/gamingmesh/jobs/PlayerManager.java +++ b/com/gamingmesh/jobs/PlayerManager.java @@ -308,7 +308,9 @@ public class PlayerManager { * @param jPlayer */ public void leaveAllJobs(JobsPlayer jPlayer) { - for (JobProgression job : jPlayer.getJobProgression()) { + List jobs = new ArrayList(); + jobs.addAll(jPlayer.getJobProgression()); + for (JobProgression job : jobs) { leaveJob(jPlayer, job.getJob()); } jPlayer.leaveAllJobs(); diff --git a/com/gamingmesh/jobs/commands/list/join.java b/com/gamingmesh/jobs/commands/list/join.java index 2cbf3c31..3bb86703 100644 --- a/com/gamingmesh/jobs/commands/list/join.java +++ b/com/gamingmesh/jobs/commands/list/join.java @@ -11,6 +11,7 @@ import com.gamingmesh.jobs.commands.JobCommand; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.ChatColor; +import com.gamingmesh.jobs.stuff.Debug; public class join implements Cmd { @@ -71,6 +72,7 @@ public class join implements Cmd { return true; } + Debug.D("s"); if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) { String message = ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.fullslots"); message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED); @@ -80,6 +82,9 @@ public class join implements Cmd { int confMaxJobs = Jobs.getGCManager().getMaxJobs(); short PlayerMaxJobs = (short) jPlayer.getJobProgression().size(); + Debug.D(confMaxJobs > 0); + Debug.D(PlayerMaxJobs >= confMaxJobs); + Debug.D(!Jobs.getPlayerManager().getJobsLimit(pSender, PlayerMaxJobs)); if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(pSender, PlayerMaxJobs)) { sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.maxjobs")); return true; diff --git a/com/gamingmesh/jobs/container/.gitignore b/com/gamingmesh/jobs/container/.gitignore index de4a14f7..290bbbf5 100644 --- a/com/gamingmesh/jobs/container/.gitignore +++ b/com/gamingmesh/jobs/container/.gitignore @@ -34,3 +34,5 @@ /BoostMultiplier.class /BoostCounter.class /BoostType.class +/McmmoSkill.class +/FastPayment.class diff --git a/com/gamingmesh/jobs/container/FastPayment.java b/com/gamingmesh/jobs/container/FastPayment.java new file mode 100644 index 00000000..11c714ce --- /dev/null +++ b/com/gamingmesh/jobs/container/FastPayment.java @@ -0,0 +1,39 @@ +package com.gamingmesh.jobs.container; + +import com.gamingmesh.jobs.economy.BufferedPayment; + +public class FastPayment { + JobsPlayer jPlayer; + ActionInfo info; + BufferedPayment payment; + Job job; + Long time; + + public FastPayment(JobsPlayer jPlayer, ActionInfo info, BufferedPayment payment, Job job) { + this.jPlayer = jPlayer; + this.info = info; + this.payment = payment; + this.job = job; + this.time = System.currentTimeMillis() + 45; + } + + public JobsPlayer getPlayer() { + return this.jPlayer; + } + + public ActionInfo getInfo() { + return this.info; + } + + public BufferedPayment getPayment() { + return this.payment; + } + + public Job getJob() { + return this.job; + } + + public Long getTime() { + return this.time; + } +} diff --git a/com/gamingmesh/jobs/listeners/.gitignore b/com/gamingmesh/jobs/listeners/.gitignore index 3b83e90a..43b9821c 100644 --- a/com/gamingmesh/jobs/listeners/.gitignore +++ b/com/gamingmesh/jobs/listeners/.gitignore @@ -10,3 +10,4 @@ /JobsListener$2.class /JobsListener$3.class /JobsListener$4.class +/McMMOlistener$Skill.class diff --git a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 1094db51..0bd547fe 100644 --- a/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -78,6 +78,7 @@ import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.api.JobsChunkChangeEvent; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ExploreRespond; +import com.gamingmesh.jobs.container.FastPayment; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.stuff.ChatColor; @@ -292,6 +293,15 @@ public class JobsPaymentListener implements Listener { } } + FastPayment fp = Jobs.FastPayment.get(player.getName()); + if (fp != null) { + if (fp.getTime() > System.currentTimeMillis()) { + Jobs.perform(fp.getPlayer(), fp.getInfo(), fp.getPayment(), fp.getJob()); + return; + } + Jobs.FastPayment.remove(player.getName()); + } + // restricted area multiplier double multiplier = 0.0; @@ -802,9 +812,9 @@ public class JobsPaymentListener implements Listener { // Entity that died must be living if (!(e.getEntity() instanceof LivingEntity)) return; - + LivingEntity lVictim = (LivingEntity) e.getEntity(); - + //extra check for Citizens 2 sentry kills if (e.getDamager() instanceof Player) if (e.getDamager().hasMetadata("NPC")) diff --git a/com/gamingmesh/jobs/listeners/McMMOlistener.java b/com/gamingmesh/jobs/listeners/McMMOlistener.java index 3521130e..04138ed2 100644 --- a/com/gamingmesh/jobs/listeners/McMMOlistener.java +++ b/com/gamingmesh/jobs/listeners/McMMOlistener.java @@ -1,10 +1,13 @@ package com.gamingmesh.jobs.listeners; +import java.util.HashMap; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -14,7 +17,9 @@ import com.gamingmesh.jobs.JobsPlugin; import com.gamingmesh.jobs.actions.ItemActionInfo; import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.JobsPlayer; -import com.gmail.nossr50.api.AbilityAPI; +import com.gmail.nossr50.datatypes.skills.AbilityType; +import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityActivateEvent; +import com.gmail.nossr50.events.skills.abilities.McMMOPlayerAbilityDeactivateEvent; import com.gmail.nossr50.events.skills.repair.McMMOPlayerRepairCheckEvent; public class McMMOlistener implements Listener { @@ -22,6 +27,8 @@ public class McMMOlistener implements Listener { private JobsPlugin plugin; public boolean mcMMOPresent = false; + HashMap> map = new HashMap>(); + public McMMOlistener(JobsPlugin plugin) { this.plugin = plugin; } @@ -53,31 +60,53 @@ public class McMMOlistener implements Listener { Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR), 0.0); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void OnAbilityOn(McMMOPlayerAbilityActivateEvent event) { + HashMap InfoMap = new HashMap(); + if (map.containsKey(event.getPlayer().getName())) + InfoMap = map.get(event.getPlayer().getName()); + InfoMap.put(event.getAbility(), System.currentTimeMillis() + (event.getAbility().getMaxLength() * 1000)); + map.put(event.getPlayer().getName(), InfoMap); +// Debug.D("rec 1 " + map.size() + " " + event.getPlayer().getName()); +// Debug.D(map.containsKey(event.getPlayer().getName())); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void OnAbilityOff(McMMOPlayerAbilityDeactivateEvent event) { + if (map.containsKey(event.getPlayer().getName())) { + HashMap InfoMap = map.get(event.getPlayer().getName()); + InfoMap.remove(event.getAbility()); + if (InfoMap.isEmpty()) + map.remove(event.getPlayer().getName()); + } + } + public double getMultiplier(Player player) { - try { - if (AbilityAPI.treeFellerEnabled(player)) + + HashMap InfoMap = map.get(player.getName()); + if (InfoMap == null) + return 1.0; + + Long t = InfoMap.get(AbilityType.TREE_FELLER); + if (t != null) { + if (t < System.currentTimeMillis()) return Jobs.getGCManager().TreeFellerMultiplier; - } catch (Exception e) { - // If fails, apply tree feller multiplier - return Jobs.getGCManager().TreeFellerMultiplier; + map.remove(AbilityType.TREE_FELLER); } - try { - if (AbilityAPI.gigaDrillBreakerEnabled(player)) + t = InfoMap.get(AbilityType.GIGA_DRILL_BREAKER); + if (t != null) { + if (t < System.currentTimeMillis()) return Jobs.getGCManager().gigaDrillMultiplier; - } catch (Exception e) { - // If fails, apply giga drill multiplier - return Jobs.getGCManager().gigaDrillMultiplier; + map.remove(AbilityType.GIGA_DRILL_BREAKER); } - try { - if (AbilityAPI.superBreakerEnabled(player)) + t = InfoMap.get(AbilityType.SUPER_BREAKER); + if (t != null) { + if (t < System.currentTimeMillis()) return Jobs.getGCManager().superBreakerMultiplier; - } catch (Exception e) { - // If fails, apply super breaker multiplier - return Jobs.getGCManager().superBreakerMultiplier; + map.remove(AbilityType.SUPER_BREAKER); } - return 1.0; } diff --git a/plugin.yml b/plugin.yml index bba1449c..9b692c66 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,7 +1,7 @@ name: Jobs description: Jobs Plugin for the BukkitAPI main: com.gamingmesh.jobs.JobsPlugin -version: 3.5.2 +version: 3.5.3 author: phrstbrn depend: [Vault] softdepend: [CoreProtect, MythicMobs, McMMO]