Advertisement
tensador125

l2j rusacis gk interface == royale

Jan 2nd, 2024 (edited)
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.59 KB | Gaming | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. diff --git java/Base/Data/XMLDocument.java java/Base/Data/XMLDocument.java
  4. new file mode 100644
  5. index 0000000..3f06c0f
  6. --- /dev/null
  7. +++ java/Base/Data/XMLDocument.java
  8. @@ -0,0 +1,121 @@
  9. +package Base.Data;
  10. +
  11. +
  12. +
  13. +import java.io.File;
  14. +import java.util.logging.Level;
  15. +import java.util.logging.Logger;
  16. +
  17. +import javax.xml.parsers.DocumentBuilderFactory;
  18. +import javax.xml.transform.OutputKeys;
  19. +import javax.xml.transform.Transformer;
  20. +import javax.xml.transform.TransformerException;
  21. +import javax.xml.transform.TransformerFactory;
  22. +import javax.xml.transform.dom.DOMSource;
  23. +import javax.xml.transform.stream.StreamResult;
  24. +
  25. +import net.sf.l2j.commons.data.StatSet;
  26. +
  27. +import org.w3c.dom.Document;
  28. +import org.w3c.dom.NamedNodeMap;
  29. +import org.w3c.dom.Node;
  30. +
  31. +/**
  32. + * An XML document, relying on a static and single DocumentBuilderFactory.
  33. + */
  34. +public abstract class XMLDocument
  35. +{
  36. +   protected static final Logger LOG = Logger.getLogger(XMLDocument.class.getName());
  37. +  
  38. +   protected Document document;
  39. +  
  40. +   private static final DocumentBuilderFactory BUILDER;
  41. +   static
  42. +   {
  43. +       BUILDER = DocumentBuilderFactory.newInstance();
  44. +       BUILDER.setValidating(false);
  45. +       BUILDER.setIgnoringComments(true);
  46. +   }
  47. +  
  48. +   abstract protected void load();
  49. +  
  50. +   abstract protected void parseDocument(Document doc, File f);
  51. +  
  52. +   public void loadDocument(String filePath)
  53. +   {
  54. +       loadDocument(new File(filePath));
  55. +   }
  56. +  
  57. +   public void writeDocument(Document doc, String fileName)
  58. +   {
  59. +       try
  60. +       {
  61. +           TransformerFactory transformerFactory = TransformerFactory.newInstance();
  62. +           Transformer transformer = transformerFactory.newTransformer();
  63. +           transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  64. +           transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  65. +           transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  66. +          
  67. +           DOMSource source = new DOMSource(doc);
  68. +           StreamResult result = new StreamResult(new File(fileName));
  69. +          
  70. +           transformer.transform(source, result);
  71. +           LOG.info("XML file saved to " + fileName);
  72. +       }
  73. +       catch (TransformerException e)
  74. +       {
  75. +           LOG.warning("Error saving XML file: " + e.getMessage());
  76. +       }
  77. +   }
  78. +  
  79. +   /**
  80. +    * Parse an entire directory or file if found.
  81. +    * @param file
  82. +    */
  83. +   public void loadDocument(File file)
  84. +   {
  85. +       if (!file.exists())
  86. +       {
  87. +           LOG.severe("The following file or directory doesn't exist: " + file.getName());
  88. +           return;
  89. +       }
  90. +      
  91. +       if (file.isDirectory())
  92. +       {
  93. +           for (File f : file.listFiles())
  94. +           {
  95. +               loadDocument(f);
  96. +           }
  97. +       }
  98. +       else if (file.isFile())
  99. +       {
  100. +           try
  101. +           {
  102. +               parseDocument(BUILDER.newDocumentBuilder().parse(file), file);
  103. +           }
  104. +           catch (Exception e)
  105. +           {
  106. +               LOG.log(Level.SEVERE, "Error loading XML file " + file.getName(), e);
  107. +           }
  108. +       }
  109. +   }
  110. +  
  111. +   public Document getDocument()
  112. +   {
  113. +       return document;
  114. +   }
  115. +  
  116. +   /**
  117. +    * This method parses the content of a NamedNodeMap and feed the given StatsSet.
  118. +    * @param attrs : The NamedNodeMap to parse.
  119. +    * @param set : The StatsSet to feed.
  120. +    */
  121. +   public static void parseAndFeed(NamedNodeMap attrs, StatSet set)
  122. +   {
  123. +       for (int i = 0; i < attrs.getLength(); i++)
  124. +       {
  125. +           final Node attr = attrs.item(i);
  126. +           set.set(attr.getNodeName(), attr.getNodeValue());
  127. +       }
  128. +   }
  129. +}
  130. diff --git java/Base/TeleportInterface/TeleLocation.java java/Base/TeleportInterface/TeleLocation.java
  131. new file mode 100644
  132. index 0000000..c552092
  133. --- /dev/null
  134. +++ java/Base/TeleportInterface/TeleLocation.java
  135. @@ -0,0 +1,36 @@
  136. +package Base.TeleportInterface;
  137. +
  138. +import net.sf.l2j.commons.data.StatSet;
  139. +
  140. +import net.sf.l2j.gameserver.model.location.Location;
  141. +
  142. +
  143. +/**
  144. + * A datatype extending {@link Location}, used to retain a single Gatekeeper teleport location.
  145. + */
  146. +public class TeleLocation extends Location
  147. +{
  148. +   public TeleLocation(StatSet set)
  149. +   {
  150. +       super(set.getInteger("x"), set.getInteger("y"), set.getInteger("z"));
  151. +
  152. +  
  153. +       _price = set.getInteger("price");
  154. +      
  155. +       _isNoble = set.getBool("isNoble");
  156. +   }
  157. +
  158. +  
  159. +   private final int _price;
  160. +   private final boolean _isNoble;
  161. +  
  162. +   public int getPrice()
  163. +   {
  164. +       return _price;
  165. +   }
  166. +  
  167. +   public boolean isNoble()
  168. +   {
  169. +       return _isNoble;
  170. +   }
  171. +}
  172. \ No newline at end of file
  173. diff --git java/Base/TeleportInterface/TeleportLocationData.java java/Base/TeleportInterface/TeleportLocationData.java
  174. new file mode 100644
  175. index 0000000..74316f8
  176. --- /dev/null
  177. +++ java/Base/TeleportInterface/TeleportLocationData.java
  178. @@ -0,0 +1,82 @@
  179. +package Base.TeleportInterface;
  180. +
  181. +import java.io.File;
  182. +import java.util.HashMap;
  183. +import java.util.Map;
  184. +
  185. +import net.sf.l2j.commons.data.StatSet;
  186. +
  187. +
  188. +
  189. +
  190. +import org.w3c.dom.Document;
  191. +import org.w3c.dom.Node;
  192. +
  193. +import Base.Data.XMLDocument;
  194. +
  195. +/**
  196. + * This class loads and stores {@link TeleLocation}s.
  197. + */
  198. +public class TeleportLocationData extends XMLDocument
  199. +{
  200. +   private final Map<Integer, TeleLocation> _teleports = new HashMap<>();
  201. +  
  202. +   protected TeleportLocationData()
  203. +   {
  204. +       load();
  205. +   }
  206. +  
  207. +   @Override
  208. +   protected void load()
  209. +   {
  210. +       loadDocument("./data/xml/teleportLocations.xml");
  211. +       LOG.info("Loaded {} teleport locations." + _teleports.size());
  212. +   }
  213. +  
  214. +   @Override
  215. +   protected void parseDocument(Document doc, File file)
  216. +   {
  217. +       // StatsSet used to feed informations. Cleaned on every entry.
  218. +       final StatSet set = new StatSet();
  219. +      
  220. +       // First element is never read.
  221. +       final Node n = doc.getFirstChild();
  222. +      
  223. +       for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
  224. +       {
  225. +           if (!"teleport".equalsIgnoreCase(o.getNodeName()))
  226. +               continue;
  227. +          
  228. +           // Parse and feed content.
  229. +           parseAndFeed(o.getAttributes(), set);
  230. +          
  231. +           // Feed the map with new data.
  232. +           _teleports.put(set.getInteger("id"), new TeleLocation(set));
  233. +          
  234. +           // Clear the StatsSet.
  235. +           set.clear();
  236. +       }
  237. +   }
  238. +  
  239. +   public void reload()
  240. +   {
  241. +       _teleports.clear();
  242. +      
  243. +       load();
  244. +   }
  245. +  
  246. +   public TeleLocation getTeleportLocation(int id)
  247. +   {
  248. +       return _teleports.get(id);
  249. +   }
  250. +  
  251. +   public static TeleportLocationData getInstance()
  252. +   {
  253. +       return SingletonHolder.INSTANCE;
  254. +   }
  255. +  
  256. +   private static class SingletonHolder
  257. +   {
  258. +       protected static final TeleportLocationData INSTANCE = new TeleportLocationData();
  259. +   }
  260. +}
  261. \ No newline at end of file
  262. diff --git java/net/sf/l2j/gameserver/GameServer.java java/net/sf/l2j/gameserver/GameServer.java
  263. index 852ed11..2c0ee64 100644
  264. --- java/net/sf/l2j/gameserver/GameServer.java
  265. +++ java/net/sf/l2j/gameserver/GameServer.java
  266. @@ -116,6 +116,7 @@
  267.  import net.sf.l2j.util.IPv4Filter;
  268.  
  269.  import Base.DropMaster.DropMaster;
  270. +import Base.TeleportInterface.TeleportLocationData;
  271.  
  272.  public class GameServer
  273.  {
  274. @@ -319,6 +320,10 @@
  275.        
  276.        
  277.  
  278. +       StringUtil.printSection("Gk Interface");
  279. +       TeleportLocationData.getInstance();
  280. +      
  281. +      
  282.        
  283.        
  284.         StringUtil.printSection("System");
  285. diff --git java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  286. index ac248d9..5b7cc45 100644
  287. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  288. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminReload.java
  289. @@ -28,6 +28,8 @@
  290.  import net.sf.l2j.gameserver.model.World;
  291.  import net.sf.l2j.gameserver.model.actor.Player;
  292.  
  293. +import Base.TeleportInterface.TeleportLocationData;
  294. +
  295.  public class AdminReload implements IAdminCommandHandler
  296.  {
  297.     private static final String[] ADMIN_COMMANDS =
  298. @@ -101,6 +103,12 @@
  299.                     MultisellData.getInstance().reload();
  300.                     player.sendMessage("The multisell instance has been reloaded.");
  301.                 }
  302. +               else if (type.equals("teleto"))
  303. +               {
  304. +                   TeleportLocationData.getInstance().reload();
  305. +                   player.sendMessage("Teleport Reloads.");
  306. +               }
  307. +              
  308.                 else if (type.equals("npc"))
  309.                 {
  310.                     NpcData.getInstance().reload();
  311. @@ -174,7 +182,7 @@
  312.         player.sendMessage("Usage : //reload <admin|announcement|buylist|config>");
  313.         player.sendMessage("Usage : //reload <crest|cw|door|htm|item|multisell|npc>");
  314.         player.sendMessage("Usage : //reload <npcwalker|script|skill|teleport|zone>");
  315. -       player.sendMessage("Usage : //reload <spawnlist|sysstring|capsule>");
  316. +       player.sendMessage("Usage : //reload <spawnlist|sysstring|teleto|capsule>");
  317.     }
  318.    
  319.     @Override
  320. diff --git java/net/sf/l2j/gameserver/network/SystemMessageId.java java/net/sf/l2j/gameserver/network/SystemMessageId.java
  321. index 12cf8b2..48a7def 100644
  322. --- java/net/sf/l2j/gameserver/network/SystemMessageId.java
  323. +++ java/net/sf/l2j/gameserver/network/SystemMessageId.java
  324. @@ -11795,6 +11795,7 @@
  325.      * Message: Please wait a moment.
  326.      */
  327.     public static final SystemMessageId PLEASE_WAIT_A_MOMENT;
  328. +   public static final SystemMessageId WILL_BE_MOVED_INTERFACE;
  329.    
  330.     public static final SystemMessageId DESACTIVATE_SUMMON_ACTACK; 
  331.     public static final SystemMessageId ACTIVATE_RESPECT_HUNT;
  332. @@ -13776,7 +13777,7 @@
  333.         S1_CANNOT_PARTICIPATE_IN_OLYMPIAD_DURING_TELEPORT = new SystemMessageId(2029);
  334.         CURRENTLY_LOGGING_IN = new SystemMessageId(2030);
  335.         PLEASE_WAIT_A_MOMENT = new SystemMessageId(2031);
  336. -      
  337. +       WILL_BE_MOVED_INTERFACE = new SystemMessageId(2154);
  338.         AUTO_FARM_DESACTIVATED = new SystemMessageId(2155);
  339.         ACTIVATE_SUMMON_ACTACK = new SystemMessageId(2156);
  340.         DESACTIVATE_SUMMON_ACTACK = new SystemMessageId(2157);     
  341. diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  342. index 3da941e..a3d63c6 100644
  343. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  344. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  345. @@ -47,6 +47,7 @@
  346.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  347.  import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
  348.  import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage.SMPOS;
  349. +import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  350.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  351.  import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  352.  import net.sf.l2j.gameserver.scripting.QuestState;
  353. @@ -54,6 +55,8 @@
  354.  import net.sf.l2j.gameserver.skills.L2Skill;
  355.  
  356.  import Base.AutoFarm.AutofarmPlayerRoutine;
  357. +import Base.TeleportInterface.TeleLocation;
  358. +import Base.TeleportInterface.TeleportLocationData;
  359.  
  360.  public final class RequestBypassToServer extends L2GameClientPacket
  361.  {
  362. @@ -321,6 +324,61 @@
  363.             {
  364.             }
  365.         }
  366. +      
  367. +      
  368. +          if (_command.startsWith("goto ")) {
  369. +               final StringTokenizer st = new StringTokenizer(_command, " ");
  370. +               st.nextToken();
  371. +
  372. +              
  373. +               if (st.hasMoreTokens()) {
  374. +                   String targetLocation = st.nextToken();
  375. +                  
  376. +                   int teleportId = extractLastInteger(targetLocation);
  377. +
  378. +                  
  379. +                   if (!checkallowed(player)) {
  380. +                       return;
  381. +                   }
  382. +
  383. +                  
  384. +                   TeleLocation list = TeleportLocationData.getInstance().getTeleportLocation(teleportId);
  385. +                   if (list == null) {
  386. +                       return;
  387. +                   }
  388. +
  389. +                   if (!isNoble(player, teleportId)) {
  390. +                       player.sendMessage("Solo Los Nobles Pueden Ir a Esta Zone");
  391. +                       return;
  392. +                       }
  393. +                  
  394. +                   int price;
  395. +                  
  396. +                  
  397. +                
  398. +                   if (shouldChargePrice(teleportId) || (player.getStatus().getLevel() > 40 )) {
  399. +                       price = list.getPrice();
  400. +                   } else {
  401. +                       price = 0;
  402. +                   }
  403. +
  404. +                  
  405. +                   if (player.destroyItemByItemId("Teleport", 57, price, player, true)) {
  406. +                       MagicSkillUse MSU = new MagicSkillUse(player, player, 2036, 1, 1, 0);
  407. +                       player.broadcastPacket(MSU);
  408. +                       player.teleToLocation(list);
  409. +                       player.sendPacket(new SystemMessage(SystemMessageId.WILL_BE_MOVED_INTERFACE));
  410. +                   }
  411. +
  412. +                   player.sendPacket(ActionFailed.STATIC_PACKET);
  413. +               }
  414. +           }
  415. +      
  416. +      
  417. +      
  418. +      
  419. +      
  420. +      
  421.         // Navigate throught Manor windows
  422.         else if (_command.startsWith("manor_menu_select?"))
  423.         {
  424. @@ -777,5 +835,75 @@
  425.       }
  426.  
  427.    
  428. +      private int extractLastInteger(String input) {
  429. +           String[] parts = input.split("\\.");
  430. +           if (parts.length > 0) {
  431. +               String lastPart = parts[parts.length - 1];
  432. +               try {
  433. +                   return Integer.parseInt(lastPart);
  434. +               } catch (NumberFormatException e) {
  435. +                  
  436. +               }
  437. +           }
  438. +           return -1;
  439. +       }
  440. +      
  441. +      
  442. +
  443. +       // Función para verificar nobleza
  444. +       private boolean isNoble(Player player, int teleportId) {
  445. +       int[] nobleZones = {154754, 154761, 154755, 154756, 154757, 154758, 154759, 154760, 159761, 154762, 154768, 154763, 154764, 154765, 154767};
  446. +        
  447. +       for (int zone : nobleZones) {
  448. +       if (teleportId == zone && !player.isNoble()) {
  449. +       return false;
  450. +       }
  451. +       }
  452. +       return true;
  453. +       }
  454. +      
  455. +    // Add this new method
  456. +       private boolean shouldChargePrice(int teleportId) {
  457. +           int[] chargeAlwaysIds = {151782, 151791, 151785, 151787, 151786, 151783, 151788, 151784};
  458. +
  459. +           for (int id : chargeAlwaysIds) {
  460. +               if (teleportId == id) {
  461. +                   return true;
  462. +               }
  463. +           }
  464. +           return false;
  465. +       }  
  466. +      
  467. +      
  468. +       public static boolean checkallowed(Player activeChar)
  469. +       {
  470. +          
  471. +           String msg = null;
  472. +           if (activeChar.isSitting())
  473. +               msg = "No Puedes Usar El Teleport Sentado";
  474. +           else if (activeChar.isDead())
  475. +               msg = "No Puedes Usar El Teleport Muerto";
  476. +           else if (activeChar.getPvpFlag() > 0)
  477. +               msg = "Estas En Modo Flag No Puedes Teleport";
  478. +           else if (activeChar.getKarma() > 0)
  479. +               msg = "Estas En Modo Pk No Puedes Teleport";
  480. +           else if (activeChar.isInCombat())
  481. +               msg = "No Puedes Usar El Teleport En Combate";
  482. +           else if (activeChar.isInDuel())
  483. +               msg = "No Puedes Usar El Teleport En Duelos";
  484. +           else if (activeChar.isInOlympiadMode())
  485. +               msg = "No Puedes Usar El Teleport En Olympiadas";
  486. +           else if (activeChar.isInJail())
  487. +               msg = "No Puedes Usar El Teleport En Jail";
  488. +          
  489. +           if (msg != null)
  490. +           {
  491. +               activeChar.sendMessage(msg);
  492. +           }
  493. +          
  494. +           return msg == null;
  495. +       }    
  496. +    
  497. +    
  498.    
  499.  }
  500. \ No newline at end of file
  501.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement