From e4085da71c212f9f6da96ec087c9dab4cd29f70b Mon Sep 17 00:00:00 2001 From: montlikadani Date: Tue, 24 Mar 2020 14:08:37 +0100 Subject: [PATCH] Fix error in jobs give command - Fixed error on startup where the Enchantmnt#getKey is null. --- .../java/com/gamingmesh/jobs/CMILib/CMIEnchantment.java | 9 ++++++--- .../java/com/gamingmesh/jobs/commands/list/give.java | 8 +++----- .../java/com/gamingmesh/jobs/config/LanguageManager.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIEnchantment.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIEnchantment.java index 48e177e3..6dbef2b3 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIEnchantment.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIEnchantment.java @@ -68,9 +68,12 @@ public enum CMIEnchantment { break; } - if (one.getKey().toString().split(":")[1].toLowerCase().replace("_", "").equalsIgnoreCase(temp)) { - enchantment = one; - break; + try { + if (one.getKey().toString().split(":")[1].toLowerCase().replace("_", "").equalsIgnoreCase(temp)) { + enchantment = one; + break; + } + } catch (Exception | Error e) { } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/give.java b/src/main/java/com/gamingmesh/jobs/commands/list/give.java index 89667adb..6ca43741 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/give.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/give.java @@ -29,7 +29,6 @@ public class give implements Cmd { @Override @JobCommand(2500) public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) { - Player player = null; Job job = null; actions name = null; @@ -60,10 +59,10 @@ public class give implements Cmd { player = (Player) sender; if (player == null) { - sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline", "%playername%", args[0])); + sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.notonline")); return true; } - + if (name == null) name = actions.items; @@ -75,7 +74,6 @@ public class give implements Cmd { switch (name) { case items: JobItems jItem = ItemBoostManager.getItemByKey(itemName); - if (jItem == null || jItem.getItemStack(player) == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); return true; @@ -88,8 +86,8 @@ public class give implements Cmd { Jobs.getCommandManager().sendUsage(sender, "give"); return true; } - JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase()); + JobLimitedItems jLItem = job.getLimitedItems().get(itemName.toLowerCase()); if (jLItem == null || jLItem.getItemStack(player) == null) { sender.sendMessage(Jobs.getLanguage().getMessage("command.give.output.noitem")); return true; diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index c2873988..361c5828 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -319,7 +319,7 @@ public class LanguageManager { c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional"); c.get("command.give.help.args", "[playername] [jobname] [items/limiteditems] [jobitemname]"); Jobs.getGCManager().getCommandArgs().put("give", Arrays.asList("[playername]", "[jobname]%%[jobitemname]", "[jobitemname]")); - c.get("command.give.output.notonline", "&4Player [%playername%] is not online!"); + c.get("command.give.output.notonline", "&4Player with that name is not online!"); c.get("command.give.output.noitem", "&4Can't find any item by given name!"); c.get("command.info.help.title", "&2*** &eJobs&2 ***");