View difference between Paste ID: hWkfneNn and dE5Hdikt
SHOW: | | - or go back to the newest paste.
1
### Eclipse Workspace Patch 1.0
2
#P L2jFanatic_GameServer
3
Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
4
===================================================================
5
--- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java	(revision 26)
6
+++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java	(working copy)
7
@@ -61,6 +61,7 @@
8
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRepairChar;
9
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRes;
10
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminRideWyvern;
11
+import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSendDonate;
12
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminShop;
13
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSiege;
14
 import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminSkill;
15
@@ -126,6 +127,7 @@
16
 		registerAdminCommandHandler(new AdminRepairChar());
17
 		registerAdminCommandHandler(new AdminRes());
18
 		registerAdminCommandHandler(new AdminRideWyvern());
19
+		registerAdminCommandHandler(new AdminSendDonate());
20
 		registerAdminCommandHandler(new AdminShop());
21
 		registerAdminCommandHandler(new AdminSiege());
22
 		registerAdminCommandHandler(new AdminSkill());
23
Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java
24
===================================================================
25
--- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java	(revision 0)
26
+++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminSendDonate.java	(working copy)
27
@@ -0,0 +1,234 @@
28
+/*
29
+ * This program is free software: you can redistribute it and/or modify it under
30
+ * the terms of the GNU General Public License as published by the Free Software
31
+ * Foundation, either version 3 of the License, or (at your option) any later
32
+ * version.
33
+ * 
34
+ * This program is distributed in the hope that it will be useful, but WITHOUT
35
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
36
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
37
+ * details.
38
+ * 
39
+ * You should have received a copy of the GNU General Public License along with
40
+ * this program. If not, see <http://www.gnu.org/licenses/>.
41
+ */
42
+package net.sf.l2j.gameserver.handler.admincommandhandlers;
43
+
44
+import java.sql.Connection;
45
+import java.sql.PreparedStatement;
46
+import java.sql.ResultSet;
47
+import java.sql.SQLException;
48
+import java.util.StringTokenizer;
49
+import java.util.logging.Level;
50
+import java.util.logging.Logger;
51
+
52
+import net.sf.l2j.Config;
53
+import net.sf.l2j.L2DatabaseFactory;
54
+import net.sf.l2j.gameserver.datatables.ItemTable;
55
+import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
56
+import net.sf.l2j.gameserver.idfactory.IdFactory;
57
+import net.sf.l2j.gameserver.model.L2ItemInstance.ItemLocation;
58
+import net.sf.l2j.gameserver.model.L2World;
59
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
60
+import net.sf.l2j.gameserver.network.SystemMessageId;
61
+import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
62
+import net.sf.l2j.gameserver.templates.item.L2Item;
63
+import net.sf.l2j.gameserver.util.GMAudit;
64
+
65
+public class AdminSendDonate implements IAdminCommandHandler
66
+{
67
+	protected static final Logger _log = Logger.getLogger(AdminSendDonate.class.getName());
68
+	
69
+	private static final String[] ADMIN_COMMANDS =
70
+	{
71
+		"admin_senddonate",
72
+		"admin_givedonate"
73
+	};
74
+	
75
+	@Override
76
+	public boolean useAdminCommand(String command, L2PcInstance activeChar)
77
+	{
78
+		if (command.equals("admin_senddonate"))
79
+		{
80
+			AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
81
+		}
82
+		else if (command.startsWith("admin_givedonate"))
83
+		{
84
+			StringTokenizer st = new StringTokenizer(command, " ");
85
+			st.nextToken();
86
+			
87
+			String playername = "";
88
+			L2PcInstance player = null;
89
+			
90
+			if (st.countTokens() == 4)
91
+			{
92
+				playername = st.nextToken();
93
+				player = L2World.getInstance().getPlayer(playername);
94
+				String id = st.nextToken();
95
+				int idval = Integer.parseInt(id);
96
+				String num = st.nextToken();
97
+				int numval = Integer.parseInt(num);
98
+				String location = st.nextToken();
99
+				
100
+				// Can't use on yourself
101
+				if (player != null && player.equals(activeChar))
102
+				{
103
+					activeChar.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
104
+					return false;
105
+				}
106
+				
107
+				if (player != null)
108
+					createItem(activeChar, player, idval, numval, getItemLocation(location));
109
+				else
110
+					giveItemToOfflinePlayer(activeChar, playername, idval, numval, getItemLocation(location));
111
+				
112
+				auditAction(command, activeChar, playername);
113
+			}
114
+			else
115
+			{
116
+				activeChar.sendChatMessage(0, 0, "SYS", "Please fill in all the blanks before requesting a item creation.");
117
+			}
118
+			
119
+			AdminHelpPage.showHelpPage(activeChar, "senddonate.htm");
120
+		}
121
+		
122
+		return true;
123
+	}
124
+	
125
+	/**
126
+	 * Create item on player inventory. If player is offline, store item on database by giveItemToOfflinePlayer method.
127
+	 * @param activeChar
128
+	 * @param player
129
+	 * @param id
130
+	 * @param count
131
+	 * @param location
132
+	 */
133
+	private static void createItem(L2PcInstance activeChar, L2PcInstance player, int id, int count, ItemLocation location)
134
+	{
135
+		L2Item item = ItemTable.getInstance().getTemplate(id);
136
+		if (item == null)
137
+		{
138
+			activeChar.sendChatMessage(0, 0, "SYS", "Unknown Item ID.");
139
+			return;
140
+		}
141
+		
142
+		if (count > 10 && !item.isStackable())
143
+		{
144
+			activeChar.sendChatMessage(0, 0, "SYS", "You can't to create more than 10 non stackable items!");
145
+			return;
146
+		}
147
+		
148
+		if (location == ItemLocation.INVENTORY)
149
+			player.getInventory().addItem("Admin", id, count, player, activeChar);
150
+		else if (location == ItemLocation.WAREHOUSE)
151
+			player.getWarehouse().addItem("Admin", id, count, player, activeChar);
152
+		
153
+		if (activeChar != player)
154
+		{
155
+			if (count > 1)
156
+				player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S2_S1).addItemName(id).addNumber(count));
157
+			else
158
+				player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1).addItemName(id));
159
+		}
160
+		
161
+		activeChar.sendChatMessage(0, 0, "SYS", "Spawned " + count + " " + item.getName() + " in " + player.getName() + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
162
+	}
163
+	
164
+	/**
165
+	 * If player is offline, store item by SQL Query
166
+	 * @param activeChar
167
+	 * @param playername
168
+	 * @param id
169
+	 * @param count
170
+	 * @param location
171
+	 */
172
+	private static void giveItemToOfflinePlayer(L2PcInstance activeChar, String playername, int id, int count, ItemLocation location)
173
+	{
174
+		L2Item item = ItemTable.getInstance().getTemplate(id);
175
+		int objectId = IdFactory.getInstance().getNextId();
176
+		
177
+		try (Connection con = L2DatabaseFactory.getInstance().getConnection())
178
+		{
179
+			PreparedStatement statement = con.prepareStatement("SELECT obj_Id FROM characters WHERE char_name=?");
180
+			statement.setString(1, playername);
181
+			ResultSet result = statement.executeQuery();
182
+			int objId = 0;
183
+			
184
+			if (result.next())
185
+			{
186
+				objId = result.getInt(1);
187
+			}
188
+			
189
+			result.close();
190
+			statement.close();
191
+			
192
+			if (objId == 0)
193
+			{
194
+				activeChar.sendChatMessage(0, 0, "SYS", "Char \"" + playername + "\" does not exists!");
195
+				con.close();
196
+				return;
197
+			}
198
+			
199
+			if (item == null)
200
+			{
201
+				activeChar.sendChatMessage(0, 0, "SYS", "Unknown Item ID.");
202
+				return;
203
+			}
204
+			
205
+			if (count > 1 && !item.isStackable())
206
+			{
207
+				activeChar.sendChatMessage(0, 0, "SYS", "You can't to create more than 1 non stackable items!");
208
+				return;
209
+			}
210
+			
211
+			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 (?,?,?,?,?,?,?,?,?,?,?)");
212
+			statement.setInt(1, objId);
213
+			statement.setInt(2, item.getItemId());
214
+			statement.setInt(3, count);
215
+			statement.setString(4, location.name());
216
+			statement.setInt(5, 0);
217
+			statement.setInt(6, 0);
218
+			statement.setInt(7, objectId);
219
+			statement.setInt(8, 0);
220
+			statement.setInt(9, 0);
221
+			statement.setInt(10, -1);
222
+			statement.setLong(11, 0);
223
+			
224
+			statement.executeUpdate();
225
+			statement.close();
226
+			
227
+			activeChar.sendChatMessage(0, 0, "SYS", "Created " + count + " " + item.getName() + " in " + playername + " " + (location == ItemLocation.INVENTORY ? "inventory" : "warehouse") + ".");
228
+			_log.info("Insert item: (" + objId + ", " + item.getName() + ", " + count + ", " + objectId + ")");
229
+		}
230
+		catch (SQLException e)
231
+		{
232
+			_log.log(Level.SEVERE, "Could not insert item " + item.getName() + " into DB: Reason: " + e.getMessage(), e);
233
+		}
234
+	}
235
+	
236
+	private static ItemLocation getItemLocation(String name)
237
+	{
238
+		ItemLocation location = null;
239
+		if (name.equalsIgnoreCase("inventory"))
240
+			location = ItemLocation.INVENTORY;
241
+		else if (name.equalsIgnoreCase("warehouse"))
242
+			location = ItemLocation.WAREHOUSE;
243
+		return location;
244
+	}
245
+	
246
+	private static void auditAction(String fullCommand, L2PcInstance activeChar, String target)
247
+	{
248
+		if (!Config.GMAUDIT)
249
+			return;
250
+		
251
+		String[] command = fullCommand.split(" ");
252
+		
253
+		GMAudit.auditGMAction(activeChar.getName() + " [" + activeChar.getObjectId() + "]", command[0], (target.equals("") ? "no-target" : target), (command.length > 2 ? command[2] : ""));
254
+	}
255
+	
256
+	@Override
257
+	public String[] getAdminCommandList()
258
+	{
259
+		return ADMIN_COMMANDS;
260
+	}
261
+}
262
\ No newline at end of file
263
#P L2jFanatic_DataPack
264
Index: data/xml/admin_commands_rights.xml
265
===================================================================
266
--- data/xml/admin_commands_rights.xml	(revision 27)
267
+++ data/xml/admin_commands_rights.xml	(working copy)
268
@@ -300,6 +300,10 @@
269
 	<aCar name="admin_ride" accessLevel="1" />
270
 	<aCar name="admin_unride" accessLevel="1" />
271
 
272
+	<!-- SEND DONATE -->
273
+	<aCar name="admin_senddonate" accessLevel="1" />
274
+	<aCar name="admin_givedonate" accessLevel="1" />
275
+	
276
 	<!-- SHOP -->
277
 	<aCar name="admin_buy" accessLevel="1" />
278
 	<aCar name="admin_gmshop" accessLevel="1" />
279
Index: data/html/admin/senddonate.htm
280
===================================================================
281
--- data/html/admin/senddonate.htm	(revision 0)
282
+++ data/html/admin/senddonate.htm	(working copy)
283
@@ -0,0 +1,23 @@
284
+<html><title>Donate</title><body>
285
+	<center>
286
+		<img src="Sek.cbui371" width=275 height=1>
287
+		<table width=275 bgcolor=000000>
288
+			<tr>
289
+				<td width=45><button value="Main" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
290
+				<td width=180 align="center"><font color="LEVEL">Send Donate Menu</font></td>
291
+				<td width=45><button value="Back" action="bypass -h admin_admin" width=45 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
292
+			</tr>
293
+		</table>
294
+		<img src="Sek.cbui371" width=275 height=1><br>
295
+		<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>
296
+		<table width=240>
297
+			<tr><td>Player Name:</td><td><edit var="playername" width=100></td></tr>
298
+			<tr><td>Item ID:</td><td><edit var="itemid" width=100 type=number></td></tr>
299
+			<tr><td>Item Count:</td><td><edit var="itemnum" width=100 type=number></td></tr>
300
+			<tr><td>Location:</td><td><combobox width=100 height=17 var=location list=Warehouse;Inventory;></td></tr>
301
+		</table>
302
+		<br><br>
303
+		<button value="Send Donate" action="bypass -h admin_givedonate $playername $itemid $itemnum $location" width=95 height=21 back="bigbutton_over" fore="bigbutton"><br>
304
+		<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>
305
+	</center>
306
+</body></html>
307
\ No newline at end of file