Skip to content

Commit

Permalink
Fix #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Darcy Chen committed Mar 3, 2018
1 parent 6c3b5ce commit ba4015d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
}

group = 'net.huskycraft'
version = '0.4.0'
description = 'Major redesign of internal structure and add support of MOD items'
version = '0.4.1'
description = 'Fix NSE exception if an equipment slot is left empty when creating kit'

dependencies {
compile 'org.spongepowered:spongeapi:7.0.0'
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = 'blockyarena'
rootProject.name = 'blockyarena'


2 changes: 1 addition & 1 deletion src/main/java/net/huskycraft/blockyarena/BlockyArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Arrays;
import java.util.List;

@Plugin(id = "blockyarena", name = "BlockyArena", version = "0.4.0")
@Plugin(id = "blockyarena", name = "BlockyArena", version = "0.4.1")
public class BlockyArena {
@Inject
private Logger logger;
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/net/huskycraft/blockyarena/utils/KitSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public KitSerializer(BlockyArena plugin) {
@Override
public Kit deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
String id = value.getNode("id").getString();
Optional<ItemStack> headwear = Optional.of(value.getNode("headwear").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> chestplate = Optional.of(value.getNode("chestplate").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> leggings = Optional.of(value.getNode("leggings").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> boots = Optional.of(value.getNode("boots").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> offHand = Optional.of(value.getNode("offHand").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> headwear = Optional.ofNullable(
value.getNode("headwear").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> chestplate = Optional.ofNullable(
value.getNode("chestplate").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> leggings = Optional.ofNullable(
value.getNode("leggings").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> boots = Optional.ofNullable(
value.getNode("boots").getValue(TypeToken.of(ItemStack.class)));
Optional<ItemStack> offHand = Optional.ofNullable(
value.getNode("offHand").getValue(TypeToken.of(ItemStack.class)));
Map<SlotIndex, ItemStack> main = new HashMap<>();
for (ConfigurationNode indexNode : value.getNode("main").getChildrenMap().values()) {
SlotIndex index = SlotIndex.of(indexNode.getKey());
Expand All @@ -40,11 +45,11 @@ public Kit deserialize(TypeToken<?> type, ConfigurationNode value) throws Object
@Override
public void serialize(TypeToken<?> type, Kit obj, ConfigurationNode value) throws ObjectMappingException {
value.getNode("id").setValue(obj.getId());
value.getNode("headwear").setValue(TypeToken.of(ItemStack.class), obj.getHeadwear().get());
value.getNode("chestplate").setValue(TypeToken.of(ItemStack.class), obj.getChestplate().get());
value.getNode("leggings").setValue(TypeToken.of(ItemStack.class), obj.getLeggings().get());
value.getNode("boots").setValue(TypeToken.of(ItemStack.class), obj.getBoots().get());
value.getNode("offHand").setValue(TypeToken.of(ItemStack.class), obj.getOffHand().get());
value.getNode("headwear").setValue(TypeToken.of(ItemStack.class), obj.getHeadwear().orElse(null));
value.getNode("chestplate").setValue(TypeToken.of(ItemStack.class), obj.getChestplate().orElse(null));
value.getNode("leggings").setValue(TypeToken.of(ItemStack.class), obj.getLeggings().orElse(null));
value.getNode("boots").setValue(TypeToken.of(ItemStack.class), obj.getBoots().orElse(null));
value.getNode("offHand").setValue(TypeToken.of(ItemStack.class), obj.getOffHand().orElse(null));
for (SlotIndex index : obj.getMain().keySet()) {
ConfigurationNode itemNode = value.getNode("main").getNode(index.getValue().toString());
itemNode.setValue(TypeToken.of(ItemStack.class), obj.getMain().get(index));
Expand Down

0 comments on commit ba4015d

Please sign in to comment.