Catch null ItemStack for #548. Bump version number

This commit is contained in:
BuildTools 2018-12-02 12:04:40 -05:00
parent 2139465cfc
commit c464916e9d
4 changed files with 43 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<groupId>me.blackvein.quests</groupId>
<artifactId>quests</artifactId>
<version>3.4.5</version>
<version>3.4.6</version>
<name>quests</name>
<url>https://github.com/FlyingPikachu/Quests/</url>
<packaging>jar</packaging>

View File

@ -31,6 +31,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.QuestMob;
@ -208,7 +209,14 @@ public class Event {
}
if (items.isEmpty() == false) {
for (ItemStack is : items) {
Quests.addItem(player, is);
try {
Quests.addItem(player, is);
} catch (Exception e) {
plugin.getLogger().severe("Unable to add null item to inventory of "
+ player.getName() + " during quest " + quest.name + " event " + name);
player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. "
+ "Please contact an administrator.");
}
}
}
if (stormWorld != null) {

View File

@ -318,7 +318,14 @@ public class Quest {
}
}
for (ItemStack i : itemRewards) {
Quests.addItem(player, i);
try {
Quests.addItem(player, i);
} catch (Exception e) {
plugin.getLogger().severe("Unable to add null reward item to inventory of "
+ player.getName() + " upon completion of quest " + name);
player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. "
+ "Please contact an administrator.");
}
none = null;
}
for (String s : commands) {
@ -368,7 +375,14 @@ public class Quest {
if (lb.getItemList().isEmpty() == false) {
phatLootItems.addAll(lb.getItemList());
for (ItemStack is : lb.getItemList()) {
Quests.addItem(player, is);
try {
Quests.addItem(player, is);
} catch (Exception e) {
plugin.getLogger().severe("Unable to add PhatLoots item to inventory of "
+ player.getName() + " upon completion of quest " + name);
player.sendMessage(ChatColor.RED + "Quests encountered a problem with an item. "
+ "Please contact an administrator.");
}
}
}
if (lb.getCommandList().isEmpty() == false) {

View File

@ -3759,14 +3759,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
public static SkillType getMcMMOSkill(String s) {
return SkillType.getSkill(s);
}
public static void addItem(Player p, ItemStack i) {
/**
* Adds item to player's inventory. If full, item is dropped at player's location.
*
* @throws NullPointerException when ItemStack is null
*/
public static void addItem(Player p, ItemStack i) throws Exception {
if (i == null) {
throw new NullPointerException("Null item while trying to add to inventory of " + p.getName());
}
PlayerInventory inv = p.getInventory();
HashMap<Integer, ItemStack> leftover = inv.addItem(i);
if (leftover != null) {
if (leftover.isEmpty() == false) {
for (ItemStack i2 : leftover.values()) {
p.getWorld().dropItem(p.getLocation(), i2);
if (i != null) {
HashMap<Integer, ItemStack> leftover = inv.addItem(i);
if (leftover != null) {
if (leftover.isEmpty() == false) {
for (ItemStack i2 : leftover.values()) {
p.getWorld().dropItem(p.getLocation(), i2);
}
}
}
}