Fixed potential null reference.
Some checks failed
RealYHD/islandsurvivalcraft/pipeline/head There was a failure building this commit
ydeng/islandsurvivalcraft/pipeline/head There was a failure building this commit

This commit is contained in:
Harrison Deng 2022-12-08 16:53:04 +00:00
parent 41938de11b
commit 6eff20bb86
3 changed files with 23 additions and 19 deletions

View File

@ -1,7 +1,10 @@
{ {
"java.configuration.updateBuildConfiguration": "automatic", "java.configuration.updateBuildConfiguration": "automatic",
"cSpell.words": [ "cSpell.words": [
"Bukkit",
"islandsurvivalcraft", "islandsurvivalcraft",
"Minecraft" "Minecraft",
] "QUICKBAR"
],
"java.compile.nullAnalysis.mode": "automatic"
} }

View File

@ -22,13 +22,16 @@ public class CommandProcessor implements CommandExecutor {
RegisteredCommands currentCommand = null; RegisteredCommands currentCommand = null;
try { try {
currentCommand = RegisteredCommands.valueOf(args[0].toUpperCase()); currentCommand = RegisteredCommands.valueOf(args[0].toUpperCase());
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "This command was not understood. Refer to \"/IslandSurvivalCraft help\" for more info.");
}
if (currentCommand.getCommandRunnable().requiresInitialization()) currentCommand.getCommandRunnable().initialize(islandSurvivalCraft); if (currentCommand.getCommandRunnable().requiresInitialization()) currentCommand.getCommandRunnable().initialize(islandSurvivalCraft);
String[] commandArguments = Arrays.copyOfRange(args, 1, args.length); String[] commandArguments = Arrays.copyOfRange(args, 1, args.length);
boolean success = currentCommand.getCommandRunnable().invoke(sender, commandArguments); boolean success = currentCommand.getCommandRunnable().invoke(sender, commandArguments);
if (!success) sender.sendMessage(String.format("The command arguments were incorrect. Please refer to \"/IslandSurvivalCraft help %s\" for help.", currentCommand.toString())); if (!success) {
sender.sendMessage(String.format("The command arguments were incorrect. Please refer to \"/IslandSurvivalCraft help %s\" for help.", currentCommand.toString()));
return false;
}
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + "This command was not understood. Refer to \"/IslandSurvivalCraft help\" for more info.");
}
return true; return true;
} }
} }

View File

@ -16,8 +16,6 @@ import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
@ -43,9 +41,9 @@ public class ItemVariantManager implements Listener {
if (items[i].getVariedItem().needInitialization()) { if (items[i].getVariedItem().needInitialization()) {
items[i].getVariedItem().initialize(islandSurvivalCraft); items[i].getVariedItem().initialize(islandSurvivalCraft);
} }
Recipe currRecipe = items[i].getVariedItem().getRecipe(); Recipe currentRecipe = items[i].getVariedItem().getRecipe();
if (currRecipe != null) { if (currentRecipe != null) {
islandSurvivalCraft.getServer().addRecipe(currRecipe); islandSurvivalCraft.getServer().addRecipe(currentRecipe);
} }
} }
@ -172,19 +170,19 @@ public class ItemVariantManager implements Listener {
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
RegisteredItemVariants[] items = RegisteredItemVariants.values(); RegisteredItemVariants[] items = RegisteredItemVariants.values();
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
ItemVariant curr = items[i].getVariedItem(); ItemVariant current = items[i].getVariedItem();
if (curr.getRecipe() == null) { if (current.getRecipe() == null) {
for (Material material : curr.getBaseItems()) { for (Material material : current.getBaseItems()) {
if (item.getType() == material) { if (item.getType() == material) {
return curr; return current;
} }
} }
} }
NamespacedKey key = new NamespacedKey(islandSurvivalCraft, curr.getItemName()); NamespacedKey key = new NamespacedKey(islandSurvivalCraft, current.getItemName());
String identifier = meta.getPersistentDataContainer().get(key, curr.getIdentifier()); String identifier = meta.getPersistentDataContainer().get(key, current.getIdentifier());
if (identifier != null) { if (identifier != null) {
if (curr.getIdentifier().getID().equals(identifier)) { if (current.getIdentifier().getID().equals(identifier)) {
return curr; return current;
} }
} }
} }