From 71f9636e07f6b270d1783982f4fbbf321b717fb1 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Tue, 10 Sep 2019 13:11:12 -0500 Subject: [PATCH] fix null errors, migrate internal API to new methods --- .../ultimatestacker/UltimateStacker.java | 16 +++++++-------- .../listeners/ItemListeners.java | 20 +++++++++---------- .../ultimatestacker/utils/Methods.java | 4 ++-- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index f88bef6..e27b2c5 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -445,15 +445,13 @@ public class UltimateStacker extends SongodaPlugin { * @return true if this material will not stack */ public static boolean isMaterialBlacklisted(ItemStack item) { - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) { - return isMaterialBlacklisted(item.getType()); + CompatibleMaterial mat = CompatibleMaterial.getMaterial(item); + if(mat == null) { + return true; + } else if (mat.usesData()) { + return isMaterialBlacklisted(mat.getMaterial(), mat.getData()); } else { - CompatibleMaterial mat = CompatibleMaterial.getMaterial(item); - if (mat.usesData()) { - return isMaterialBlacklisted(mat.getMaterial(), mat.getData()); - } else { - return isMaterialBlacklisted(mat.getMaterial()); - } + return isMaterialBlacklisted(mat.getMaterial()); } } @@ -461,7 +459,7 @@ public class UltimateStacker extends SongodaPlugin { * Check to see if this material is not permitted to stack * * @param type Material to check - * @param data daya value for this item (for 1.12 and older servers) + * @param data data value for this item (for 1.12 and older servers) * @return true if this material will not stack */ public static boolean isMaterialBlacklisted(Material type, byte data) { diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java index f72440b..cf3f165 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ItemListeners.java @@ -1,7 +1,6 @@ package com.songoda.ultimatestacker.listeners; import com.songoda.core.compatibility.CompatibleSound; -import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.utils.BlockUtils; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.settings.Settings; @@ -37,28 +36,27 @@ public class ItemListeners implements Listener { event.setCancelled(true); int specific = instance.getItemFile().getInt("Items." + itemStack.getType().name() + ".Max Stack Size"); - int max = specific == -1 && new ItemStack(itemStack.getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific; + int max; - if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) && Methods.isMaterialBlacklisted(itemStack.getType())) - max = new ItemStack(itemStack.getType()).getMaxStackSize(); - - if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) && Methods.isMaterialBlacklisted(itemStack.getType(), itemStack.getData().getData())) + if (UltimateStacker.isMaterialBlacklisted(itemStack)) max = new ItemStack(itemStack.getType()).getMaxStackSize(); + else + max = specific == -1 && new ItemStack(itemStack.getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific; if (max == -1) max = 1; - int newAmount = Methods.getActualItemAmount(event.getEntity()) - + Methods.getActualItemAmount(item); + int newAmount = UltimateStacker.getActualItemAmount(event.getEntity()) + + UltimateStacker.getActualItemAmount(item); if (newAmount > max) return; - Methods.updateItemAmount(item, itemStack, newAmount); + UltimateStacker.updateItemAmount(item, itemStack, newAmount); event.getEntity().remove(); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInvPickup(InventoryPickupItemEvent event) { - if (!Settings.STACK_ITEMS.getBoolean() || !Methods.hasCustomAmount(event.getItem())) return; + if (!Settings.STACK_ITEMS.getBoolean() || !UltimateStacker.hasCustomAmount(event.getItem())) return; event.setCancelled(true); Methods.updateInventory(event.getItem(), event.getInventory()); @@ -77,7 +75,7 @@ public class ItemListeners implements Listener { return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/ } - Methods.updateItemAmount(event.getEntity(), itemStack, event.getEntity().getItemStack().getAmount()); + UltimateStacker.updateItemAmount(event.getEntity(), itemStack, event.getEntity().getItemStack().getAmount()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) diff --git a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java index 48ae95a..ddc7b36 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/Methods.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/Methods.java @@ -32,7 +32,7 @@ import org.bukkit.util.Vector; public class Methods { public static void updateInventory(Item item, Inventory inventory) { - int amount = Methods.getActualItemAmount(item); + int amount = UltimateStacker.getActualItemAmount(item); ItemStack itemStack = item.getItemStack(); final int maxStack = itemStack.getMaxStackSize(); @@ -51,7 +51,7 @@ public class Methods { if (amount <= 0) item.remove(); else - Methods.updateItemAmount(item, itemStack, amount); + UltimateStacker.updateItemAmount(item, itemStack, amount); } // Do not touch! API for older plugins