Search in sources :

Example 1 with EntityStackClearEvent

use of dev.rosewood.rosestacker.event.EntityStackClearEvent in project RoseStacker by Rosewood-Development.

the class StackingThread method removeAllEntityStacks.

@Override
public int removeAllEntityStacks() {
    List<StackedEntity> toRemove = this.stackedEntities.values().stream().filter(x -> x.getEntity() != null && x.getEntity().getType() != EntityType.PLAYER).filter(x -> x.getStackSize() != 1 || Setting.MISC_CLEARALL_REMOVE_SINGLE.getBoolean()).collect(Collectors.toList());
    EntityStackClearEvent entityStackClearEvent = new EntityStackClearEvent(this.targetWorld, toRemove);
    Bukkit.getPluginManager().callEvent(entityStackClearEvent);
    if (entityStackClearEvent.isCancelled())
        return 0;
    toRemove.stream().map(StackedEntity::getEntity).forEach(this::setRemoved);
    toRemove.stream().map(StackedEntity::getEntity).forEach(LivingEntity::remove);
    this.stackedEntities.values().removeIf(toRemove::contains);
    return toRemove.size();
}
Also used : StackedEntityDataEntry(dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry) EntityUtils(dev.rosewood.rosestacker.utils.EntityUtils) Player(org.bukkit.entity.Player) ItemUtils(dev.rosewood.rosestacker.utils.ItemUtils) PreDropStackedItemsEvent(dev.rosewood.rosestacker.event.PreDropStackedItemsEvent) EntityStackSettings(dev.rosewood.rosestacker.stack.settings.EntityStackSettings) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) Block(org.bukkit.block.Block) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) PersistentDataUtils(dev.rosewood.rosestacker.utils.PersistentDataUtils) Chunk(org.bukkit.Chunk) ItemStackSettings(dev.rosewood.rosestacker.stack.settings.ItemStackSettings) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) Setting(dev.rosewood.rosestacker.manager.ConfigurationManager.Setting) Entity(org.bukkit.entity.Entity) Predicate(java.util.function.Predicate) ItemStackClearEvent(dev.rosewood.rosestacker.event.ItemStackClearEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) LivingEntity(org.bukkit.entity.LivingEntity) EntityCacheManager(dev.rosewood.rosestacker.manager.EntityCacheManager) Collectors(java.util.stream.Collectors) RosePlugin(dev.rosewood.rosegarden.RosePlugin) EntityUnstackEvent(dev.rosewood.rosestacker.event.EntityUnstackEvent) StackedEntityDataStorage(dev.rosewood.rosestacker.nms.storage.StackedEntityDataStorage) ItemStack(org.bukkit.inventory.ItemStack) Objects(java.util.Objects) StackManager(dev.rosewood.rosestacker.manager.StackManager) List(java.util.List) Entry(java.util.Map.Entry) BukkitTask(org.bukkit.scheduler.BukkitTask) Optional(java.util.Optional) StackerUtils(dev.rosewood.rosestacker.utils.StackerUtils) NPCsHook(dev.rosewood.rosestacker.hook.NPCsHook) DustOptions(org.bukkit.Particle.DustOptions) Item(org.bukkit.entity.Item) WorldGuardHook(dev.rosewood.rosestacker.hook.WorldGuardHook) HashMap(java.util.HashMap) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) DataUtils(dev.rosewood.rosestacker.utils.DataUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ItemStackEvent(dev.rosewood.rosestacker.event.ItemStackEvent) NMSHandler(dev.rosewood.rosestacker.nms.NMSHandler) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) CreatureSpawner(org.bukkit.block.CreatureSpawner) Particle(org.bukkit.Particle) Vector(org.bukkit.util.Vector) EntityStackEvent(dev.rosewood.rosestacker.event.EntityStackEvent) EntityStackClearEvent(dev.rosewood.rosestacker.event.EntityStackClearEvent) ArmorStand(org.bukkit.entity.ArmorStand) NMSAdapter(dev.rosewood.rosestacker.nms.NMSAdapter) LivingEntity(org.bukkit.entity.LivingEntity) EntityStackClearEvent(dev.rosewood.rosestacker.event.EntityStackClearEvent)

Aggregations

RosePlugin (dev.rosewood.rosegarden.RosePlugin)1 EntityStackClearEvent (dev.rosewood.rosestacker.event.EntityStackClearEvent)1 EntityStackEvent (dev.rosewood.rosestacker.event.EntityStackEvent)1 EntityUnstackEvent (dev.rosewood.rosestacker.event.EntityUnstackEvent)1 ItemStackClearEvent (dev.rosewood.rosestacker.event.ItemStackClearEvent)1 ItemStackEvent (dev.rosewood.rosestacker.event.ItemStackEvent)1 PreDropStackedItemsEvent (dev.rosewood.rosestacker.event.PreDropStackedItemsEvent)1 NPCsHook (dev.rosewood.rosestacker.hook.NPCsHook)1 WorldGuardHook (dev.rosewood.rosestacker.hook.WorldGuardHook)1 Setting (dev.rosewood.rosestacker.manager.ConfigurationManager.Setting)1 EntityCacheManager (dev.rosewood.rosestacker.manager.EntityCacheManager)1 StackManager (dev.rosewood.rosestacker.manager.StackManager)1 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)1 NMSAdapter (dev.rosewood.rosestacker.nms.NMSAdapter)1 NMSHandler (dev.rosewood.rosestacker.nms.NMSHandler)1 StackedEntityDataEntry (dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry)1 StackedEntityDataStorage (dev.rosewood.rosestacker.nms.storage.StackedEntityDataStorage)1 EntityStackSettings (dev.rosewood.rosestacker.stack.settings.EntityStackSettings)1 ItemStackSettings (dev.rosewood.rosestacker.stack.settings.ItemStackSettings)1 DataUtils (dev.rosewood.rosestacker.utils.DataUtils)1