1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-31 21:37:57 +01:00

Implementation of fast payment method

Tweaks for mcmmo abilities checker
Fix for leaveall
This commit is contained in:
Zrips 2016-06-28 12:33:28 +03:00
parent 72848342e1
commit fe2aae14ce
10 changed files with 141 additions and 25 deletions

View File

@ -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<String, PaymentData> ExpLimit = new HashMap<String, PaymentData>();
public final static HashMap<String, PaymentData> PointLimit = new HashMap<String, PaymentData>();
public final static HashMap<String, FastPayment> FastPayment = new HashMap<String, FastPayment>();
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);
}
}

View File

@ -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);

View File

@ -308,7 +308,9 @@ public class PlayerManager {
* @param jPlayer
*/
public void leaveAllJobs(JobsPlayer jPlayer) {
for (JobProgression job : jPlayer.getJobProgression()) {
List<JobProgression> jobs = new ArrayList<JobProgression>();
jobs.addAll(jPlayer.getJobProgression());
for (JobProgression job : jobs) {
leaveJob(jPlayer, job.getJob());
}
jPlayer.leaveAllJobs();

View File

@ -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;

View File

@ -34,3 +34,5 @@
/BoostMultiplier.class
/BoostCounter.class
/BoostType.class
/McmmoSkill.class
/FastPayment.class

View File

@ -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;
}
}

View File

@ -10,3 +10,4 @@
/JobsListener$2.class
/JobsListener$3.class
/JobsListener$4.class
/McMMOlistener$Skill.class

View File

@ -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"))

View File

@ -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<String, HashMap<AbilityType, Long>> map = new HashMap<String, HashMap<AbilityType, Long>>();
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<AbilityType, Long> InfoMap = new HashMap<AbilityType, Long>();
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<AbilityType, Long> 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<AbilityType, Long> 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;
}

View File

@ -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]