Fix pre stacking items

This commit is contained in:
ceze88 2022-12-29 11:50:51 +01:00
parent 1a911ee085
commit 17fb03f073

View File

@ -1,5 +1,6 @@
package com.songoda.core.lootables.loot;
import com.bgsoftware.wildstacker.api.objects.StackedItem;
import com.songoda.core.SongodaCore;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.settings.Settings;
@ -69,30 +70,25 @@ public class DropUtils {
private static void dropItems(List<ItemStack> items, EntityDeathEvent event) {
if (SongodaCore.isRegistered("UltimateStacker")) {
List<StackedItem> stacks = new ArrayList<>();
int maxSize = Settings.MAX_STACK_ITEMS.getInt();
for (ItemStack item : items) {
if (stacks.isEmpty()) {
StackedItem stack = stacks.stream().filter(stackedItem -> stackedItem.getItem().getType() == item.getType()).findFirst().orElse(null);
if (stack == null) {
stacks.add(new StackedItem(item, item.getAmount()));
continue;
}
for (StackedItem stackedItem : stacks.toArray(new StackedItem[0])) {
if (stackedItem.getMaterial().equals(item.getType())) {
int newAmount = stackedItem.getAmount() + item.getAmount();
int maxSize = Settings.MAX_STACK_ITEMS.getInt();
while (newAmount > maxSize) {
newAmount -= maxSize;
stacks.add(new StackedItem(item, newAmount));
}
if (newAmount > 0) {
stacks.add(new StackedItem(item, newAmount));
}
} else {
stacks.add(new StackedItem(item, item.getAmount()));
}
int newAmount = stack.getAmount() + item.getAmount();
while (newAmount > maxSize) {
newAmount -= maxSize;
stacks.add(new StackedItem(item, maxSize));
}
stack.setamount(newAmount);
}
for (StackedItem stack : stacks) {
UltimateStacker.spawnStackedItem(stack.getItem(), stack.getAmount(), event.getEntity().getLocation());
}
Bukkit.getScheduler().runTask(UltimateStacker.getInstance(), () -> {
for (StackedItem stack : stacks) {
UltimateStacker.spawnStackedItem(stack.getItem(), stack.getAmount(), event.getEntity().getLocation());
}
});
return;
}
for (ItemStack item : items) {
@ -101,21 +97,24 @@ public class DropUtils {
}
private static void runCommands(LivingEntity entity, List<String> commands) {
for (String command : commands) {
if (entity.getKiller() != null) {
command = command.replace("%player%", entity.getKiller().getName());
}
Bukkit.getScheduler().runTask(SongodaCore.getHijackedPlugin(), () -> {
for (String command : commands) {
if (entity.getKiller() != null) {
command = command.replace("%player%", entity.getKiller().getName());
}
if (!command.contains("%player%")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
if (!command.contains("%player%")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
}
}
}
});
}
private static class StackedItem {
private final ItemStack item;
private final int amount;
private int amount;
public StackedItem(ItemStack item, int amount) {
this.item = item;
@ -133,5 +132,9 @@ public class DropUtils {
public int getAmount() {
return amount;
}
public void setamount(int amount) {
this.amount = amount;
}
}
}