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,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) {

View File

@ -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)

View File

@ -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