mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-12-02 15:03:24 +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;
|
package com.songoda.ultimatestacker.events;
|
||||||
|
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
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.spawner.SpawnerStack;
|
||||||
import com.songoda.ultimatestacker.utils.Methods;
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -13,6 +15,7 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StackingTask extends BukkitRunnable {
|
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)
|
if (configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size") != -1)
|
||||||
maxEntityStackSize = configurationSection.getInt("Mobs." + initalEntity.getType().name() + ".Max Stack Size");
|
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)) {
|
for (Entity entity : entityList) {
|
||||||
if (removed.contains(entity.getUniqueId())) continue;
|
|
||||||
EntityStack stack = stackManager.getStack(entity);
|
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 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.addAmount(amtToStack);
|
||||||
stack.updateStack();
|
stack.updateStack();
|
||||||
removed.add(initalEntity.getUniqueId());
|
removed.add(initalEntity.getUniqueId());
|
||||||
|
@ -41,6 +41,7 @@ public class Methods {
|
|||||||
UltimateStacker instance = UltimateStacker.getInstance();
|
UltimateStacker instance = UltimateStacker.getInstance();
|
||||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||||
Entity newEntity = newEntity(killed);
|
Entity newEntity = newEntity(killed);
|
||||||
|
killed.setMetadata("no-stack", new FixedMetadataValue(instance, true));
|
||||||
|
|
||||||
((LivingEntity) newEntity).getEquipment().clear();
|
((LivingEntity) newEntity).getEquipment().clear();
|
||||||
|
|
||||||
@ -83,10 +84,9 @@ public class Methods {
|
|||||||
if(lastDamageCause != null) {
|
if(lastDamageCause != null) {
|
||||||
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
||||||
for(String s : reasons) {
|
for(String s : reasons) {
|
||||||
if(cause.name().equalsIgnoreCase(s)) {
|
if(!cause.name().equalsIgnoreCase(s)) continue;
|
||||||
handleWholeStackDeath(killed, stack, items, droppedExp);
|
handleWholeStackDeath(killed, stack, items, droppedExp);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handleSingleStackDeath(killed);
|
handleSingleStackDeath(killed);
|
||||||
|
Loading…
Reference in New Issue
Block a user