From 7320c1a349ae43d89b4d775bcdb7980e95b08b20 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 26 Oct 2021 16:32:39 +0300 Subject: [PATCH] Fix for jobs info command with provided action and page --- .../jobs/commands/JobsCommands.java | 24 ++++++------------- .../gamingmesh/jobs/commands/list/info.java | 18 ++++++++++---- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java index e9606435..4be2f116 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java +++ b/src/main/java/com/gamingmesh/jobs/commands/JobsCommands.java @@ -25,6 +25,7 @@ import com.gamingmesh.jobs.stuff.Util; import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.Container.PageInfo; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.RawMessages.RawMessage; public class JobsCommands implements CommandExecutor { @@ -235,14 +236,6 @@ public class JobsCommands implements CommandExecutor { List message = new ArrayList<>(); - int showAllTypes = 1; - for (ActionType actionType : ActionType.values()) { - if (type.startsWith(actionType.getName().toLowerCase())) { - showAllTypes = 0; - break; - } - } - if (job.getBoost().get(CurrencyType.EXP) != 0D) message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1)); @@ -264,21 +257,19 @@ public class JobsCommands implements CommandExecutor { } for (ActionType actionType : ActionType.values()) { - if (showAllTypes == 1 || type.startsWith(actionType.getName().toLowerCase())) { + if (!type.isEmpty() && type.startsWith(actionType.getName().toLowerCase())) { List info = job.getJobInfo(actionType); - if (info != null && !info.isEmpty()) { String m = jobInfoMessage(player, job, actionType); - if (m.contains("\n")) message.addAll(Arrays.asList(m.split("\n"))); else message.add(m); - } else if (showAllTypes == 0) { - String myMessage = Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none"); - myMessage = myMessage.replace("%jobname%", job.getJobDisplayName()); - message.add(myMessage); } + } else if (type.isEmpty()) { + String myMessage = Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none"); + myMessage = myMessage.replace("%jobname%", job.getJobDisplayName()); + message.add(myMessage); } } @@ -298,9 +289,8 @@ public class JobsCommands implements CommandExecutor { sender.sendMessage(one); } - String t = type.isEmpty() ? "" : " " + type; - if (isPlayer) { + String t = type.isEmpty() ? "" : " " + type; String pName = player.getName(); if (sender.getName().equalsIgnoreCase(pName)) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/info.java b/src/main/java/com/gamingmesh/jobs/commands/list/info.java index ce56f781..6202d92a 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/info.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/info.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobsPlayer; @@ -12,6 +13,7 @@ public class info implements Cmd { @Override public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { + if (!(sender instanceof Player)) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame")); return false; @@ -47,12 +49,20 @@ public class info implements Cmd { } int page = 1; - String type = ""; - if (args.length >= 2) { + String type = null; + + for (int i = 1; i < args.length; i++) { + String one = args[i]; + if (type == null) { + ActionType t = ActionType.getByName(one); + if (t != null) { + type = t.getName(); + continue; + } + } try { - page = Integer.parseInt(args[1]); + page = Integer.parseInt(args[i]); } catch (NumberFormatException e) { - type = args[1]; } }