#include "InventoryManager.h"
#include "Client.h"

#include "Utils/TimeUtils.h"
#include "Utils/MathUtils.h"

auto InventoryManager::onContainerScreenTick(ContainerScreenController* _this) -> void {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto localplayer = clientinstance->getLocalPlayer();
	if (!localplayer) return;

	auto actorequipmentcomponent = localplayer->getActorEquipmentComponent();
	if (!actorequipmentcomponent) return;


	auto playerinventory = localplayer->getPlayerInventory();
	if (!playerinventory) return;

	auto inventory = playerinventory->getInventory();
	if (!inventory) return;


	if (Client::screenName != _("inventory_screen"))
		return;


	std::vector<int> swordslots, pickaxeslots, axeslots, snowballslots, enderpearlslots, bowslots, blockslots, helmetslots, chestplateslots, leggingsslots, bootsslots, fireswordslots, dropslots;
	short maxsworddamage = 0, maxpickaxedamage = 0, maxaxedamage = 0, maxhelmetdamage = 0, maxchestplatedamage = 0, maxleggingsdamage = 0, maxbootsdamage = 0, maxfiresworddamage = 0;
	int _swordslot = -1, _pickaxeslot = -1, _axeslot = -1, helmetslot = -1, chestplateslot = -1, leggingsslot = -1, bootsslot = -1, _fireswordslot = -1;

	for (int i = 0; i < 36; i++) {
		if (inventory->getItemStack(i)->getItem()) {
			if (firesword) {
				if (inventory->getItemStack(i)->getCustomName().find(reinterpret_cast<const char*>(_("§r§6Sword of §eEmbers"))) != std::string::npos ||
					inventory->getItemStack(i)->getCustomName().find(reinterpret_cast<const char*>(_(u8"§r§cFire Sword"))) != std::string::npos) {

					if (_fireswordslot == -1) 
						_fireswordslot = i;

					fireswordslots.push_back(i);
					continue;
				}
			}
			if (sword) {
				if (firesword && (
					inventory->getItemStack(i)->getCustomName().find(reinterpret_cast<const char*>(_("Embers"))) != std::string::npos ||
					inventory->getItemStack(i)->getCustomName().find(reinterpret_cast<const char*>(_(u8"Fire"))) != std::string::npos
					))
					continue;

				short qualityvalue = 0;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_sword")) != std::string::npos) {
					if ((*inventory->getItemStack(i)->getItem())->getName().find(_("wooden")) != std::string::npos) qualityvalue = 1;
					if ((*inventory->getItemStack(i)->getItem())->getName().find(_("stone")) != std::string::npos) qualityvalue = 2;
					if ((*inventory->getItemStack(i)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue = 3;
					if ((*inventory->getItemStack(i)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue = 4;
					if ((*inventory->getItemStack(i)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue = 5;

					if (maxsworddamage < qualityvalue + inventory->getItemStack(i)->getEnchantValue(0x9)) {
						maxsworddamage = qualityvalue + inventory->getItemStack(i)->getEnchantValue(0x9);
						_swordslot = i;
					}
					swordslots.push_back(i);
					continue;
				}
			}
			if (pickaxe) {
				short qualityvalue = 0;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("wooden")) != std::string::npos) qualityvalue = 1;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("stone")) != std::string::npos) qualityvalue = 2;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue = 3;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue = 4;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue = 5;

				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_pickaxe")) != std::string::npos) {
					if (maxpickaxedamage < qualityvalue) {
						maxpickaxedamage = qualityvalue;
						_pickaxeslot = i;
					}
					pickaxeslots.push_back(i);
					continue;
				}
			}
			if (axe) {
				short qualityvalue = 1;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("wooden")) != std::string::npos) qualityvalue = 1;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("stone")) != std::string::npos) qualityvalue = 2;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue = 3;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue = 4;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue = 5;

				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_axe")) != std::string::npos) {
					if (maxaxedamage < qualityvalue) {
						maxaxedamage = qualityvalue;
						_axeslot = i;
					}
					axeslots.push_back(i);
					continue;
				}
			}
			if (enderpearl) {
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("ender_pearl")) != std::string::npos) {
					enderpearlslots.push_back(i);
					continue;
				}
			}
			if (snowball) {
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("snowball")) != std::string::npos) {
					snowballslots.push_back(i);
					continue;
				}
			}

			if (armor) {
				short qualityvalue = 0, qualityvalue_1 = 0, qualityvalue_2 = 0, qualityvalue_3 = 0, qualityvalue_4 = 0;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("leather")) != std::string::npos) qualityvalue = 1;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("chainmail")) != std::string::npos) qualityvalue = 2;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue = 3;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("golden")) != std::string::npos) qualityvalue = 4;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue = 5;
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue = 6;

				if (actorequipmentcomponent->armor->getItemStack(0)->getItem()) {
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("leather")) != std::string::npos) qualityvalue_1 = 1;
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("chainmail")) != std::string::npos) qualityvalue_1 = 2;
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue_1 = 3;
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("golden")) != std::string::npos) qualityvalue_1 = 4;
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue_1 = 5;
					if ((*actorequipmentcomponent->armor->getItemStack(0)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue_1 = 6;
				}

				if (actorequipmentcomponent->armor->getItemStack(1)->getItem()) {
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("leather")) != std::string::npos) qualityvalue_2 = 1;
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("chainmail")) != std::string::npos) qualityvalue_2 = 2;
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue_2 = 3;
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("golden")) != std::string::npos) qualityvalue_2 = 4;
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue_2 = 5;
					if ((*actorequipmentcomponent->armor->getItemStack(1)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue_2 = 6;
				}

				if (actorequipmentcomponent->armor->getItemStack(2)->getItem()) {
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("leather")) != std::string::npos) qualityvalue_3 = 1;
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("chainmail")) != std::string::npos) qualityvalue_3 = 2;
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue_3 = 3;
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("golden")) != std::string::npos) qualityvalue_3 = 4;
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue_3 = 5;
					if ((*actorequipmentcomponent->armor->getItemStack(2)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue_3 = 6;
				}

				if (actorequipmentcomponent->armor->getItemStack(3)->getItem()) {
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("leather")) != std::string::npos) qualityvalue_4 = 1;
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("chainmail")) != std::string::npos) qualityvalue_4 = 2;
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("iron")) != std::string::npos) qualityvalue_4 = 3;
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("golden")) != std::string::npos) qualityvalue_4 = 4;
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("diamond")) != std::string::npos) qualityvalue_4 = 5;
					if ((*actorequipmentcomponent->armor->getItemStack(3)->getItem())->getName().find(_("netherite")) != std::string::npos) qualityvalue_4 = 6;
				}

				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_helmet")) != std::string::npos && (qualityvalue_1 + (actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x0) + actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x1))) < (qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1)))) {
					if (maxhelmetdamage < qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1))) {
						maxhelmetdamage = qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1));
						helmetslot = i;
					}
					helmetslots.push_back(i);
					continue;
				}
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_chestplate")) != std::string::npos && (qualityvalue_2 + (actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x0) + actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x1))) < (qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x0)))) {
					if (maxchestplatedamage < qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1))) {
						maxchestplatedamage = qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1));
						chestplateslot = i;
					}
					chestplateslots.push_back(i);
					continue;
				}
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_leggings")) != std::string::npos && (qualityvalue_3 + (actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x0) + actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x1))) < (qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x0)))) {
					if (maxleggingsdamage < qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1))) {
						maxleggingsdamage = qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1));
						leggingsslot = i;
					}
					leggingsslots.push_back(i);
					continue;
				}

				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("_boots")) != std::string::npos && (qualityvalue_4 + (actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x0) + actorequipmentcomponent->armor->getItemStack(i)->getEnchantValue(0x1))) < (qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x0)))) {
					if (maxbootsdamage < qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1))) {
						maxbootsdamage = qualityvalue + (inventory->getItemStack(i)->getEnchantValue(0x0) + inventory->getItemStack(i)->getEnchantValue(0x1));
						bootsslot = i;
					}
					bootsslots.push_back(i);
					continue;
				}

			}

			if (block) {
				if (inventory->getItemStack(i)->getBlock())
					continue;
			}

			if (spells) {
				if (inventory->getItemStack(i)->getCustomName().find(reinterpret_cast<const char*>(_(u8"§r§dSpell"))) != std::string::npos) 
					continue;
			}

			if (foods) {
				if ((*inventory->getItemStack(i)->getItem())->isFood())
					continue;
			}

			if (bows) {
				if ((*inventory->getItemStack(i)->getItem())->getName() == _("bow")) {
					bool founded = false;
					for (int i_ = 0; i_ < 36; i_++) {
						if (i_ == i) continue;
						if (inventory->getItemStack(i_)->getItem() && (*(inventory->getItemStack(i_)->getItem()))->getName().find("bow") != std::string::npos) {
							founded = true;
						}
					}
					if (!founded) {
						bowslots.push_back(i);
						continue;
					}
				}
			}

			if (arrows) {
				if ((*inventory->getItemStack(i)->getItem())->getName().find(_("arrow")) != std::string::npos) {
					continue;
				}
			}

			dropslots.push_back(i);
		}
	}

	static float currentdelay = Utils::Math::getrandom(mindelay, maxdelay);
	long long now = Utils::Time::getMs();

	{
		static long long start = now;
		if (now - start >= currentdelay * 1000.f) {
			currentdelay = Utils::Math::getrandom(mindelay, maxdelay);
			start = now;
		}
	}

	for (int i : dropslots) {
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			inventory->dropSlot(i, true);
			start = now;
		}
	}

	if (!helmetslots.empty()) {
		static int i = 0, i2 = 0;

		for (int i : helmetslots) {
			if (helmetslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			_this->handleTakeAll(helmetslot < 9 ? _("hotbar_items") : _("inventory_items"), helmetslot < 9 ? helmetslot : helmetslot - 9);
			_this->handlePlaceAll(_("armor_items"), 0);
			_this->handlePlaceAll(helmetslot < 9 ? _("hotbar_items") : _("inventory_items"), helmetslot < 9 ? helmetslot : helmetslot - 9);
			start = now;
		}
	}

	if (!chestplateslots.empty()) {
		static int i = 0, i2 = 0;

		for (int i : chestplateslots) {
			if (chestplateslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}

		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			_this->handleTakeAll(chestplateslot < 9 ? _("hotbar_items") : _("inventory_items"), chestplateslot < 9 ? chestplateslot : chestplateslot - 9);
			_this->handlePlaceAll(_("armor_items"), 1);
			_this->handlePlaceAll(chestplateslot < 9 ? _("hotbar_items") : _("inventory_items"), chestplateslot < 9 ? chestplateslot : chestplateslot - 9);
			start = now;
		}
	}

	if (!leggingsslots.empty()) {
		for (int i : leggingsslots) {
			if (leggingsslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			_this->handleTakeAll(leggingsslot < 9 ? _("hotbar_items") : _("inventory_items"), leggingsslot < 9 ? leggingsslot : leggingsslot - 9);
			_this->handlePlaceAll(_("armor_items"), 2);
			_this->handlePlaceAll(leggingsslot < 9 ? _("hotbar_items") : _("inventory_items"), leggingsslot < 9 ? leggingsslot : leggingsslot - 9);
			start = now;
		}
	}

	if (!bootsslots.empty()) {
		for (int i : bootsslots) {
			if (bootsslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			_this->handleTakeAll(bootsslot < 9 ? _("hotbar_items") : _("inventory_items"), bootsslot < 9 ? bootsslot : bootsslot - 9);
			_this->handlePlaceAll(_("armor_items"), 3);
			_this->handlePlaceAll(bootsslot < 9 ? _("hotbar_items") : _("inventory_items"), bootsslot < 9 ? bootsslot : bootsslot - 9);
			start = now;
		}
	}


	if (!fireswordslots.empty()) {
		static int i = 0, i2 = 0;

		for (int i : fireswordslots) {
			if (_fireswordslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			if (!inventory->getItemStack(_fireswordslot) && inventory->getItemStack(fireswordslot)) {
				_this->handleTakeAll(_("hotbar_items"), fireswordslot);
				_this->handlePlaceAll(_fireswordslot < 9 ? _("hotbar_items") : _("inventory_items"), _fireswordslot < 9 ? _fireswordslot : _fireswordslot - 9);
				_this->handlePlaceAll(_("hotbar_items"), fireswordslot);
				return;
			}

			_this->handleTakeAll(_fireswordslot < 9 ? _("hotbar_items") : _("inventory_items"), _fireswordslot < 9 ? _fireswordslot : _fireswordslot - 9);
			_this->handlePlaceAll(_("hotbar_items"), fireswordslot);
			_this->handlePlaceAll(_fireswordslot < 9 ? _("hotbar_items") : _("inventory_items"), _fireswordslot < 9 ? _fireswordslot : _fireswordslot - 9);
			start = now;
		}
	}

	if (!swordslots.empty()) {
		static int i = 0, i2 = 0;

		for (int i : swordslots) {
			if (_swordslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			if (!inventory->getItemStack(_swordslot) && inventory->getItemStack(swordslot)) {
				_this->handleTakeAll(_("hotbar_items"), swordslot);
				_this->handlePlaceAll(_swordslot < 9 ? _("hotbar_items") : _("inventory_items"), _swordslot < 9 ? _swordslot : _swordslot - 9);
				_this->handlePlaceAll(_("hotbar_items"), swordslot);
				return;
			}

			_this->handleTakeAll(_swordslot < 9 ? _("hotbar_items") : _("inventory_items"), _swordslot < 9 ? _swordslot : _swordslot - 9);
			_this->handlePlaceAll(_("hotbar_items"), swordslot);
			_this->handlePlaceAll(_swordslot < 9 ? _("hotbar_items") : _("inventory_items"), _swordslot < 9 ? _swordslot : _swordslot - 9);
			start = now;
		}
	}

	if (!pickaxeslots.empty()) {
		for (int i : pickaxeslots) {
			if (_pickaxeslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}

		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			if (!inventory->getItemStack(_pickaxeslot) && inventory->getItemStack(pickaxeslot)) {
				_this->handleTakeAll(_("hotbar_items"), pickaxeslot);
				_this->handlePlaceAll(_pickaxeslot < 9 ? _("hotbar_items") : _("inventory_items"), _pickaxeslot < 9 ? _pickaxeslot : _pickaxeslot - 9);
				_this->handlePlaceAll(_("hotbar_items"), pickaxeslot);
				return;
			}

			_this->handleTakeAll(_pickaxeslot < 9 ? _("hotbar_items") : _("inventory_items"), _pickaxeslot < 9 ? _pickaxeslot : _pickaxeslot - 9);
			_this->handlePlaceAll(_("hotbar_items"), pickaxeslot);
			_this->handlePlaceAll(_pickaxeslot < 9 ? _("hotbar_items") : _("inventory_items"), _pickaxeslot < 9 ? _pickaxeslot : _pickaxeslot - 9);
			start = now;
		}
	}

	if (!axeslots.empty()) {
		for (int i : axeslots) {
			if (_axeslot != i) {
				static long long start = Utils::Time::getMs();
				if (now - start >= currentdelay * 1000.f) {
					inventory->dropSlot(i, true);
					start = now;
				}
			}
		}
		static long long start = Utils::Time::getMs();
		if (now - start >= currentdelay * 1000.f) {
			if (!inventory->getItemStack(_axeslot) && inventory->getItemStack(axeslot)) {
				_this->handleTakeAll(_("hotbar_items"), axeslot);
				_this->handlePlaceAll(_axeslot < 9 ? _("hotbar_items") : _("inventory_items"), _axeslot < 9 ? _axeslot : _axeslot - 9);
				_this->handlePlaceAll(_("hotbar_items"), axeslot);
				return;
			}

			_this->handleTakeAll(_axeslot < 9 ? _("hotbar_items") : _("inventory_items"), _axeslot < 9 ? _axeslot : _axeslot - 9);
			_this->handlePlaceAll(_("hotbar_items"), axeslot);
			_this->handlePlaceAll(_axeslot < 9 ? _("hotbar_items") : _("inventory_items"), _axeslot < 9 ? _axeslot : _axeslot - 9);
			start = now;
		}
	}

	if (!snowballslots.empty()) {
		for (int slot : snowballslots) {
			static long long start = Utils::Time::getMs();
			if (now - start >= currentdelay * 1000.f) {
				if (!inventory->getItemStack(slot) && inventory->getItemStack(snowballslot)) {
					_this->handleTakeAll(_("hotbar_items"), snowballslot);
					_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
					_this->handlePlaceAll(_("hotbar_items"), snowballslot);
					return;
				}

				_this->handleTakeAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				_this->handlePlaceAll(_("hotbar_items"), snowballslot);
				_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				start = now;
			}
		}
	}

	if (!enderpearlslots.empty()) {
		for (int slot : enderpearlslots) {
			static long long start = Utils::Time::getMs();
			if (now - start >= currentdelay * 1000.f) {
				if (!inventory->getItemStack(slot) && inventory->getItemStack(enderpearlslot)) {
					_this->handleTakeAll(_("hotbar_items"), enderpearlslot);
					_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
					_this->handlePlaceAll(_("hotbar_items"), enderpearlslot);
					return;
				}

				_this->handleTakeAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				_this->handlePlaceAll(_("hotbar_items"), enderpearlslot);
				_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				start = now;
			}
		}
	}

	if (!bowslots.empty()) {
		for (int slot : bowslots) {
			static long long start = Utils::Time::getMs();
			if (now - start >= currentdelay * 1000.f) {
				if (!inventory->getItemStack(slot) && inventory->getItemStack(bowslot)) {
					_this->handleTakeAll(_("hotbar_items"), bowslot);
					_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
					_this->handlePlaceAll(_("hotbar_items"), bowslot);
					return;
				}

				_this->handleTakeAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				_this->handlePlaceAll(_("hotbar_items"), bowslot);
				_this->handlePlaceAll(slot < 9 ? _("hotbar_items") : _("inventory_items"), slot < 9 ? slot : slot - 9);
				start = now;
			}
		}
	}
}

auto InventoryManager::onClient4() -> void {
	name = Datas::Language::get().module.player.inventorymanager.name;
	description = Datas::Language::get().module.player.inventorymanager.description;
}

auto InventoryManager::getMode() -> std::string {
	std::stringstream ss;
	ss.precision(0);
	ss << std::fixed << (mindelay * 100) << " " << (maxdelay * 100);

	return ss.str();
}
