Browse Source

Always check for empty arrays. For loop processes them.

combat-2
MagicBot 9 months ago
parent
commit
839be1f28f
  1. 15
      src/engine/objects/ItemTemplate.java

15
src/engine/objects/ItemTemplate.java

@ -78,9 +78,10 @@ public class ItemTemplate { @@ -78,9 +78,10 @@ public class ItemTemplate {
obj_name = (String) jsonObject.get("obj_name");
// Reading floats from an array
// Reading floats from an array (note always check for empty arrays)
JSONArray scaleData = (JSONArray) jsonObject.get("obj_scale");
if (scaleData.isEmpty() == false)
obj_scale = new Vector3fImmutable(((Double) scaleData.get(0)).floatValue(), ((Double) scaleData.get(1)).floatValue(),
((Double) scaleData.get(2)).floatValue());
@ -131,10 +132,10 @@ public class ItemTemplate { @@ -131,10 +132,10 @@ public class ItemTemplate {
item_render_object_female = ((Long) jsonObject.get("item_render_object_female")).intValue();
item_health_full = ((Double) jsonObject.get("item_health_full")).floatValue();
Object skills_used = jsonObject.get("item_skill_used");
Object skill_used = jsonObject.get("item_skill_used");
if (skills_used instanceof String) {
String skilString = (String) skills_used;
if (skill_used instanceof String) {
String skilString = (String) skill_used;
skilString = skilString.replaceAll("\\s", "");
skilString = skilString.replaceAll(",", "");
item_skill_used.add(Enum.CharacterSkills.valueOf(skilString));
@ -171,6 +172,7 @@ public class ItemTemplate { @@ -171,6 +172,7 @@ public class ItemTemplate {
JSONArray weapon_damage = (JSONArray) item_weapon.get("weapon_damage");
if (weapon_damage.isEmpty() == false)
for (Object o : weapon_damage) {
JSONObject damage_entry = (JSONObject) o;
Enum.SourceType sourceType = Enum.SourceType.valueOf(((String) damage_entry.get("damage_type")).toUpperCase());
@ -200,6 +202,7 @@ public class ItemTemplate { @@ -200,6 +202,7 @@ public class ItemTemplate {
JSONArray skill_required = (JSONArray) jsonObject.get("item_skill_req");
if (skill_required.isEmpty() == false)
for (Object o : skill_required) {
JSONObject skill_req = (JSONObject) o;
String skill_type = (String) skill_req.get("skill_type");
@ -213,6 +216,7 @@ public class ItemTemplate { @@ -213,6 +216,7 @@ public class ItemTemplate {
boolean restrict = ((Boolean) race_required.get("restrict"));
JSONArray races = (JSONArray) race_required.get("races");
if (races.isEmpty() == false)
for (Object o : races) {
String race = (String) o;
race = race.replaceAll("\\s", "");
@ -229,6 +233,7 @@ public class ItemTemplate { @@ -229,6 +233,7 @@ public class ItemTemplate {
restrict = ((Boolean) class_required.get("restrict"));
JSONArray classes = (JSONArray) class_required.get("classes");
if (classes.isEmpty() == false)
for (Object o : classes) {
String classEntry = (String) o;
classEntry = classEntry.replaceAll("\\s", "");
@ -244,6 +249,7 @@ public class ItemTemplate { @@ -244,6 +249,7 @@ public class ItemTemplate {
restrict = ((Boolean) disc_required.get("restrict"));
JSONArray discs = (JSONArray) disc_required.get("discs");
if (discs.isEmpty() == false)
for (Object o : discs) {
String disc = (String) o;
disc = disc.replaceAll("\\s", "");
@ -260,6 +266,7 @@ public class ItemTemplate { @@ -260,6 +266,7 @@ public class ItemTemplate {
JSONArray powerActions = (JSONArray) jsonObject.get("item_user_power_action");
if (powerActions.isEmpty() == false)
for (Object o : powerActions) {
JSONObject powerActionEntry = (JSONObject) o;
String power = (String) powerActionEntry.get("power");

Loading…
Cancel
Save