Advertisement
Guest User

custom name zone (l2jesios)

a guest
Nov 14th, 2012
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 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.l2jesios.gameserver.model.zone.type;
  16.  
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.util.Random;
  21. import java.util.logging.Level;
  22.  
  23. import com.l2jesios.L2DatabaseFactory;
  24. import com.l2jesios.gameserver.ThreadPoolManager;
  25. import com.l2jesios.gameserver.model.actor.L2Character;
  26. import com.l2jesios.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jesios.gameserver.model.zone.L2SpawnZone;
  28. import com.l2jesios.util.Rnd;
  29.  
  30. /**
  31. * An Custom PvP Zone
  32. * @author NeverMore
  33. */
  34. public class L2CustomPvP extends L2SpawnZone
  35. {
  36.  
  37. // Ramdom Locations configs
  38. L2PcInstance activeChar;
  39. Random random = new Random();
  40. private static int[] _x =
  41. {
  42. 11551,
  43. 10999,
  44. 10401
  45. };
  46. private static int[] _y =
  47. {
  48. -24264,
  49. -23576,
  50. -24030
  51. };
  52. private static int[] _z =
  53. {
  54. -3644,
  55. -3651,
  56. -3660
  57. };
  58.  
  59. public L2CustomPvP(int id)
  60. {
  61. super(5555);
  62. }
  63.  
  64. public void setNewName(L2PcInstance activeChar)
  65. {
  66.  
  67. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  68. PreparedStatement statement = con.prepareStatement("UPDATE characters SET pvpname=? WHERE charId=?"))
  69. {
  70. int pvpname1 = random.nextInt();
  71. statement.setString(1, "" + pvpname1);
  72. statement.setInt(2, activeChar.getObjectId());
  73. statement.execute();
  74. }
  75. catch (Exception e)
  76. {
  77. _log.log(Level.SEVERE, "Failed updating character online status.", e);
  78. }
  79. }
  80.  
  81. public void getName(L2PcInstance activeChar)
  82. {
  83. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  84. {
  85. String sql = "SELECT pvpname FROM characters WHERE charId=?";
  86. PreparedStatement statement = con.prepareStatement(sql);
  87. statement.setInt(1, activeChar.getObjectId());
  88. ResultSet rset = statement.executeQuery();
  89. while (rset.next())
  90. {
  91. String itemSender = rset.getString("pvpname");
  92. activeChar.setName(itemSender);
  93. activeChar.sendMessage(rset.getString("pvpname"));
  94. }
  95. rset.close();
  96. statement.close();
  97. }
  98. catch (Exception e)
  99. {
  100. _log.log(Level.SEVERE, "Could not restore premium items: " + e.getMessage(), e);
  101. }
  102. }
  103.  
  104. @Override
  105. protected void onEnter(L2Character character)
  106. {
  107.  
  108. if (character instanceof L2PcInstance)
  109. {
  110. setNewName(((L2PcInstance) character));
  111. getName(((L2PcInstance) character));
  112. ((L2PcInstance) character).sendMessage("You entered a PvP Area");
  113. ((L2PcInstance) character).setPvpFlag(1);
  114. }
  115. }
  116.  
  117. @Override
  118. protected void onExit(L2Character character)
  119. {
  120.  
  121. if (character instanceof L2PcInstance)
  122. {
  123. activeChar.setName(activeChar.getName());
  124. ((L2PcInstance) character).stopNoblesseBlessing(null);
  125. ((L2PcInstance) character).setPvpFlag(0);
  126. ((L2PcInstance) character).sendMessage("You exit from a PvP Area");
  127. }
  128. }
  129.  
  130. static class BackToPvp implements Runnable
  131. {
  132. private final L2Character _activeChar;
  133.  
  134. BackToPvp(L2Character character)
  135. {
  136. _activeChar = character;
  137. }
  138.  
  139. @Override
  140. public void run()
  141. {
  142. int r = Rnd.get(3);
  143. _activeChar.teleToLocation(_x[r], _y[r], _z[r]);
  144. }
  145. }
  146.  
  147. @Override
  148. public void onDieInside(L2Character character)
  149. {
  150. if (character instanceof L2PcInstance)
  151. {
  152. }
  153. }
  154.  
  155. @Override
  156. public void onReviveInside(L2Character character)
  157. {
  158. ThreadPoolManager.getInstance().scheduleGeneral(new BackToPvp(character), 500);
  159. ((L2PcInstance) character).isNoblesseBlessed();
  160. }
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement