View difference between Paste ID: X1ep8Wet and QRjXRsxS
SHOW: | | - or go back to the newest paste.
1
diff --git a/java/net/sf/l2j/commons/data/xml/XMLDocument.java b/java/net/sf/l2j/commons/data/xml/XMLDocument.java
2
new file mode 100644
3
index 0000000..c1b16f8
4
--- /dev/null
5
+++ b/java/net/sf/l2j/commons/data/xml/XMLDocument.java
6
@@ -0,0 +1,82 @@
7
+package net.sf.l2j.commons.data.xml;
8
+
9
+import java.io.File;
10
+import java.util.logging.Level;
11
+import java.util.logging.Logger;
12
+
13
+import javax.xml.parsers.DocumentBuilderFactory;
14
+
15
+import net.sf.l2j.commons.data.StatSet;
16
+
17
+import org.w3c.dom.Document;
18
+import org.w3c.dom.NamedNodeMap;
19
+import org.w3c.dom.Node;
20
+
21
+/**
22
+ * An XML document, relying on a static and single DocumentBuilderFactory.
23
+ */
24
+public abstract class XMLDocument
25
+{
26
+	protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
27
+	
28
+	private static final DocumentBuilderFactory BUILDER;
29
+	static
30
+	{
31
+		BUILDER = DocumentBuilderFactory.newInstance();
32
+		BUILDER.setValidating(false);
33
+		BUILDER.setIgnoringComments(true);
34
+	}
35
+	
36
+	abstract protected void load();
37
+	
38
+	abstract protected void parseDocument(Document doc, File f);
39
+	
40
+	public void loadDocument(String filePath)
41
+	{
42
+		loadDocument(new File(filePath));
43
+	}
44
+	
45
+	/**
46
+	 * Parse an entire directory or file if found.
47
+	 * @param file
48
+	 */
49
+	public void loadDocument(File file)
50
+	{
51
+		if (!file.exists())
52
+		{
53
+			LOG.severe("The following file or directory doesn't exist: " + file.getName());
54
+			return;
55
+		}
56
+		
57
+		if (file.isDirectory())
58
+		{
59
+			for (File f : file.listFiles())
60
+				loadDocument(f);
61
+		}
62
+		else if (file.isFile())
63
+		{
64
+			try
65
+			{
66
+				parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
67
+			}
68
+			catch (Exception e)
69
+			{
70
+				LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
71
+			}
72
+		}
73
+	}
74
+	
75
+	/**
76
+	 * This method parses the content of a NamedNodeMap and feed the given StatsSet.
77
+	 * @param attrs : The NamedNodeMap to parse.
78
+	 * @param set : The StatsSet to feed.
79
+	 */
80
+	public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
81
+	{
82
+		for (int i = 0; i < attrs.getLength(); i++)
83
+		{
84
+			final Node attr = attrs.item(i);
85
+			set.set(attr.getNodeName(), attr.getNodeValue());
86
+		}
87
+	}
88
+}
89
\ No newline at end of file
90
diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java
91
index e682cc6..6c1638e 100644
92
--- a/java/net/sf/l2j/gameserver/GameServer.java
93
+++ b/java/net/sf/l2j/gameserver/GameServer.java
94
@@ -72,6 +72,7 @@
95
 import net.sf.l2j.gameserver.data.xml.StaticObjectData;
96
 import net.sf.l2j.gameserver.data.xml.SummonItemData;
97
 import net.sf.l2j.gameserver.data.xml.TeleportData;
98
+import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
99
 import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
100
 import net.sf.l2j.gameserver.geoengine.GeoEngine;
101
 import net.sf.l2j.gameserver.handler.AdminCommandHandler;
102
@@ -232,6 +233,7 @@
103
 		DimensionalRiftManager.getInstance();
104
 		NewbieBuffData.getInstance();
105
 		InstantTeleportData.getInstance();
106
+		TeleportLocationData.getInstance();
107
 		TeleportData.getInstance();
108
 		
109
 		StringUtil.printSection("Olympiads & Heroes");
110
diff --git a/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java b/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java
111
new file mode 100644
112
index 0000000..a19af62
113
--- /dev/null
114
+++ b/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java
115
@@ -0,0 +1,77 @@
116
+package net.sf.l2j.gameserver.data.xml;
117
+
118
+import java.io.File;
119
+import java.util.HashMap;
120
+import java.util.Map;
121
+
122
+import net.sf.l2j.commons.data.StatSet;
123
+import net.sf.l2j.commons.data.xml.XMLDocument;
124
+
125
+import net.sf.l2j.gameserver.model.location.TeleportLocation;
126
+
127
+import org.w3c.dom.Document;
128
+import org.w3c.dom.Node;
129
+
130
+public class TeleportLocationData extends XMLDocument
131
+{
132
+	private final Map<Integer, TeleportLocation> _teleports = new HashMap<>();
133
+	
134
+	protected TeleportLocationData()
135
+	{
136
+		load();
137
+	}
138
+	
139
+	@Override
140
+	protected void load()
141
+	{
142
+		loadDocument("./data/xml/teleportVip.xml");
143
+		LOG.info("Loaded " + _teleports.size() + " teleport locations.");
144
+	}
145
+	
146
+	@Override
147
+	protected void parseDocument(Document doc, File file)
148
+	{
149
+		// StatsSet used to feed informations. Cleaned on every entry.
150
+		final StatSet set = new StatSet();
151
+		
152
+		// First element is never read.
153
+		final Node n = doc.getFirstChild();
154
+		
155
+		for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
156
+		{
157
+			if (!"teleport".equalsIgnoreCase(o.getNodeName()))
158
+				continue;
159
+			
160
+			// Parse and feed content.
161
+			parseAndFeed(o.getAttributes(), set);
162
+			
163
+			// Feed the map with new data.
164
+			_teleports.put(set.getInteger("id"), new TeleportLocation(set));
165
+			
166
+			// Clear the StatsSet.
167
+			set.clear();
168
+		}
169
+	}
170
+	
171
+	public void reload()
172
+	{
173
+		_teleports.clear();
174
+		
175
+		load();
176
+	}
177
+	
178
+	public TeleportLocation getTeleportLocation(int id)
179
+	{
180
+		return _teleports.get(id);
181
+	}
182
+	
183
+	public static TeleportLocationData getInstance()
184
+	{
185
+		return SingletonHolder.INSTANCE;
186
+	}
187
+	
188
+	private static class SingletonHolder
189
+	{
190
+		protected static final TeleportLocationData INSTANCE = new TeleportLocationData();
191
+	}
192
+}
193
\ No newline at end of file
194
diff --git a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
195
index 5f11f94..e5aaeba 100644
196
--- a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
197
+++ b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
198
@@ -18,6 +18,7 @@
199
 import net.sf.l2j.gameserver.data.xml.NpcData;
200
 import net.sf.l2j.gameserver.data.xml.ScriptData;
201
 import net.sf.l2j.gameserver.data.xml.TeleportData;
202
+import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
203
 import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
204
 import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
205
 import net.sf.l2j.gameserver.model.actor.Player;
206
@@ -115,6 +116,7 @@
207
 				{
208
 					InstantTeleportData.getInstance().reload();
209
 					TeleportData.getInstance().reload();
210
+					TeleportLocationData.getInstance().reload();
211
 					player.sendMessage("Teleport locations have been reloaded.");
212
 				}
213
 				else if (type.startsWith("zone"))
214
diff --git a/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java b/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java
215
new file mode 100644
216
index 0000000..aebe277
217
--- /dev/null
218
+++ b/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java
219
@@ -0,0 +1,110 @@
220
+package net.sf.l2j.gameserver.model.actor.instance;
221
+
222
+import java.util.Calendar;
223
+import java.util.StringTokenizer;
224
+
225
+import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
226
+import net.sf.l2j.gameserver.model.actor.Player;
227
+import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
228
+import net.sf.l2j.gameserver.model.location.TeleportLocation;
229
+import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
230
+
231
+
232
+public final class GatekeeperVip extends Folk
233
+{
234
+	private static final int COND_BUSY_BECAUSE_OF_SIEGE = 1;
235
+	private static final int COND_OWNER = 2;
236
+	private static final int COND_REGULAR = 3;
237
+	
238
+	public GatekeeperVip(int objectId, NpcTemplate template)
239
+	{
240
+		super(objectId, template);
241
+	}
242
+	
243
+	@Override
244
+	public void onBypassFeedback(Player player, String command)
245
+	{
246
+		player.sendPacket(ActionFailed.STATIC_PACKET);
247
+		if (!player.isVip())
248
+		{
249
+			player.sendMessage("You must be vip to get this npc.");
250
+			showChatWindow(player);
251
+			return;
252
+		}
253
+		if (command.startsWith("goto"))
254
+		{
255
+			final StringTokenizer st = new StringTokenizer(command, " ");
256
+			st.nextToken();
257
+			
258
+			if (st.countTokens() <= 0)
259
+				return;
260
+			
261
+			final int condition = validateCondition(player);
262
+			if (condition == COND_REGULAR || condition == COND_OWNER)
263
+			{
264
+				if (player.isAlikeDead())
265
+					return;
266
+				
267
+				final TeleportLocation list = TeleportLocationData.getInstance().getTeleportLocation(Integer.parseInt(st.nextToken()));
268
+				if (list == null)
269
+					return;
270
+				
271
+				int price = list.getPrice();
272
+				
273
+				if (player.destroyItemByItemId("Teleport ", (list.isNoble()) ? 6651 : 57, price, this, true))
274
+					player.teleToLocation(list);
275
+				
276
+				player.sendPacket(ActionFailed.STATIC_PACKET);
277
+			}
278
+		}
279
+		else if (command.startsWith("Chat"))
280
+		{
281
+			Calendar cal = Calendar.getInstance();
282
+			int val = 0;
283
+			try
284
+			{
285
+				val = Integer.parseInt(command.substring(5));
286
+			}
287
+			catch (IndexOutOfBoundsException ioobe)
288
+			{
289
+			}
290
+			catch (NumberFormatException nfe)
291
+			{
292
+			}
293
+			
294
+			if (val == 1 && cal.get(Calendar.HOUR_OF_DAY) >= 20 && cal.get(Calendar.HOUR_OF_DAY) <= 23 && (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7))
295
+			{
296
+				return;
297
+			}
298
+			showChatWindow(player, val);
299
+		}
300
+		else
301
+			super.onBypassFeedback(player, command);
302
+	}
303
+	
304
+	@Override
305
+	public String getHtmlPath(int npcId, int val)
306
+	{
307
+		String filename = "";
308
+		if (val == 0)
309
+			filename = "" + npcId;
310
+		else
311
+			filename = npcId + "-" + val;
312
+		
313
+		return "data/html/teleporterVip/" + filename + ".htm";
314
+	}
315
+	
316
+	private int validateCondition(Player player)
317
+	{
318
+		if (getCastle() != null)
319
+		{
320
+			if (getCastle().getSiege().isInProgress())
321
+				return COND_BUSY_BECAUSE_OF_SIEGE;
322
+			
323
+			if (player.getClan() != null && getCastle().getOwnerId() == player.getClanId())
324
+				return COND_OWNER;
325
+		}
326
+		
327
+		return COND_REGULAR;
328
+	}
329
+}
330
\ No newline at end of file
331
diff --git a/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java b/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java
332
new file mode 100644
333
index 0000000..bfab7f6
334
--- /dev/null
335
+++ b/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java
336
@@ -0,0 +1,30 @@
337
+package net.sf.l2j.gameserver.model.location;
338
+
339
+import net.sf.l2j.commons.data.StatSet;
340
+
341
+/**
342
+ * A datatype extending {@link Location}, used to retain a single Gatekeeper teleport location.
343
+ */
344
+public class TeleportLocation extends Location
345
+{
346
+	public TeleportLocation(StatSet set)
347
+	{
348
+		super(set.getInteger("x"), set.getInteger("y"), set.getInteger("z"));
349
+		
350
+		_price = set.getInteger("price");
351
+		_isNoble = set.getBool("isNoble");
352
+	}
353
+	
354
+	private final int _price;
355
+	private final boolean _isNoble;
356
+	
357
+	public int getPrice()
358
+	{
359
+		return _price;
360
+	}
361
+	
362
+	public boolean isNoble()
363
+	{
364
+		return _isNoble;
365
+	}
366
+}
367
\ No newline at end of file
368