fix null errors, migrate internal API to new methods

This commit is contained in:
jascotty2 2019-09-10 13:11:12 -05:00
parent 413c26c914
commit 71f9636e07
3 changed files with 18 additions and 22 deletions

View File

@ -445,23 +445,21 @@ public class UltimateStacker extends SongodaPlugin {
* @return true if this material will not stack * @return true if this material will not stack
*/ */
public static boolean isMaterialBlacklisted(ItemStack item) { public static boolean isMaterialBlacklisted(ItemStack item) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
return isMaterialBlacklisted(item.getType());
} else {
CompatibleMaterial mat = CompatibleMaterial.getMaterial(item); CompatibleMaterial mat = CompatibleMaterial.getMaterial(item);
if (mat.usesData()) { if(mat == null) {
return true;
} else if (mat.usesData()) {
return isMaterialBlacklisted(mat.getMaterial(), mat.getData()); return isMaterialBlacklisted(mat.getMaterial(), mat.getData());
} else { } else {
return isMaterialBlacklisted(mat.getMaterial()); return isMaterialBlacklisted(mat.getMaterial());
} }
} }
}
/** /**
* Check to see if this material is not permitted to stack * Check to see if this material is not permitted to stack
* *
* @param type Material to check * @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 * @return true if this material will not stack
*/ */
public static boolean isMaterialBlacklisted(Material type, byte data) { public static boolean isMaterialBlacklisted(Material type, byte data) {

View File

@ -1,7 +1,6 @@
package com.songoda.ultimatestacker.listeners; package com.songoda.ultimatestacker.listeners;
import com.songoda.core.compatibility.CompatibleSound; import com.songoda.core.compatibility.CompatibleSound;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.utils.BlockUtils; import com.songoda.core.utils.BlockUtils;
import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings; import com.songoda.ultimatestacker.settings.Settings;
@ -37,28 +36,27 @@ public class ItemListeners implements Listener {
event.setCancelled(true); event.setCancelled(true);
int specific = instance.getItemFile().getInt("Items." + itemStack.getType().name() + ".Max Stack Size"); 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())) if (UltimateStacker.isMaterialBlacklisted(itemStack))
max = new ItemStack(itemStack.getType()).getMaxStackSize();
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) && Methods.isMaterialBlacklisted(itemStack.getType(), itemStack.getData().getData()))
max = new ItemStack(itemStack.getType()).getMaxStackSize(); max = new ItemStack(itemStack.getType()).getMaxStackSize();
else
max = specific == -1 && new ItemStack(itemStack.getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific;
if (max == -1) max = 1; if (max == -1) max = 1;
int newAmount = Methods.getActualItemAmount(event.getEntity()) int newAmount = UltimateStacker.getActualItemAmount(event.getEntity())
+ Methods.getActualItemAmount(item); + UltimateStacker.getActualItemAmount(item);
if (newAmount > max) return; if (newAmount > max) return;
Methods.updateItemAmount(item, itemStack, newAmount); UltimateStacker.updateItemAmount(item, itemStack, newAmount);
event.getEntity().remove(); event.getEntity().remove();
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onInvPickup(InventoryPickupItemEvent event) { 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); event.setCancelled(true);
Methods.updateInventory(event.getItem(), event.getInventory()); 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/ 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) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

View File

@ -32,7 +32,7 @@ import org.bukkit.util.Vector;
public class Methods { public class Methods {
public static void updateInventory(Item item, Inventory inventory) { public static void updateInventory(Item item, Inventory inventory) {
int amount = Methods.getActualItemAmount(item); int amount = UltimateStacker.getActualItemAmount(item);
ItemStack itemStack = item.getItemStack(); ItemStack itemStack = item.getItemStack();
final int maxStack = itemStack.getMaxStackSize(); final int maxStack = itemStack.getMaxStackSize();
@ -51,7 +51,7 @@ public class Methods {
if (amount <= 0) if (amount <= 0)
item.remove(); item.remove();
else else
Methods.updateItemAmount(item, itemStack, amount); UltimateStacker.updateItemAmount(item, itemStack, amount);
} }
// Do not touch! API for older plugins // Do not touch! API for older plugins