warc222

Vip/donate Item {Reshared}

Sep 29th, 2015
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P L2jFrozen_Gs
  3. Index: head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java
  4. ===================================================================
  5. --- head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java (revision 946)
  6. +++ head-src/com/l2jfrozen/gameserver/handler/ItemHandler.java (working copy)
  7. @@ -65,6 +66,7 @@
  8. import com.l2jfrozen.gameserver.handler.itemhandlers.SpecialXMas;
  9. import com.l2jfrozen.gameserver.handler.itemhandlers.SpiritShot;
  10. import com.l2jfrozen.gameserver.handler.itemhandlers.SummonItems;
  11. +import com.l2jfrozen.gameserver.handler.itemhandlers.VipItem;
  12.  
  13. /**
  14. * This class manages handlers of items
  15. @@ -144,6 +147,7 @@
  16. registerItemHandler(new ExtractableItems());
  17. registerItemHandler(new SpecialXMas());
  18. registerItemHandler(new SummonItems());
  19. + registerItemHandler(new VipItem());
  20. registerItemHandler(new BeastSpice());
  21. registerItemHandler(new JackpotSeed());
  22. registerItemHandler(new NobleCustomItem());
  23.  
  24. ### Eclipse Workspace Patch 1.0
  25. #P L2jFrozen_Gs
  26. Index: head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java
  27. ===================================================================
  28. --- head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java (revision 0)
  29. +++ head-src/com/l2jfrozen/gameserver/handler/itemhandlers/VipItem.java (working copy)
  30. @@ -0,0 +1,145 @@
  31. +/*
  32. + * This program is free software: you can redistribute it and/or modify it under
  33. + * the terms of the GNU General Public License as published by the Free Software
  34. + * Foundation, either version 3 of the License, or (at your option) any later
  35. + * version.
  36. + *
  37. + * This program is distributed in the hope that it will be useful, but WITHOUT
  38. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  39. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  40. + * details.
  41. + *
  42. + * You should have received a copy of the GNU General Public License along with
  43. + * this program. If not, see <http://www.gnu.org/licenses/>.
  44. + */
  45. +package com.l2jfrozen.gameserver.handler.itemhandlers;
  46. +
  47. +import java.sql.Connection;
  48. +import java.sql.PreparedStatement;
  49. +import com.l2jfrozen.Config;
  50. +import com.l2jfrozen.gameserver.handler.IItemHandler;
  51. +import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  52. +import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  53. +import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
  54. +import com.l2jfrozen.util.CloseUtil;
  55. +import com.l2jfrozen.util.database.L2DatabaseFactory;
  56. +
  57. +/**
  58. + * @author Crystalia
  59. + *
  60. + */
  61. +public class VipItem implements IItemHandler
  62. +{
  63. +
  64. + private static final int ITEM_IDS[] = {
  65. + 6673
  66. + };
  67. +
  68. + @Override
  69. + public int[] getItemIds()
  70. + {
  71. + return ITEM_IDS;
  72. + }
  73. +
  74. + private void updateDatabase(L2PcInstance player, boolean newDonator)
  75. + {
  76. + Connection con = null;
  77. + try
  78. + {
  79. + // prevents any NPE.
  80. + // ----------------
  81. + if(player == null)
  82. + return;
  83. +
  84. + // Database Connection
  85. + //--------------------------------
  86. + con = L2DatabaseFactory.getInstance().getConnection(false);
  87. + PreparedStatement stmt = con.prepareStatement(newDonator ? INSERT_DATA : DEL_DATA);
  88. +
  89. + // if it is a new donator insert proper data
  90. + // --------------------------------------------
  91. + if(newDonator)
  92. + {
  93. + stmt.setInt(1, player.getObjectId());
  94. + stmt.setString(2, player.getName());
  95. + stmt.setInt(3, player.isHero() ? 1 : 0);
  96. + stmt.setInt(4, player.isNoble() ? 1 : 0);
  97. + stmt.setInt(5, 1);
  98. + stmt.execute();
  99. + stmt.close();
  100. + stmt = null;
  101. + }
  102. + else
  103. + // deletes from database
  104. + {
  105. + stmt.setInt(1, player.getObjectId());
  106. + stmt.execute();
  107. + stmt.close();
  108. + stmt = null;
  109. + }
  110. + }
  111. + catch(Exception e)
  112. + {
  113. + if(Config.ENABLE_ALL_EXCEPTIONS)
  114. + e.printStackTrace();
  115. +
  116. +
  117. + }
  118. + finally
  119. + {
  120. + CloseUtil.close(con);
  121. + }
  122. + }
  123. +
  124. + // Updates That Will be Executed by MySQL
  125. + // ----------------------------------------
  126. + String INSERT_DATA = "REPLACE INTO characters_custom_data (obj_Id, char_name, hero, noble, donator) VALUES (?,?,?,?,?)";
  127. + String DEL_DATA = "UPDATE characters_custom_data SET donator = 0 WHERE obj_Id=?";
  128. +
  129. + @Override
  130. + public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  131. + {
  132. + if(!(playable instanceof L2PcInstance))
  133. + return;
  134. + L2PcInstance activeChar = (L2PcInstance)playable;
  135. +
  136. + if(activeChar.isDonator())
  137. + {
  138. + activeChar.sendMessage("You are already a donator.You cannot use that item.");
  139. + return;
  140. + }
  141. + playable.destroyItem("Consume", item.getObjectId(), 1, null, false);
  142. + activeChar.setDonator(true);
  143. + updateDatabase(activeChar, true);
  144. + activeChar.sendMessage("Thanks for using our item in order to be server's donator.");
  145. + activeChar.broadcastUserInfo();
  146. +
  147. +
  148. + }
  149. +
  150. +}
  151. \ No newline at end of file
Add Comment
Please, Sign In to add comment