Added whitelist for items and fixed issue with non custom drops.

This commit is contained in:
Brianna 2019-08-12 20:59:32 -04:00
parent 8a39d51ad9
commit 2c2faf170f
6 changed files with 36 additions and 34 deletions

View File

@ -131,7 +131,7 @@ public class EntityStack {
UltimateStacker.getInstance().addExp(killed.getKiller(), this);
}
private void handleSingleStackDeath(LivingEntity killed) {
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops) {
EntityStackManager stackManager = plugin.getEntityStackManager();
LivingEntity newEntity = plugin.getEntityUtils().newEntity(killed);
@ -152,6 +152,8 @@ public class EntityStack {
newEntity.setMetadata(entityMetadataKey, new FixedMetadataValue(UltimateStacker.getInstance(), true));
}
DropUtils.processStackedDrop(killed, drops);
EntityStack entityStack = stackManager.updateStack(killed, newEntity);
entityStack.addAmount(-1);
@ -185,7 +187,7 @@ public class EntityStack {
return;
}
}
handleSingleStackDeath(killed);
handleSingleStackDeath(killed, drops);
}
}

View File

@ -3,7 +3,6 @@ package com.songoda.ultimatestacker.listeners;
import com.songoda.lootables.loot.Drop;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.utils.DropUtils;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -27,22 +26,14 @@ public class DeathListeners implements Listener {
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity() instanceof Player) return;
List<Drop> drops = instance.getLootablesManager().getDrops(event.getEntity());
boolean custom = Setting.CUSTOM_DROPS.getBoolean();
List<Drop> drops = custom ? instance.getLootablesManager().getDrops(event.getEntity()) : new ArrayList<>();
boolean custom = false;
if (Setting.CUSTOM_DROPS.getBoolean()) {
event.getDrops().clear();
for (Drop drop : drops) {
if (drop == null) continue;
DropUtils.processDrop(event.getEntity(), drop);
}
custom = true;
} else {
if (!custom) {
for (ItemStack item : event.getDrops())
drops.add(new Drop(item));
}
event.getDrops().clear();
if (instance.getEntityStackManager().isStacked(event.getEntity()))
instance.getEntityStackManager().getStack(event.getEntity())

View File

@ -67,8 +67,7 @@ public class EntityListeners implements Listener {
EntityStack stack = stackManager.getStack(entity);
ItemStack item = event.getEntity().getItemStack();
item.setAmount((stack.getAmount() - 1) + item.getAmount() > item.getMaxStackSize() ? item.getMaxStackSize()
: item.getAmount() + (stack.getAmount() - 1));
item.setAmount(Math.min((stack.getAmount() - 1) + item.getAmount(), item.getMaxStackSize()));
event.getEntity().setItemStack(item);
}

View File

@ -5,8 +5,6 @@ import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
@ -16,11 +14,9 @@ import org.bukkit.event.entity.ItemMergeEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import java.util.Map;
import java.util.List;
public class ItemListeners implements Listener {
@ -35,12 +31,18 @@ public class ItemListeners implements Listener {
int maxItemStackSize = Setting.MAX_STACK_ITEMS.getInt();
if (!Setting.STACK_ITEMS.getBoolean()) return;
Item item = event.getTarget();
ItemStack itemStack = item.getItemStack();
event.setCancelled(true);
Item item = event.getTarget();
int specific = instance.getItemFile().getConfig().getInt("Items." + itemStack.getType().name() + ".Max Stack Size");
int max = specific == -1 && new ItemStack(itemStack.getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific;
int specific = instance.getItemFile().getConfig().getInt("Items." + item.getItemStack().getType().name() + ".Max Stack Size");
int max = specific == -1 && new ItemStack(item.getItemStack().getType()).getMaxStackSize() != 1 ? maxItemStackSize : specific;
List<String> whitelist = Setting.ITEM_WHITELIST.getStringList();
if (!whitelist.isEmpty() && !whitelist.contains(itemStack.getType().name())) {
max = new ItemStack(itemStack.getType()).getMaxStackSize();
}
if (max == -1) max = 1;
@ -49,7 +51,7 @@ public class ItemListeners implements Listener {
if (newAmount > max) return;
Methods.updateItemAmount(item, newAmount);
Methods.updateItemAmount(item, itemStack, newAmount);
event.getEntity().remove();
}
@ -74,7 +76,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(), event.getEntity().getItemStack().getAmount());
Methods.updateItemAmount(event.getEntity(), itemStack, event.getEntity().getItemStack().getAmount());
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)

View File

@ -21,11 +21,12 @@ public class Methods {
public static void updateInventory(Item item, Inventory inventory) {
int amount = Methods.getActualItemAmount(item);
ItemStack itemStack = item.getItemStack();
while (amount > 0) {
int subtract = Math.min(amount, 64);
amount -= subtract;
ItemStack newItem = item.getItemStack().clone();
ItemStack newItem = itemStack.clone();
newItem.setAmount(subtract);
Map<Integer, ItemStack> result = inventory.addItem(newItem);
if (result.get(0) != null) {
@ -37,21 +38,21 @@ public class Methods {
if (amount <= 0)
item.remove();
else
Methods.updateItemAmount(item, amount);
Methods.updateItemAmount(item, itemStack, amount);
}
public static void updateItemAmount(Item item, int newAmount) {
public static void updateItemAmount(Item item, ItemStack itemStack, int newAmount) {
UltimateStacker plugin = UltimateStacker.getInstance();
Material material = item.getItemStack().getType();
Material material = itemStack.getType();
String name = Methods.convertToInvisibleString("IS") +
compileItemName(item.getItemStack(), newAmount);
compileItemName(itemStack, newAmount);
if (newAmount > 32) {
item.setMetadata("US_AMT", new FixedMetadataValue(plugin, newAmount));
item.getItemStack().setAmount(32);
itemStack.setAmount(32);
} else {
item.removeMetadata("US_AMT", plugin);
item.getItemStack().setAmount(newAmount);
itemStack.setAmount(newAmount);
}
if (plugin.getItemFile().getConfig().getBoolean("Items." + material + ".Has Hologram")

View File

@ -4,7 +4,9 @@ import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.Check;
import com.songoda.ultimatestacker.entity.Split;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -152,6 +154,11 @@ public enum Setting {
"This is added only because it looks smoother in game. This is only visual and",
"doesn't actually effect the item."),
ITEM_WHITELIST("Items.Whitelist", new ArrayList(),
"Items included in this whitelist will be stacked.",
"Material list: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html",
"Leave this empty by using \"whitelist: []\" if you want everything to be stacked."),
SHOW_STACK_SIZE_SINGLE("Items.Show Stack Size For Single", false,
"When enabled stack sizes for a stack with a single item will",
"not display the stack size. The stack size will be added",