Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- diff --git java/Base/Data/XMLDocument.java java/Base/Data/XMLDocument.java
- new file mode 100644
- index 0000000..3f06c0f
- --- /dev/null
- +++ java/Base/Data/XMLDocument.java
- @@ -0,0 +1,121 @@
- +package Base.Data;
- +
- +
- +
- +import java.io.File;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import javax.xml.parsers.DocumentBuilderFactory;
- +import javax.xml.transform.OutputKeys;
- +import javax.xml.transform.Transformer;
- +import javax.xml.transform.TransformerException;
- +import javax.xml.transform.TransformerFactory;
- +import javax.xml.transform.dom.DOMSource;
- +import javax.xml.transform.stream.StreamResult;
- +
- +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());
- +
- + protected Document document;
- +
- + 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));
- + }
- +
- + public void writeDocument(Document doc, String fileName)
- + {
- + try
- + {
- + TransformerFactory transformerFactory = TransformerFactory.newInstance();
- + Transformer transformer = transformerFactory.newTransformer();
- + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- + transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- +
- + DOMSource source = new DOMSource(doc);
- + StreamResult result = new StreamResult(new File(fileName));
- +
- + transformer.transform(source, result);
- + LOG.info("XML file saved to " + fileName);
- + }
- + catch (TransformerException e)
- + {
- + LOG.warning("Error saving XML file: " + e.getMessage());
- + }
- + }
- +
- + /**
- + * 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);
- + }
- + }
- + }
- +
- + public Document getDocument()
- + {
- + return document;
- + }
- +
- + /**
- + * 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());
- + }
- + }
- +}
- diff --git java/Base/TeleportInterface/TeleLocation.java java/Base/TeleportInterface/TeleLocation.java
- new file mode 100644
- index 0000000..c552092
- --- /dev/null
- +++ java/Base/TeleportInterface/TeleLocation.java
- @@ -0,0 +1,36 @@
- +package Base.TeleportInterface;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +
- +import net.sf.l2j.gameserver.model.location.Location;
- +
- +
- +/**
- + * A datatype extending {@link Location}, used to retain a single Gatekeeper teleport location.
- + */
- +public class TeleLocation extends Location
- +{
- + public TeleLocation(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
- diff --git java/Base/TeleportInterface/TeleportLocationData.java java/Base/TeleportInterface/TeleportLocationData.java
- new file mode 100644
- index 0000000..74316f8
- --- /dev/null
- +++ java/Base/TeleportInterface/TeleportLocationData.java
- @@ -0,0 +1,82 @@
- +package Base.TeleportInterface;
- +
- +import java.io.File;
- +import java.util.HashMap;
- +import java.util.Map;
- +
- +import net.sf.l2j.commons.data.StatSet;
- +
- +
- +
- +
- +import org.w3c.dom.Document;
- +import org.w3c.dom.Node;
- +
- +import Base.Data.XMLDocument;
- +
- +/**
- + * This class loads and stores {@link TeleLocation}s.
- + */
- +public class TeleportLocationData extends XMLDocument
- +{
- + private final Map<Integer, TeleLocation> _teleports = new HashMap<>();
- +
- + protected TeleportLocationData()
- + {
- + load();
- + }
- +
- + @Override
- + protected void load()
- + {
- + loadDocument("./data/xml/teleportLocations.xml");
- + LOG.info("Loaded {} teleport locations." + _teleports.size());
- + }
- +
- + @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 TeleLocation(set));
- +
- + // Clear the StatsSet.
- + set.clear();
- + }
- + }
- +
- + public void reload()
- + {
- + _teleports.clear();
- +
- + load();
- + }
- +
- + public TeleLocation 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 java/net/sf/l2j/gameserver/GameServer.java java/net/sf/l2j/gameserver/GameServer.java
- index 852ed11..2c0ee64 100644
- --- java/net/sf/l2j/gameserver/GameServer.java
- +++ java/net/sf/l2j/gameserver/GameServer.java
- @@ -116,6 +116,7 @@
- import net.sf.l2j.util.IPv4Filter;
- import Base.DropMaster.DropMaster;
- +import Base.TeleportInterface.TeleportLocationData;
- public class GameServer
- {
- @@ -319,6 +320,10 @@
- + StringUtil.printSection("Gk Interface");
- + TeleportLocationData.getInstance();
- +
- +
- StringUtil.printSection("System");
- diff --git java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- index ac248d9..5b7cc45 100644
- --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
- @@ -28,6 +28,8 @@
- import net.sf.l2j.gameserver.model.World;
- import net.sf.l2j.gameserver.model.actor.Player;
- +import Base.TeleportInterface.TeleportLocationData;
- +
- public class AdminReload implements IAdminCommandHandler
- {
- private static final String[] ADMIN_COMMANDS =
- @@ -101,6 +103,12 @@
- MultisellData.getInstance().reload();
- player.sendMessage("The multisell instance has been reloaded.");
- }
- + else if (type.equals("teleto"))
- + {
- + TeleportLocationData.getInstance().reload();
- + player.sendMessage("Teleport Reloads.");
- + }
- +
- else if (type.equals("npc"))
- {
- NpcData.getInstance().reload();
- @@ -174,7 +182,7 @@
- player.sendMessage("Usage : //reload <admin|announcement|buylist|config>");
- player.sendMessage("Usage : //reload <crest|cw|door|htm|item|multisell|npc>");
- player.sendMessage("Usage : //reload <npcwalker|script|skill|teleport|zone>");
- - player.sendMessage("Usage : //reload <spawnlist|sysstring|capsule>");
- + player.sendMessage("Usage : //reload <spawnlist|sysstring|teleto|capsule>");
- }
- @Override
- diff --git java/net/sf/l2j/gameserver/network/SystemMessageId.java java/net/sf/l2j/gameserver/network/SystemMessageId.java
- index 12cf8b2..48a7def 100644
- --- java/net/sf/l2j/gameserver/network/SystemMessageId.java
- +++ java/net/sf/l2j/gameserver/network/SystemMessageId.java
- @@ -11795,6 +11795,7 @@
- * Message: Please wait a moment.
- */
- public static final SystemMessageId PLEASE_WAIT_A_MOMENT;
- + public static final SystemMessageId WILL_BE_MOVED_INTERFACE;
- public static final SystemMessageId DESACTIVATE_SUMMON_ACTACK;
- public static final SystemMessageId ACTIVATE_RESPECT_HUNT;
- @@ -13776,7 +13777,7 @@
- S1_CANNOT_PARTICIPATE_IN_OLYMPIAD_DURING_TELEPORT = new SystemMessageId(2029);
- CURRENTLY_LOGGING_IN = new SystemMessageId(2030);
- PLEASE_WAIT_A_MOMENT = new SystemMessageId(2031);
- -
- + WILL_BE_MOVED_INTERFACE = new SystemMessageId(2154);
- AUTO_FARM_DESACTIVATED = new SystemMessageId(2155);
- ACTIVATE_SUMMON_ACTACK = new SystemMessageId(2156);
- DESACTIVATE_SUMMON_ACTACK = new SystemMessageId(2157);
- diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- index 3da941e..a3d63c6 100644
- --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- @@ -47,6 +47,7 @@
- import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
- import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
- import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
- +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
- import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.scripting.QuestState;
- @@ -54,6 +55,8 @@
- import net.sf.l2j.gameserver.skills.L2Skill;
- import Base.AutoFarm.AutofarmPlayerRoutine;
- +import Base.TeleportInterface.TeleLocation;
- +import Base.TeleportInterface.TeleportLocationData;
- public final class RequestBypassToServer extends L2GameClientPacket
- {
- @@ -321,6 +324,61 @@
- {
- }
- }
- +
- +
- + if (_command.startsWith("goto ")) {
- + final StringTokenizer st = new StringTokenizer(_command, " ");
- + st.nextToken();
- +
- +
- + if (st.hasMoreTokens()) {
- + String targetLocation = st.nextToken();
- +
- + int teleportId = extractLastInteger(targetLocation);
- +
- +
- + if (!checkallowed(player)) {
- + return;
- + }
- +
- +
- + TeleLocation list = TeleportLocationData.getInstance().getTeleportLocation(teleportId);
- + if (list == null) {
- + return;
- + }
- +
- + if (!isNoble(player, teleportId)) {
- + player.sendMessage("Solo Los Nobles Pueden Ir a Esta Zone");
- + return;
- + }
- +
- + int price;
- +
- +
- +
- + if (shouldChargePrice(teleportId) || (player.getStatus().getLevel() > 40 )) {
- + price = list.getPrice();
- + } else {
- + price = 0;
- + }
- +
- +
- + if (player.destroyItemByItemId("Teleport", 57, price, player, true)) {
- + MagicSkillUse MSU = new MagicSkillUse(player, player, 2036, 1, 1, 0);
- + player.broadcastPacket(MSU);
- + player.teleToLocation(list);
- + player.sendPacket(new SystemMessage(SystemMessageId.WILL_BE_MOVED_INTERFACE));
- + }
- +
- + player.sendPacket(ActionFailed.STATIC_PACKET);
- + }
- + }
- +
- +
- +
- +
- +
- +
- // Navigate throught Manor windows
- else if (_command.startsWith("manor_menu_select?"))
- {
- @@ -777,5 +835,75 @@
- }
- + private int extractLastInteger(String input) {
- + String[] parts = input.split("\\.");
- + if (parts.length > 0) {
- + String lastPart = parts[parts.length - 1];
- + try {
- + return Integer.parseInt(lastPart);
- + } catch (NumberFormatException e) {
- +
- + }
- + }
- + return -1;
- + }
- +
- +
- +
- + // Función para verificar nobleza
- + private boolean isNoble(Player player, int teleportId) {
- + int[] nobleZones = {154754, 154761, 154755, 154756, 154757, 154758, 154759, 154760, 159761, 154762, 154768, 154763, 154764, 154765, 154767};
- +
- + for (int zone : nobleZones) {
- + if (teleportId == zone && !player.isNoble()) {
- + return false;
- + }
- + }
- + return true;
- + }
- +
- + // Add this new method
- + private boolean shouldChargePrice(int teleportId) {
- + int[] chargeAlwaysIds = {151782, 151791, 151785, 151787, 151786, 151783, 151788, 151784};
- +
- + for (int id : chargeAlwaysIds) {
- + if (teleportId == id) {
- + return true;
- + }
- + }
- + return false;
- + }
- +
- +
- + public static boolean checkallowed(Player activeChar)
- + {
- +
- + String msg = null;
- + if (activeChar.isSitting())
- + msg = "No Puedes Usar El Teleport Sentado";
- + else if (activeChar.isDead())
- + msg = "No Puedes Usar El Teleport Muerto";
- + else if (activeChar.getPvpFlag() > 0)
- + msg = "Estas En Modo Flag No Puedes Teleport";
- + else if (activeChar.getKarma() > 0)
- + msg = "Estas En Modo Pk No Puedes Teleport";
- + else if (activeChar.isInCombat())
- + msg = "No Puedes Usar El Teleport En Combate";
- + else if (activeChar.isInDuel())
- + msg = "No Puedes Usar El Teleport En Duelos";
- + else if (activeChar.isInOlympiadMode())
- + msg = "No Puedes Usar El Teleport En Olympiadas";
- + else if (activeChar.isInJail())
- + msg = "No Puedes Usar El Teleport En Jail";
- +
- + if (msg != null)
- + {
- + activeChar.sendMessage(msg);
- + }
- +
- + return msg == null;
- + }
- +
- +
- }
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement