Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/java/net/sf/l2j/commons/data/xml/XMLDocument.java b/java/net/sf/l2j/commons/data/xml/XMLDocument.java
- new file mode 100644
- index 0000000..c1b16f8
- --- /dev/null
- +++ b/java/net/sf/l2j/commons/data/xml/XMLDocument.java
- @@ -0,0 +1,82 @@
- +package net.sf.l2j.commons.data.xml;
- +
- +import java.io.File;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.NamedNodeMap;
- +import org.w3c.dom.Node;
- +
- +/**
- + * An XML document, relying on a static and single DocumentBuilderFactory.
- + */
- +public abstract class XMLDocument
- +{
- + protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
- +
- + private static final DocumentBuilderFactory BUILDER;
- + static
- + {
- + BUILDER = DocumentBuilderFactory.newInstance();
- + BUILDER.setValidating(false);
- + BUILDER.setIgnoringComments(true);
- + }
- +
- + abstract protected void load();
- +
- + abstract protected void parseDocument(Document doc, File f);
- +
- + public void loadDocument(String filePath)
- + {
- + loadDocument(new File(filePath));
- + }
- +
- + /**
- + * Parse an entire directory or file if found.
- + * @param file
- + */
- + public void loadDocument(File file)
- + {
- + if (!file.exists())
- + {
- + LOG.severe("The following file or directory doesn't exist: " + file.getName());
- + return;
- + }
- +
- + if (file.isDirectory())
- + {
- + for (File f : file.listFiles())
- + loadDocument(f);
- + }
- + else if (file.isFile())
- + {
- + try
- + {
- + parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
- + }
- + catch (Exception e)
- + {
- + LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
- + }
- + }
- + }
- +
- + /**
- + * This method parses the content of a NamedNodeMap and feed the given StatsSet.
- + * @param attrs : The NamedNodeMap to parse.
- + * @param set : The StatsSet to feed.
- + */
- + public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
- + {
- + for (int i = 0; i < attrs.getLength(); i++)
- + {
- + final Node attr = attrs.item(i);
- + set.set(attr.getNodeName(), attr.getNodeValue());
- + }
- + }
- +}
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java
- index e682cc6..6c1638e 100644
- --- a/java/net/sf/l2j/gameserver/GameServer.java
- +++ b/java/net/sf/l2j/gameserver/GameServer.java
- @@ -72,6 +72,7 @@
- import net.sf.l2j.gameserver.data.xml.StaticObjectData;
- import net.sf.l2j.gameserver.data.xml.SummonItemData;
- import net.sf.l2j.gameserver.data.xml.TeleportData;
- +import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
- import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
- import net.sf.l2j.gameserver.geoengine.GeoEngine;
- import net.sf.l2j.gameserver.handler.AdminCommandHandler;
- @@ -232,6 +233,7 @@
- DimensionalRiftManager.getInstance();
- NewbieBuffData.getInstance();
- InstantTeleportData.getInstance();
- + TeleportLocationData.getInstance();
- TeleportData.getInstance();
- StringUtil.printSection("Olympiads & Heroes");
- diff --git a/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java b/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java
- new file mode 100644
- index 0000000..a19af62
- --- /dev/null
- +++ b/java/net/sf/l2j/gameserver/data/xml/TeleportLocationData.java
- @@ -0,0 +1,77 @@
- +package net.sf.l2j.gameserver.data.xml;
- +
- +import java.io.File;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +import net.sf.l2j.commons.data.xml.XMLDocument;
- +
- +import net.sf.l2j.gameserver.model.location.TeleportLocation;
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.Node;
- +
- +public class TeleportLocationData extends XMLDocument
- +{
- + private final Map<Integer, TeleportLocation> _teleports = new HashMap<>();
- +
- + protected TeleportLocationData()
- + {
- + load();
- + }
- +
- + @Override
- + protected void load()
- + {
- + loadDocument("./data/xml/teleportVip.xml");
- + LOG.info("Loaded " + _teleports.size() + " teleport locations.");
- + }
- +
- + @Override
- + protected void parseDocument(Document doc, File file)
- + {
- + // StatsSet used to feed informations. Cleaned on every entry.
- + final StatSet set = new StatSet();
- +
- + // First element is never read.
- + final Node n = doc.getFirstChild();
- +
- + for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
- + {
- + if (!"teleport".equalsIgnoreCase(o.getNodeName()))
- + continue;
- +
- + // Parse and feed content.
- + parseAndFeed(o.getAttributes(), set);
- +
- + // Feed the map with new data.
- + _teleports.put(set.getInteger("id"), new TeleportLocation(set));
- +
- + // Clear the StatsSet.
- + set.clear();
- + }
- + }
- +
- + public void reload()
- + {
- + _teleports.clear();
- +
- + load();
- + }
- +
- + public TeleportLocation getTeleportLocation(int id)
- + {
- + return _teleports.get(id);
- + }
- +
- + public static TeleportLocationData getInstance()
- + {
- + return SingletonHolder.INSTANCE;
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final TeleportLocationData INSTANCE = new TeleportLocationData();
- + }
- +}
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- index 5f11f94..e5aaeba 100644
- --- a/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- +++ b/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- @@ -18,6 +18,7 @@
- import net.sf.l2j.gameserver.data.xml.NpcData;
- import net.sf.l2j.gameserver.data.xml.ScriptData;
- import net.sf.l2j.gameserver.data.xml.TeleportData;
- +import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
- import net.sf.l2j.gameserver.data.xml.WalkerRouteData;
- import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
- import net.sf.l2j.gameserver.model.actor.Player;
- @@ -115,6 +116,7 @@
- {
- InstantTeleportData.getInstance().reload();
- TeleportData.getInstance().reload();
- + TeleportLocationData.getInstance().reload();
- player.sendMessage("Teleport locations have been reloaded.");
- }
- else if (type.startsWith("zone"))
- diff --git a/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java b/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java
- new file mode 100644
- index 0000000..aebe277
- --- /dev/null
- +++ b/java/net/sf/l2j/gameserver/model/actor/instance/GatekeeperVip.java
- @@ -0,0 +1,110 @@
- +package net.sf.l2j.gameserver.model.actor.instance;
- +
- +import java.util.Calendar;
- +import java.util.StringTokenizer;
- +
- +import net.sf.l2j.gameserver.data.xml.TeleportLocationData;
- +import net.sf.l2j.gameserver.model.actor.Player;
- +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
- +import net.sf.l2j.gameserver.model.location.TeleportLocation;
- +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- +
- +
- +public final class GatekeeperVip extends Folk
- +{
- + private static final int COND_BUSY_BECAUSE_OF_SIEGE = 1;
- + private static final int COND_OWNER = 2;
- + private static final int COND_REGULAR = 3;
- +
- + public GatekeeperVip(int objectId, NpcTemplate template)
- + {
- + super(objectId, template);
- + }
- +
- + @Override
- + public void onBypassFeedback(Player player, String command)
- + {
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + if (!player.isVip())
- + {
- + player.sendMessage("You must be vip to get this npc.");
- + showChatWindow(player);
- + return;
- + }
- + if (command.startsWith("goto"))
- + {
- + final StringTokenizer st = new StringTokenizer(command, " ");
- + st.nextToken();
- +
- + if (st.countTokens() <= 0)
- + return;
- +
- + final int condition = validateCondition(player);
- + if (condition == COND_REGULAR || condition == COND_OWNER)
- + {
- + if (player.isAlikeDead())
- + return;
- +
- + final TeleportLocation list = TeleportLocationData.getInstance().getTeleportLocation(Integer.parseInt(st.nextToken()));
- + if (list == null)
- + return;
- +
- + int price = list.getPrice();
- +
- + if (player.destroyItemByItemId("Teleport ", (list.isNoble()) ? 6651 : 57, price, this, true))
- + player.teleToLocation(list);
- +
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + }
- + }
- + else if (command.startsWith("Chat"))
- + {
- + Calendar cal = Calendar.getInstance();
- + int val = 0;
- + try
- + {
- + val = Integer.parseInt(command.substring(5));
- + }
- + catch (IndexOutOfBoundsException ioobe)
- + {
- + }
- + catch (NumberFormatException nfe)
- + {
- + }
- +
- + 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))
- + {
- + return;
- + }
- + showChatWindow(player, val);
- + }
- + else
- + super.onBypassFeedback(player, command);
- + }
- +
- + @Override
- + public String getHtmlPath(int npcId, int val)
- + {
- + String filename = "";
- + if (val == 0)
- + filename = "" + npcId;
- + else
- + filename = npcId + "-" + val;
- +
- + return "data/html/teleporterVip/" + filename + ".htm";
- + }
- +
- + private int validateCondition(Player player)
- + {
- + if (getCastle() != null)
- + {
- + if (getCastle().getSiege().isInProgress())
- + return COND_BUSY_BECAUSE_OF_SIEGE;
- +
- + if (player.getClan() != null && getCastle().getOwnerId() == player.getClanId())
- + return COND_OWNER;
- + }
- +
- + return COND_REGULAR;
- + }
- +}
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java b/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java
- new file mode 100644
- index 0000000..bfab7f6
- --- /dev/null
- +++ b/java/net/sf/l2j/gameserver/model/location/TeleportLocation.java
- @@ -0,0 +1,30 @@
- +package net.sf.l2j.gameserver.model.location;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +
- +/**
- + * A datatype extending {@link Location}, used to retain a single Gatekeeper teleport location.
- + */
- +public class TeleportLocation extends Location
- +{
- + public TeleportLocation(StatSet set)
- + {
- + super(set.getInteger("x"), set.getInteger("y"), set.getInteger("z"));
- +
- + _price = set.getInteger("price");
- + _isNoble = set.getBool("isNoble");
- + }
- +
- + private final int _price;
- + private final boolean _isNoble;
- +
- + public int getPrice()
- + {
- + return _price;
- + }
- +
- + public boolean isNoble()
- + {
- + return _isNoble;
- + }
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement