Re-add event

This commit is contained in:
ceze88 2023-07-08 11:15:54 +02:00
parent 250435cfa0
commit 79e5680c46

View File

@ -1,8 +1,11 @@
package com.craftaro.ultimatestacker.listeners.item;
import com.craftaro.core.nms.NmsManager;
import com.craftaro.core.third_party.org.apache.commons.lang3.StringUtils;
import com.craftaro.ultimatestacker.UltimateStacker;
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
import com.craftaro.ultimatestacker.api.stack.item.StackedItem;
import com.craftaro.ultimatestacker.api.stack.item.StackedItemManager;
import com.craftaro.ultimatestacker.settings.Settings;
import com.craftaro.ultimatestacker.utils.Methods;
import org.bukkit.block.Block;
@ -10,7 +13,11 @@ import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import java.util.List;
public class ItemListeners implements Listener {
@ -51,30 +58,30 @@ public class ItemListeners implements Listener {
//Do we need this?
//@EventHandler
// public void onExist(ItemSpawnEvent event) {
// if (!Settings.STACK_ITEMS.getBoolean()) return;
//
// List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
// if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr)))
// return;
//
// ItemStack itemStack = event.getEntity().getItemStack();
//
// if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
// StringUtils.substring(itemStack.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
// return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
// }
//
// StackedItemManager itemStackManager = UltimateStackerAPI.getStackedItemManager();
//
// if (itemStackManager.isStackedItem(event.getEntity())) {
// StackedItem stackedItem = UltimateStacker.getInstance().getStackedItemManager().getStackedItem(event.getEntity());
// stackedItem.setAmount(stackedItem.getAmount() + itemStack.getAmount());
// UltimateStacker.updateItemAmount(event.getEntity(), itemStack, UltimateStacker.getActualItemAmount(event.getEntity()) + itemStack.getAmount());
// } else {
// UltimateStacker.updateItemAmount(event.getEntity(), itemStack, itemStack.getAmount());
// }
//
// }
@EventHandler
public void onExist(ItemSpawnEvent event) {
if (!Settings.STACK_ITEMS.getBoolean()) return;
List<String> disabledWorlds = Settings.DISABLED_WORLDS.getStringList();
if (disabledWorlds.stream().anyMatch(worldStr -> event.getEntity().getWorld().getName().equalsIgnoreCase(worldStr)))
return;
ItemStack itemStack = event.getEntity().getItemStack();
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() &&
StringUtils.substring(itemStack.getItemMeta().getDisplayName(), 0, 3).equals("***")) {
return; //Compatibility with Shop instance: https://www.spigotmc.org/resources/shop-a-simple-intuitive-shop-instance.9628/
}
StackedItemManager itemStackManager = UltimateStackerApi.getStackedItemManager();
if (itemStackManager.isStackedItem(event.getEntity())) {
StackedItem stackedItem = UltimateStacker.getInstance().getStackedItemManager().getStackedItem(event.getEntity());
stackedItem.setAmount(stackedItem.getAmount() + itemStack.getAmount());
UltimateStackerApi.getStackedItemManager().createStack(event.getEntity(), UltimateStackerApi.getStackedItemManager().getActualItemAmount(event.getEntity()) + itemStack.getAmount());
} else {
UltimateStackerApi.getStackedItemManager().createStack(event.getEntity(), itemStack.getAmount());
}
}
}