Closes gh-149. Forgot to fix all reward and loadout-related item NPEs. This is War v1.4.2.

This commit is contained in:
taoneill 2011-04-11 11:10:53 -04:00
parent b9c0030e3c
commit 628c33778e
11 changed files with 85 additions and 58 deletions

View File

@ -244,10 +244,11 @@ public class War extends JavaPlugin {
PlayerInventory inv = player.getInventory();
int i = 0;
for(ItemStack stack : inv.getContents()){
if(stack.getType() != Material.AIR) {
if(stack != null && stack.getType() != Material.AIR) {
loadout.put(i, stack);
i++;
}
i++;
}
if(inv.getBoots() != null && inv.getBoots().getType() != Material.AIR) {
loadout.put(100, inv.getBoots());

View File

@ -111,20 +111,22 @@ public class WarPlayerListener extends PlayerListener {
} else {
Item item = event.getItemDrop();
ItemStack itemStack = item.getItemStack();
if(itemStack != null
&& itemStack.getType() == team.getKind().getMaterial()
&& itemStack.getData().getData() == team.getKind().getData()) {
// Can't drop your team's kind block
war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
event.setCancelled(true);
return;
}
if(zone.isNearWall(player.getLocation()) && itemStack != null) {
war.badMsg(player, "Can't drop items near the zone border!");
event.setCancelled(true);
return;
if(item != null) {
ItemStack itemStack = item.getItemStack();
if(itemStack != null
&& itemStack.getType() == team.getKind().getMaterial()
&& itemStack.getData().getData() == team.getKind().getData()) {
// Can't drop your team's kind block
war.badMsg(player, "Can't drop " + team.getName() + " block blocks.");
event.setCancelled(true);
return;
}
if(zone.isNearWall(player.getLocation()) && itemStack != null) {
war.badMsg(player, "Can't drop items near the zone border!");
event.setCancelled(true);
return;
}
}
}
}
@ -141,15 +143,17 @@ public class WarPlayerListener extends PlayerListener {
event.setCancelled(true);
} else {
Item item = event.getItem();
if(item instanceof CraftItem) {
if(item != null && item instanceof CraftItem) {
CraftItem cItem = (CraftItem)item;
ItemStack itemStack = cItem.getItemStack();
if(itemStack != null && itemStack.getType() == team.getKind().getMaterial()
&& player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
// Can't pick up a second precious block
//war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true);
return;
if(cItem != null) {
ItemStack itemStack = cItem.getItemStack();
if(itemStack != null && itemStack.getType() == team.getKind().getMaterial()
&& player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
// Can't pick up a second precious block
//war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true);
return;
}
}
}

View File

@ -393,8 +393,11 @@ public class Warzone {
playerInv.setLeggings(loadout.get(slot));
} else if(slot == 102) {
playerInv.setChestplate(loadout.get(slot));
} else {
playerInv.addItem(loadout.get(slot));
} else {
ItemStack item = loadout.get(slot);
if(item != null) {
playerInv.addItem(item);
}
}
}
if(isBlockHeads()) {
@ -457,7 +460,9 @@ public class Warzone {
this.loadout.clear();
for(Integer slot : newLoadout.keySet()) {
ItemStack stack = newLoadout.get(slot);
this.loadout.put(slot, stack);
if(stack != null) {
this.loadout.put(slot, stack);
}
}
}

View File

@ -17,7 +17,9 @@ public class LootDropperTask implements Runnable {
public void run() {
for(ItemStack item : drop) {
location.getWorld().dropItemNaturally(location, item);
if(item != null) {
location.getWorld().dropItemNaturally(location, item);
}
}
}
}

View File

@ -1,6 +1,7 @@
package com.tommytony.war.jobs;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
@ -30,7 +31,10 @@ public class ScoreCapReachedJob implements Runnable {
if(winnersStr.contains(t.getName())) {
// give reward
for(Integer slot : zone.getReward().keySet()){
tp.getInventory().addItem(zone.getReward().get(slot));
ItemStack item = zone.getReward().get(slot);
if(item != null) {
tp.getInventory().addItem(item);
}
}
}
}

View File

@ -236,12 +236,14 @@ public class VolumeMapper {
List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
if(contents != null) {
for(ItemStack item : contents) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
if(item != null) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
}
}
out.write(extra);
}
@ -251,12 +253,14 @@ public class VolumeMapper {
List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
if(contents != null) {
for(ItemStack item : contents) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
if(item != null) {
extra += item.getTypeId() + ";"
+ item.getAmount() + ";"
+ item.getDurability();
if(item.getData() != null)
extra += ";" + item.getData().getData() ;
extra += ";;";
}
}
out.write(extra);
}

View File

@ -3,8 +3,6 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import bukkit.tommytony.war.War;
@ -14,7 +12,6 @@ import com.tommytony.war.WarHub;
import com.tommytony.war.Warzone;
import com.tommytony.war.jobs.RestoreWarhubJob;
import com.tommytony.war.jobs.RestoreWarzonesJob;
import com.tommytony.war.volumes.Volume;
/**
*
@ -176,7 +173,9 @@ public class WarMapper {
HashMap<Integer, ItemStack> items = war.getDefaultLoadout();
for(Integer slot : items.keySet()) {
ItemStack item = items.get(slot);
defaultLoadoutStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
if(item != null) {
defaultLoadoutStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
}
warConfig.setString("defaultLoadout", defaultLoadoutStr);
@ -215,7 +214,9 @@ public class WarMapper {
HashMap<Integer, ItemStack> rewardItems = war.getDefaultReward();
for(Integer slot : rewardItems.keySet()) {
ItemStack item = items.get(slot);
defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
if(item != null) {
defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
}
warConfig.setString("defaultReward", defaultRewardStr);

View File

@ -381,7 +381,9 @@ public class WarzoneMapper {
HashMap<Integer, ItemStack> items = warzone.getLoadout();
for(Integer slot : items.keySet()) {
ItemStack item = items.get(slot);
loadoutStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
if(item != null) {
loadoutStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
}
warzoneConfig.setString("loadout", loadoutStr);
@ -411,7 +413,9 @@ public class WarzoneMapper {
HashMap<Integer, ItemStack> rewardItems = warzone.getReward();
for(Integer slot : rewardItems.keySet()) {
ItemStack item = rewardItems.get(slot);
rewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
if(item != null) {
rewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
}
}
warzoneConfig.setString("reward", rewardStr);

View File

@ -1,6 +1,5 @@
package com.tommytony.war.volumes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -16,12 +15,11 @@ import org.bukkit.block.Dispenser;
import org.bukkit.block.Sign;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.tommytony.war.jobs.BlockResetJob;
import bukkit.tommytony.war.War;
import com.tommytony.war.jobs.BlockResetJob;
/**
*
* @author tommytony
@ -208,8 +206,10 @@ public class Volume {
int ii = 0;
chest.getInventory().clear();
for(ItemStack item : contents) {
chest.getInventory().setItem(ii, item);
ii++;
if(item != null) {
chest.getInventory().setItem(ii, item);
ii++;
}
}
chest.update(true);
}
@ -226,8 +226,10 @@ public class Volume {
int ii = 0;
dispenser.getInventory().clear();
for(ItemStack item : contents) {
dispenser.getInventory().setItem(ii, item);
ii++;
if(item != null) {
dispenser.getInventory().setItem(ii, item);
ii++;
}
}
dispenser.update(true);
}

View File

@ -1,5 +1,5 @@
name: War
version: 1.4.1 (Slim)
version: 1.4.2 (Slim)
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com

View File

@ -1,5 +1,5 @@
name: War
version: 1.4.1 (Slim)
version: 1.4.2 (Slim)
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com