From 55a0705826276fda5e13cbc0ad28a8983e687a11 Mon Sep 17 00:00:00 2001 From: Zrips Date: Wed, 19 Jan 2022 17:28:12 +0200 Subject: [PATCH] Improving boost command handling --- .../jobs/commands/list/expboost.java | 79 ++++++++++++------- .../jobs/commands/list/moneyboost.java | 78 +++++++++++------- .../jobs/commands/list/pointboost.java | 77 ++++++++++++------ 3 files changed, 154 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java index 11b7eb93..7f8d279e 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/expboost.java @@ -6,7 +6,8 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.stuff.Util; + +import net.Zrips.CMILib.Time.timeModifier; public class expboost implements Cmd { @@ -17,35 +18,67 @@ public class expboost implements Cmd { return true; } - double rate = 1.0; - if (args[0].equalsIgnoreCase("all")) { + Double rate = null; + Long timeDuration = null; + String jobName = null; + boolean reset = false; + + for (String one : args) { + if (one.equalsIgnoreCase("reset")) { + reset = true; + continue; + } + + if (jobName == null) { + jobName = one; + continue; + } + + if (rate == null) { + try { + rate = Double.parseDouble(one); + continue; + } catch (NumberFormatException e) { + } + } + try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "expboost"); - return true; + Long t = timeModifier.getTimeRangeFromString(one); + if (t != null) + timeDuration = t; + continue; + } catch (Exception e) { } + } - int[] times = Util.parseTime(args); + if (!reset && rate == null || jobName == null) { + Jobs.getCommandManager().sendUsage(sender, "expboost"); + return false; + } + + if (rate == null) + rate = 1D; + if (timeDuration == null) + timeDuration = 0L; + + if (!reset && jobName.equalsIgnoreCase("all")) { for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.EXP, rate, times); + job.addBoost(CurrencyType.EXP, rate, timeDuration); } - - sender.sendMessage( - Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate)); + sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostalladded", "%boost%", rate)); return true; } - if (args[0].equalsIgnoreCase("reset")) { - if (args[1].equalsIgnoreCase("all")) { + if (reset) { + if (jobName.equalsIgnoreCase("all")) { for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.EXP, 1.0); } sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.allreset")); } else if (args.length > 1) { - Job job = Jobs.getJob(args[1]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; @@ -53,27 +86,19 @@ public class expboost implements Cmd { job.addBoost(CurrencyType.EXP, 1.0); - sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.jobsboostreset", - "%jobname%", job.getName())); + sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.jobsboostreset", "%jobname%", job.getName())); } return true; } - Job job = Jobs.getJob(args[0]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - - try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "expboost"); - return true; - } - - job.addBoost(CurrencyType.EXP, rate, Util.parseTime(args)); + + job.addBoost(CurrencyType.EXP, rate, timeDuration); sender.sendMessage(Jobs.getLanguage().getMessage("command.expboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName())); return true; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java index 4d4fb8d7..506bd6fc 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/moneyboost.java @@ -6,7 +6,8 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.stuff.Util; + +import net.Zrips.CMILib.Time.timeModifier; public class moneyboost implements Cmd { @@ -17,35 +18,67 @@ public class moneyboost implements Cmd { return true; } - double rate = 1.0; - if (args[0].equalsIgnoreCase("all")) { + Double rate = null; + Long timeDuration = null; + String jobName = null; + boolean reset = false; + + for (String one : args) { + if (one.equalsIgnoreCase("reset")) { + reset = true; + continue; + } + + if (jobName == null) { + jobName = one; + continue; + } + + if (rate == null) { + try { + rate = Double.parseDouble(one); + continue; + } catch (NumberFormatException e) { + } + } + try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); - return true; + Long t = timeModifier.getTimeRangeFromString(one); + if (t != null) + timeDuration = t; + continue; + } catch (Exception e) { } + } - int[] times = Util.parseTime(args); + if (!reset && rate == null || jobName == null) { + Jobs.getCommandManager().sendUsage(sender, "moneyboost"); + return false; + } + if (rate == null) + rate = 1D; + + if (timeDuration == null) + timeDuration = 0L; + + if (!reset && jobName.equalsIgnoreCase("all")) { for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.MONEY, rate, times); + job.addBoost(CurrencyType.MONEY, rate, 0L); } - - sender.sendMessage( - Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate)); + sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostalladded", "%boost%", rate)); return true; } - if (args[0].equalsIgnoreCase("reset")) { - if (args[1].equalsIgnoreCase("all")) { + if (reset) { + if (jobName.equalsIgnoreCase("all")) { for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.MONEY, 1.0); } sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.allreset")); } else if (args.length > 1) { - Job job = Jobs.getJob(args[1]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; @@ -53,30 +86,21 @@ public class moneyboost implements Cmd { job.addBoost(CurrencyType.MONEY, 1.0); - sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.jobsboostreset", - "%jobname%", job.getName())); + sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.jobsboostreset", "%jobname%", job.getName())); } return true; } - Job job = Jobs.getJob(args[0]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "moneyboost"); - return true; - } - - job.addBoost(CurrencyType.MONEY, rate, Util.parseTime(args)); + job.addBoost(CurrencyType.MONEY, rate, timeDuration); sender.sendMessage(Jobs.getLanguage().getMessage("command.moneyboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName())); return true; } - } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java index 065fa8b5..da32b94b 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/pointboost.java @@ -6,7 +6,8 @@ import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.stuff.Util; + +import net.Zrips.CMILib.Time.timeModifier; public class pointboost implements Cmd { @@ -17,35 +18,67 @@ public class pointboost implements Cmd { return true; } - double rate = 1.0; - if (args[0].equalsIgnoreCase("all")) { + Double rate = null; + Long timeDuration = null; + String jobName = null; + boolean reset = false; + + for (String one : args) { + if (one.equalsIgnoreCase("reset")) { + reset = true; + continue; + } + + if (jobName == null) { + jobName = one; + continue; + } + + if (rate == null) { + try { + rate = Double.parseDouble(one); + continue; + } catch (NumberFormatException e) { + } + } + try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "pointboost"); - return true; + Long t = timeModifier.getTimeRangeFromString(one); + if (t != null) + timeDuration = t; + continue; + } catch (Exception e) { } + } - int[] times = Util.parseTime(args); + if (!reset && rate == null || jobName == null) { + Jobs.getCommandManager().sendUsage(sender, "moneyboost"); + return false; + } + if (rate == null) + rate = 1D; + + if (timeDuration == null) + timeDuration = 0L; + + if (!reset && jobName.equalsIgnoreCase("all")) { for (Job job : Jobs.getJobs()) { - job.addBoost(CurrencyType.POINTS, rate, times); + job.addBoost(CurrencyType.POINTS, rate, 0L); } - - sender.sendMessage( - Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate)); + sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.boostalladded", "%boost%", rate)); return true; } - if (args[0].equalsIgnoreCase("reset")) { - if (args[1].equalsIgnoreCase("all")) { + if (reset) { + if (jobName.equalsIgnoreCase("all")) { for (Job one : Jobs.getJobs()) { one.addBoost(CurrencyType.POINTS, 1.0); } sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.allreset")); } else if (args.length > 1) { - Job job = Jobs.getJob(args[1]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; @@ -53,27 +86,19 @@ public class pointboost implements Cmd { job.addBoost(CurrencyType.POINTS, 1.0); - sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.jobsboostreset", - "%jobname%", job.getName())); + sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.jobsboostreset", "%jobname%", job.getName())); } return true; } - Job job = Jobs.getJob(args[0]); + Job job = Jobs.getJob(jobName); if (job == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - try { - rate = Double.parseDouble(args[args.length > 2 ? 2 : 1]); - } catch (NumberFormatException e) { - Jobs.getCommandManager().sendUsage(sender, "pointboost"); - return true; - } - - job.addBoost(CurrencyType.POINTS, rate, Util.parseTime(args)); + job.addBoost(CurrencyType.POINTS, rate, timeDuration); sender.sendMessage(Jobs.getLanguage().getMessage("command.pointboost.output.boostadded", "%boost%", rate, "%jobname%", job.getName())); return true;