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",
"cSpell.words": [
"Bukkit",
"islandsurvivalcraft",
"Minecraft"
]
"Minecraft",
"QUICKBAR"
],
"java.compile.nullAnalysis.mode": "automatic"
}

View File

@ -22,13 +22,16 @@ public class CommandProcessor implements CommandExecutor {
RegisteredCommands currentCommand = null;
try {
currentCommand = RegisteredCommands.valueOf(args[0].toUpperCase());
if (currentCommand.getCommandRunnable().requiresInitialization()) currentCommand.getCommandRunnable().initialize(islandSurvivalCraft);
String[] commandArguments = Arrays.copyOfRange(args, 1, args.length);
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()));
return false;
}
} 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);
String[] commandArguments = Arrays.copyOfRange(args, 1, args.length);
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()));
return true;
}
}

View File

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