Advertisement
Guest User

zone name system

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