From 17e6d33869d2fe207c99a7da7496b69ccbc7ab9c Mon Sep 17 00:00:00 2001
From: Maneco2 <maneco_1@hotmail.com>
Date: Sun, 17 Jan 2021 11:46:40 -0300
Subject: [PATCH] Added Auto Loot Extension

Core part required:
https://bitbucket.org/l2jserver/l2j-server-game/commits/de04327906e7dfd61ee7cfaf3a65c9b7f86a97a6
---
 .../datapack/handlers/MasterHandler.java      |   2 +
 .../voicedcommandhandlers/AutoLoot.java       | 153 ++++++++++++++++++
 2 files changed, 155 insertions(+)
 create mode 100644 src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/AutoLoot.java

diff --git a/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java b/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
index af3379cf8a..68f62a4d38 100644
--- a/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
+++ b/src/main/java/com/l2jserver/datapack/handlers/MasterHandler.java
@@ -261,6 +261,7 @@ import com.l2jserver.datapack.handlers.usercommandhandlers.PartyInfo;
 import com.l2jserver.datapack.handlers.usercommandhandlers.SiegeStatus;
 import com.l2jserver.datapack.handlers.usercommandhandlers.Time;
 import com.l2jserver.datapack.handlers.usercommandhandlers.Unstuck;
+import com.l2jserver.datapack.handlers.voicedcommandhandlers.AutoLoot;
 import com.l2jserver.datapack.handlers.voicedcommandhandlers.Banking;
 import com.l2jserver.datapack.handlers.voicedcommandhandlers.ChangePassword;
 import com.l2jserver.datapack.handlers.voicedcommandhandlers.ChatAdmin;
@@ -560,6 +561,7 @@ public class MasterHandler {
 	};
 	
 	private static final Class<?>[] VOICED_COMMAND_HANDLERS = {
+		AutoLoot.class,
 		StatsVCmd.class,
 		// TODO: Add configuration options for this voiced commands:
 		// CastleVCmd.class,
diff --git a/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/AutoLoot.java b/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/AutoLoot.java
new file mode 100644
index 0000000000..3104e55a24
--- /dev/null
+++ b/src/main/java/com/l2jserver/datapack/handlers/voicedcommandhandlers/AutoLoot.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright © 2004-2021 L2J DataPack
+ * 
+ * This file is part of L2J DataPack.
+ * 
+ * L2J DataPack is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J DataPack is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.datapack.handlers.voicedcommandhandlers;
+
+import static com.l2jserver.gameserver.config.Configuration.character;
+import static com.l2jserver.gameserver.config.Configuration.customs;
+
+import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * Auto Loot Extension voiced command.
+ * @author Maneco2
+ * @version 2.6.2.0
+ */
+public class AutoLoot implements IVoicedCommandHandler
+{
+	private static final String[] VOICED_COMMANDS =
+	{
+		"loot",
+		"autoloot",
+		"itemloot",
+		"herbloot"
+	};
+	
+	@Override
+	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
+	{
+		if (!customs().autoLootVoiceCommand())
+		{
+			return false;
+		}
+		if (command.equals("loot"))
+		{
+			activeChar.sendMessage("Using Voices Methods:\n.autoloot: Loot all item(s).\n.itemloot: Loot all better item(s).\n.herbloot: Loot recovery(s) herb(s).");
+			if (activeChar.isAutoLoot())
+			{
+				activeChar.sendMessage("Auto Loot: enabled.");
+			}
+			if (activeChar.isAutoLootItem())
+			{
+				activeChar.sendMessage("Auto Loot Item: enabled.");
+			}
+			if (activeChar.isAutoLootHerb())
+			{
+				activeChar.sendMessage("Auto Loot Herbs: enabled.");
+			}
+		}
+		else if (command.equals("autoloot"))
+		{
+			if (!character().autoLoot())
+			{
+				if (activeChar.isAutoLoot())
+				{
+					activeChar.setAutoLoot(false);
+					activeChar.sendMessage("Auto Loot: disabled.");
+					if (customs().autoLootVoiceRestore())
+					{
+						activeChar.getVariables().remove("AutoLoot");
+					}
+				}
+				else
+				{
+					activeChar.setAutoLoot(true);
+					activeChar.sendMessage("Auto Loot: enabled.");
+					if (customs().autoLootVoiceRestore())
+					{
+						activeChar.getVariables().set("AutoLoot", true);
+					}
+				}
+			}
+			else
+			{
+				activeChar.sendMessage("Auto Loot already enable.");
+			}
+		}
+		else if (command.equals("itemloot"))
+		{
+			if (activeChar.isAutoLootItem())
+			{
+				activeChar.setAutoLootItem(false);
+				activeChar.sendMessage("Auto Loot Item: disabled.");
+				if (customs().autoLootVoiceRestore())
+				{
+					activeChar.getVariables().remove("AutoLootItems");
+				}
+			}
+			else
+			{
+				activeChar.setAutoLootItem(true);
+				activeChar.sendMessage("Auto Loot Item: enabled.");
+				if (customs().autoLootVoiceRestore())
+				{
+					activeChar.getVariables().set("AutoLootItems", true);
+				}
+				
+				if (activeChar.isAutoLoot())
+				{
+					activeChar.setAutoLoot(false);
+					activeChar.sendMessage("Auto Loot Item is now priority.");
+					if (customs().autoLootVoiceRestore())
+					{
+						activeChar.getVariables().remove("AutoLoot");
+					}
+				}
+			}
+		}
+		else if (command.equals("herbloot"))
+		{
+			if (activeChar.isAutoLootHerb())
+			{
+				activeChar.setAutoLootHerbs(false);
+				activeChar.sendMessage("Auto Loot Herbs: disabled.");
+				if (customs().autoLootVoiceRestore())
+				{
+					activeChar.getVariables().remove("AutoLootHerbs");
+				}
+			}
+			else
+			{
+				activeChar.setAutoLootHerbs(true);
+				activeChar.sendMessage("Auto Loot Herbs: enabled.");
+				if (customs().autoLootVoiceRestore())
+				{
+					activeChar.getVariables().set("AutoLootHerbs", true);
+				}
+			}
+		}
+		return true;
+	}
+	
+	@Override
+	public String[] getVoicedCommandList()
+	{
+		return VOICED_COMMANDS;
+	}
+}
\ No newline at end of file
-- 
GitLab