Advertisement
Guest User

Custom Zone

a guest
Nov 18th, 2012
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.zone.type;
  16.  
  17. import java.io.File;
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.util.Random;
  22. import java.util.logging.Level;
  23.  
  24. import javax.xml.parsers.DocumentBuilder;
  25. import javax.xml.parsers.DocumentBuilderFactory;
  26.  
  27. import org.w3c.dom.Document;
  28. import org.w3c.dom.Element;
  29. import org.w3c.dom.Node;
  30. import org.w3c.dom.NodeList;
  31.  
  32. import com.l2jserver.Config;
  33. import com.l2jserver.L2DatabaseFactory;
  34. import com.l2jserver.gameserver.model.actor.L2Character;
  35. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  36. import com.l2jserver.gameserver.model.zone.ZoneId;
  37.  
  38. /**
  39. * @author Marwan
  40. */
  41. public class L2CustomPvP extends L2RespawnZone
  42. {
  43. // Ramdom Locations configs
  44. File fXmlFile = new File(Config.DATAPACK_ROOT + "/data/customzone.xml");
  45. DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
  46. Random random = new Random();
  47.  
  48. public L2CustomPvP(int id)
  49. {
  50. super(5555);
  51. }
  52.  
  53. public void setNewName(L2PcInstance activeChar)
  54. {
  55. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  56. PreparedStatement statement = con.prepareStatement("UPDATE characters SET pvpname=? WHERE charId=?"))
  57. {
  58. int pvpname1 = random.nextInt();
  59. statement.setString(1, "" + pvpname1);
  60. statement.setInt(2, activeChar.getObjectId());
  61. statement.execute();
  62. }
  63. catch (Exception e)
  64. {
  65. _log.log(Level.SEVERE, "Failed updating character online status.", e);
  66. }
  67. }
  68.  
  69. public void getName(L2PcInstance activeChar)
  70. {
  71. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  72. {
  73. String sql = "SELECT pvpname FROM characters WHERE charId=?";
  74. PreparedStatement statement = con.prepareStatement(sql);
  75. statement.setInt(1, activeChar.getObjectId());
  76. ResultSet rset = statement.executeQuery();
  77. while (rset.next())
  78. {
  79. String name = rset.getString("pvpname");
  80. activeChar.setName(name);
  81. activeChar.sendMessage(rset.getString("pvpname"));
  82. }
  83. rset.close();
  84. statement.close();
  85. }
  86. catch (Exception e)
  87. {
  88. _log.log(Level.SEVERE, "Could not restore premium items: " + e.getMessage(), e);
  89. }
  90. }
  91.  
  92. @Override
  93. protected void onEnter(L2Character character)
  94. {
  95.  
  96. try
  97. {
  98. DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  99. Document doc = dBuilder.parse(fXmlFile);
  100. doc.getDocumentElement().normalize();
  101. NodeList nList = doc.getElementsByTagName("enter");
  102.  
  103. for (int temp = 0; temp < nList.getLength(); temp++)
  104. {
  105.  
  106. Node nNode = nList.item(temp);
  107.  
  108. if (nNode.getNodeType() == Node.ELEMENT_NODE)
  109. {
  110. Element eElement = (Element) nNode;
  111. ((L2PcInstance) character).sendMessage(getTagValue("msg", eElement));
  112. if (getTagValue("randomName", eElement).equals("true"))
  113. {
  114. getName(((L2PcInstance) character));
  115. setNewName(((L2PcInstance) character));
  116. }
  117. if (getTagValue("parties", eElement).equals("true"))
  118. {
  119. ((L2PcInstance) character).getParty().removePartyMember(((L2PcInstance) character).getName(), null);
  120. }
  121. if (getTagValue("flag", eElement).equals("true"))
  122. {
  123. ((L2PcInstance) character).setPvpFlag(1);
  124. }
  125. }
  126. }
  127.  
  128. }
  129. catch (Exception e)
  130. {
  131. e.printStackTrace();
  132. }
  133. character.setInsideZone(ZoneId.PVP, true);
  134. }
  135.  
  136. @Override
  137. protected void onExit(L2Character character)
  138. {
  139. try
  140. {
  141. DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  142. Document doc = dBuilder.parse(fXmlFile);
  143. doc.getDocumentElement().normalize();
  144. NodeList nList = doc.getElementsByTagName("exit");
  145.  
  146. for (int temp = 0; temp < nList.getLength(); temp++)
  147. {
  148.  
  149. Node nNode = nList.item(temp);
  150.  
  151. if (nNode.getNodeType() == Node.ELEMENT_NODE)
  152. {
  153.  
  154. Element eElement = (Element) nNode;
  155. ((L2PcInstance) character).sendMessage(getTagValue("msg", eElement));
  156. if (getTagValue("flag", eElement).equals("true"))
  157. {
  158.  
  159. }
  160. }
  161. }
  162. }
  163.  
  164. catch (Exception e)
  165. {
  166. e.printStackTrace();
  167. }
  168.  
  169. }
  170.  
  171. @Override
  172. public void onDieInside(L2Character character)
  173. {
  174. try
  175. {
  176. DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
  177. Document doc = dBuilder.parse(fXmlFile);
  178. doc.getDocumentElement().normalize();
  179. NodeList nList = doc.getElementsByTagName("exit");
  180.  
  181. for (int temp = 0; temp < nList.getLength(); temp++)
  182. {
  183. Node nNode = nList.item(temp);
  184.  
  185. if (nNode.getNodeType() == Node.ELEMENT_NODE)
  186. {
  187.  
  188. Element eElement = (Element) nNode;
  189. ((L2PcInstance) character).sendMessage(getTagValue("dieMsg", eElement));
  190.  
  191. }
  192. }
  193. }
  194. catch (Exception e)
  195. {
  196. }
  197. }
  198.  
  199. private static String getTagValue(String sTag, Element eElement)
  200. {
  201. NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
  202.  
  203. Node nValue = nlList.item(0);
  204.  
  205. return nValue.getNodeValue();
  206. }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement