Skip to content

Commit

Permalink
1.8.8 backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 7, 2018
1 parent 32cc268 commit d0d4d9b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
14 changes: 10 additions & 4 deletions src/main/java/net/citizensnpcs/api/trait/trait/Equipment.java
Expand Up @@ -122,13 +122,16 @@ public void onSpawn() {
} else {
EntityEquipment equip = getEquipmentFromEntity(npc.getEntity());
if (equipment[0] != null) {
equip.setItemInMainHand(equipment[0]);
equip.setItemInHand(equipment[0]);
}
equip.setHelmet(equipment[1]);
equip.setChestplate(equipment[2]);
equip.setLeggings(equipment[3]);
equip.setBoots(equipment[4]);
equip.setItemInOffHand(equipment[5]);
try {
equip.setItemInOffHand(equipment[5]);
} catch (NoSuchMethodError e) {
}
}
if (npc.getEntity() instanceof Player) {
((Player) npc.getEntity()).updateInventory();
Expand Down Expand Up @@ -186,7 +189,7 @@ public void set(int slot, ItemStack item) {
EntityEquipment equip = getEquipmentFromEntity(npc.getEntity());
switch (slot) {
case 0:
equip.setItemInMainHand(item);
equip.setItemInHand(item);
break;
case 1:
equip.setHelmet(item);
Expand All @@ -201,7 +204,10 @@ public void set(int slot, ItemStack item) {
equip.setBoots(item);
break;
case 5:
equip.setItemInOffHand(item);
try {
equip.setItemInOffHand(item);
} catch (NoSuchMethodError e) {
}
break;
default:
throw new IllegalArgumentException("Slot must be between 0 and 5");
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/net/citizensnpcs/api/trait/trait/Inventory.java
Expand Up @@ -67,8 +67,13 @@ public void inventoryCloseEvent(InventoryCloseEvent event) {
}
}
if (npc.getEntity() instanceof InventoryHolder) {
int maxSize = ((InventoryHolder) npc.getEntity()).getInventory().getStorageContents().length;
((InventoryHolder) npc.getEntity()).getInventory().setStorageContents(Arrays.copyOf(contents, maxSize));
try {
int maxSize = ((InventoryHolder) npc.getEntity()).getInventory().getStorageContents().length;
((InventoryHolder) npc.getEntity()).getInventory().setStorageContents(Arrays.copyOf(contents, maxSize));
} catch (NoSuchMethodError e) {
int maxSize = ((InventoryHolder) npc.getEntity()).getInventory().getContents().length;
((InventoryHolder) npc.getEntity()).getInventory().setContents(Arrays.copyOf(contents, maxSize));
}
}
views.remove(event.getView());
}
Expand All @@ -88,8 +93,7 @@ public void onSpawn() {
setContents(contents);
int size = npc.getEntity() instanceof Player ? 36
: npc.getEntity() instanceof InventoryHolder
? ((InventoryHolder) npc.getEntity()).getInventory().getSize()
: contents.length;
? ((InventoryHolder) npc.getEntity()).getInventory().getSize() : contents.length;
int rem = size % 9;
if (rem != 0) {
size += 9 - rem; // round up to nearest multiple of 9
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/net/citizensnpcs/api/util/ItemStorage.java
Expand Up @@ -176,9 +176,12 @@ private static void deserialiseMeta(DataKey root, ItemStack res) {

if (root.keyExists("potion")) {
PotionMeta meta = ensureMeta(res);
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")),
root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
try {
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")),
root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
} catch (Throwable t) {
}
for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
int duration = sub.getInt("duration");
int amplifier = sub.getInt("amplifier");
Expand Down Expand Up @@ -392,11 +395,14 @@ private static void serialiseMeta(DataKey key, ItemMeta meta) {

if (meta instanceof PotionMeta) {
PotionMeta potion = (PotionMeta) meta;
PotionData data = potion.getBasePotionData();
List<PotionEffect> effects = potion.getCustomEffects();
key.setBoolean("potion.data.extended", data.isExtended());
key.setBoolean("potion.data.upgraded", data.isUpgraded());
key.setString("potion.data.type", data.getType().name());
try {
PotionData data = potion.getBasePotionData();
key.setBoolean("potion.data.extended", data.isExtended());
key.setBoolean("potion.data.upgraded", data.isUpgraded());
key.setString("potion.data.type", data.getType().name());
} catch (Throwable t) {
}
key.removeKey("potion.effects");
DataKey effectKey = key.getRelative("potion.effects");
for (int i = 0; i < effects.size(); i++) {
Expand Down

0 comments on commit d0d4d9b

Please sign in to comment.