mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-30 05:53:39 +01:00
Optimized Stacking task & Added no-stack metadata for killed entities.
This commit is contained in:
parent
667063a816
commit
791b790247
@ -1,6 +1,8 @@
|
||||
package com.songoda.ultimatestacker.events;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
import com.songoda.ultimatestacker.spawner.SpawnerStack;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.Location;
|
||||
@ -13,6 +15,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class StackingTask extends BukkitRunnable {
|
||||
|
||||
@ -115,18 +116,17 @@ public class StackingTask extends BukkitRunnable {
|
||||
if (configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size") != -1)
|
||||
maxEntityStackSize = configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size");
|
||||
|
||||
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity);
|
||||
List<Entity> entityList = Methods.getSimilarEntitesAroundEntity(initalEntity).stream().filter(entity ->
|
||||
!entity.hasMetadata("no-stack")
|
||||
&& entity.getCustomName() == null
|
||||
&& stackManager.getStack(entity) != null
|
||||
&& removed.contains(entity.getUniqueId())).collect(Collectors.toList());
|
||||
|
||||
for (Entity entity : new ArrayList<>(entityList)) {
|
||||
if (removed.contains(entity.getUniqueId())) continue;
|
||||
for (Entity entity : entityList) {
|
||||
EntityStack stack = stackManager.getStack(entity);
|
||||
if (stack == null && entity.getCustomName() != null) {
|
||||
entityList.remove(entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
//If a stack was found add 1 to this stack.
|
||||
if (stack != null && (stack.getAmount() + amtToStack) <= maxEntityStackSize) {
|
||||
if ((stack.getAmount() + amtToStack) <= maxEntityStackSize) {
|
||||
stack.addAmount(amtToStack);
|
||||
stack.updateStack();
|
||||
removed.add(initalEntity.getUniqueId());
|
||||
|
@ -41,6 +41,7 @@ public class Methods {
|
||||
UltimateStacker instance = UltimateStacker.getInstance();
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
Entity newEntity = newEntity(killed);
|
||||
killed.setMetadata("no-stack", new FixedMetadataValue(instance, true));
|
||||
|
||||
((LivingEntity) newEntity).getEquipment().clear();
|
||||
|
||||
@ -83,12 +84,11 @@ public class Methods {
|
||||
if(lastDamageCause != null) {
|
||||
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
||||
for(String s : reasons) {
|
||||
if(cause.name().equalsIgnoreCase(s)) {
|
||||
if(!cause.name().equalsIgnoreCase(s)) continue;
|
||||
handleWholeStackDeath(killed, stack, items, droppedExp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
handleSingleStackDeath(killed);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user