Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

[Comando] Send Donate

Iniciado por Swarlog, Ago 05, 2022, 01:22 AM

Tema anterior - Siguiente tema

Swarlog

### Eclipse Workspace Patch 1.0
#P L2jFanatic_GameServer
Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 26)
+++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
@@ -61,6 +61,7 @@
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRepairChar;
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
+import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSendDonate;
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
@@ -126,6 +127,7 @@
                registerAdminCommandHandler(new AdminRepairChar());
                registerAdminCommandHandler(new AdminRes());
                registerAdminCommandHandler(new AdminRideWyvern());
+               registerAdminCommandHandler(new AdminSendDonate());
                registerAdminCommandHandler(new AdminShop());
                registerAdminCommandHandler(new AdminSiege());
                registerAdminCommandHandler(new AdminSkill());
Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java
===================================================================
--- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java        (revision 0)
+++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java        (working copy)
@@ -0,0 +1,234 @@
+/*
+ * This program 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.
+ *
+ * This program 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 net.sf.l2j.gameserver.handler.admincommandhandlers;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import net.sf.l2j.Config;
+import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.gameserver.datatables.ItemTable;
+import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
+import net.sf.l2j.gameserver.idfactory.IdFactory;
+import net.sf.l2j.gameserver.model.L2ItemInstance.ItemLocation;
+import net.sf.l2j.gameserver.model.L2World;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.network.SystemMessageId;
+import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
+import net.sf.l2j.gameserver.templates.item.L2Item;
+import net.sf.l2j.gameserver.util.GMAudit;
+
+public class AdminSendDonate implements IAdminCommandHandler
+{
+       protected static final Logger _log = Logger.getLogger(AdminSendDonate.class.getName());
+     
+       private static final String[] ADMIN_COMMANDS =
+       {
+               "admin_senddonate",
+               "admin_givedonate"
+       };
+     
+       @Override
+       public boolean useAdminCommand(String command, L2PcInstance activeChar)
+       {
+               if (command.equals("admin_senddonate"))
+               {
+                       AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
+               }
+               else if (command.startsWith("admin_givedonate"))
+               {
+                       StringTokenizer st = new StringTokenizer(command, " ");
+                       st.nextToken();
+                     
+                       String playername = "";
+                       L2PcInstance player = null;
+                     
+                       if (st.countTokens() == 4)
+                       {
+                               playername = st.nextToken();
+                               player = L2World.getInstance().getPlayer(playername);
+                               String id = st.nextToken();
+                               int idval = Integer.parseInt(id);
+                               String num = st.nextToken();
+                               int numval = Integer.parseInt(num);
+                               String location = st.nextToken();
+                             
+                               // Can't use on yourself
+                               if (player != null && player.equals(activeChar))
+                               {
+                                       activeChar.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
+                                       return false;
+                               }
+                             
+                               if (player != null)
+                                       createItem(activeChar, player, idval, numval, getItemLocation(location));
+                               else
+                                       giveItemToOfflinePlayer(activeChar, playername, idval, numval, getItemLocation(location));
+                             
+                               auditAction(command, activeChar, playername);
+                       }
+                       else
+                       {
+                               activeChar.sendChatMessage(0, 0, "SYS", "Please fill in all the blanks before requesting a item creation.");
+                       }
+                     
+                       AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
+               }
+             
+               return true;
+       }
+     
+       /**
+        * Create item on player inventory. If player is offline, store item on database by giveItemToOfflinePlayer method.
+        * @param activeChar
+        * @param player
+        * @param id
+        * @param count
+        * @param location
+        */
+       private static void createItem(L2PcInstance activeChar, L2PcInstance player, int id, int count, ItemLocation location)
+       {
+               L2Item item = ItemTable.getInstance().getTemplate(id);
+               if (item == null)
+               {
+                       activeChar.sendChatMessage(0, 0, "SYS", "Unknown Item ID.");
+                       return;
+               }
+             
+               if (count > 10 && !item.isStackable())
+               {
+                       activeChar.sendChatMessage(0, 0, "SYS", "You can't to create more than 10 non stackable items!");
+                       return;
+               }
+             
+               if (location == ItemLocation.INVENTORY)
+                       player.getInventory().addItem("Admin", id, count, player, activeChar);
+               else if (location == ItemLocation.WAREHOUSE)
+                       player.getWarehouse().addItem("Admin", id, count, player, activeChar);
+             
+               if (activeChar != player)
+               {
+                       if (count > 1)
+                               player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(id).addNumber(count));
+                       else
+                               player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(id));
+               }
+             
+               activeChar.sendChatMessage(0, 0, "SYS", "Spawned " + count + " " + item.getName() + " in " + player.getName() + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
+       }
+     
+       /**
+        * If player is offline, store item by SQL Query
+        * @param activeChar
+        * @param playername
+        * @param id
+        * @param count
+        * @param location
+        */
+       private static void giveItemToOfflinePlayer(L2PcInstance activeChar, String playername, int id, int count, ItemLocation location)
+       {
+               L2Item item = ItemTable.getInstance().getTemplate(id);
+               int objectId = IdFactory.getInstance().getNextId();
+             
+               try (Connection con = L2DatabaseFactory.getInstance().getConnection())
+               {
+                       PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters WHERE char_name=?");
+                       statement.setString(1, playername);
+                       ResultSet result = statement.executeQuery();
+                       int objId = 0;
+                     
+                       if (result.next())
+                       {
+                               objId = result.getInt(1);
+                       }
+                     
+                       result.close();
+                       statement.close();
+                     
+                       if (objId == 0)
+                       {
+                               activeChar.sendChatMessage(0, 0, "SYS", "Char \"" + playername + "\" does not exists!");
+                               con.close();
+                               return;
+                       }
+                     
+                       if (item == null)
+                       {
+                               activeChar.sendChatMessage(0, 0, "SYS", "Unknown Item ID.");
+                               return;
+                       }
+                     
+                       if (count > 1 && !item.isStackable())
+                       {
+                               activeChar.sendChatMessage(0, 0, "SYS", "You can't to create more than 1 non stackable items!");
+                               return;
+                       }
+                     
+                       statement = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,object_id,custom_type1,custom_type2,mana_left,time) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
+                       statement.setInt(1, objId);
+                       statement.setInt(2, item.getItemId());
+                       statement.setInt(3, count);
+                       statement.setString(4, location.name());
+                       statement.setInt(5, 0);
+                       statement.setInt(6, 0);
+                       statement.setInt(7, objectId);
+                       statement.setInt(8, 0);
+                       statement.setInt(9, 0);
+                       statement.setInt(10, -1);
+                       statement.setLong(11, 0);
+                     
+                       statement.executeUpdate();
+                       statement.close();
+                     
+                       activeChar.sendChatMessage(0, 0, "SYS", "Created " + count + " " + item.getName() + " in " + playername + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
+                       _log.info("Insert item: (" + objId + ", " + item.getName() + ", " + count + ", " + objectId + ")");
+               }
+               catch (SQLException e)
+               {
+                       _log.log(Level.SEVERE, "Could not insert item " + item.getName() + " into DB: Reason: " + e.getMessage(), e);
+               }
+       }
+     
+       private static ItemLocation getItemLocation(String name)
+       {
+               ItemLocation location = null;
+               if (name.equalsIgnoreCase("inventory"))
+                       location = ItemLocation.INVENTORY;
+               else if (name.equalsIgnoreCase("warehouse"))
+                       location = ItemLocation.WAREHOUSE;
+               return location;
+       }
+     
+       private static void auditAction(String fullCommand, L2PcInstance activeChar, String target)
+       {
+               if (!Config.GMAUDIT)
+                       return;
+             
+               String[] command = fullCommand.split(" ");
+             
+               GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", command[0], (target.equals("") ? "no-target" : target), (command.length > 2 ? command[2] : ""));
+       }
+     
+       @Override
+       public String[] getAdminCommandList()
+       {
+               return ADMIN_COMMANDS;
+       }
+}
\ No newline at end of file
#P L2jFanatic_DataPack
Index: data/xml/admin_commands_rights.xml
===================================================================
--- data/xml/admin_commands_rights.xml  (revision 27)
+++ data/xml/admin_commands_rights.xml  (working copy)
@@ -300,6 +300,10 @@
        <aCar name="admin_ride" accessLevel="1" />
        <aCar name="admin_unride" accessLevel="1" />
 
+       <!-- SEND DONATE -->
+       <aCar name="admin_senddonate" accessLevel="1" />
+       <aCar name="admin_givedonate" accessLevel="1" />
+     
        <!-- SHOP -->
        <aCar name="admin_buy" accessLevel="1" />
        <aCar name="admin_gmshop" accessLevel="1" />
Index: data/html/admin/senddonate.htm
===================================================================
--- data/html/admin/senddonate.htm      (revision 0)
+++ data/html/admin/senddonate.htm      (working copy)
@@ -0,0 +1,23 @@
+<html><title>Donate</title><body>
+       <center>
+               <img src="Sek.cbui371" width=275 height=1>
+               <table width=275 bgcolor=000000>
+                       <tr>
+                               <td width=45><button value="Main" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
+                               <td width=180 align="center"><font color="LEVEL">Send Donate Menu</font></td>
+                               <td width=45><button value="Back" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
+                       </tr>
+               </table>
+               <img src="Sek.cbui371" width=275 height=1><br>
+               <table width=280><tr><td>First fill the player's name. Then, fill in the ID number of the Item ID to create the item you want. Then fill in the quantity of the item you want to create in item count. Finally, choose where to create the item: in the warehouse or in the inventory.</td></tr></table><br>
+               <table width=240>
+                       <tr><td>Player Name:</td><td><edit var="playername" width=100></td></tr>
+                       <tr><td>Item ID:</td><td><edit var="itemid" width=100 type=number></td></tr>
+                       <tr><td>Item Count:</td><td><edit var="itemnum" width=100 type=number></td></tr>
+                       <tr><td>Location:</td><td><combobox width=100 height=17 var=location list=Warehouse;Inventory;></td></tr>
+               </table>
+               <br><br>
+               <button value="Send Donate" action="bypass -h admin_givedonate $playername $itemid $itemnum $location" width=95 height=21 back="bigbutton_over" fore="bigbutton"><br>
+               <table width=280><tr><td align="center"><font color="FF0000">Non-stackable items can't have amount superior to 10.</font></font></td></tr></table>
+       </center>
+</body></html>

Creditos: BlackZer0 por su publicación.