AdminForgePacket.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 net.sf.l2j.gameserver.serverpackets;
  16. import java.math.BigInteger;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. /**
  20. * This class is made to create packets with any format
  21. * @author Maktakien
  22. *
  23. */
  24. public class AdminForgePacket extends L2GameServerPacket
  25. {
  26. private List<Part> _parts = new ArrayList<Part>();
  27. private class Part
  28. {
  29. public byte b;
  30. public String str;
  31. public Part(byte bb, String string)
  32. {
  33. b = bb;
  34. str = string;
  35. }
  36. }
  37. public AdminForgePacket()
  38. {
  39. }
  40. /* (non-Javadoc)
  41. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#writeImpl()
  42. */
  43. @Override
  44. protected void writeImpl()
  45. {
  46. for(Part p : _parts)
  47. {
  48. generate(p.b, p.str);
  49. }
  50. }
  51. /* (non-Javadoc)
  52. * @see net.sf.l2j.gameserver.BasePacket#getType()
  53. */
  54. @Override
  55. public String getType()
  56. {
  57. return "[S] -1 AdminForge";
  58. }
  59. /**
  60. * @param b
  61. * @param string
  62. */
  63. public boolean generate(byte b, String string)
  64. {
  65. // TODO Auto-generated method stub
  66. if((b == 'C')||(b == 'c'))
  67. {
  68. writeC(Integer.decode(string));
  69. return true;
  70. }
  71. else if((b == 'D')||(b == 'd'))
  72. {
  73. writeD(Integer.decode(string));
  74. return true;
  75. }
  76. else if((b == 'H')||(b == 'h'))
  77. {
  78. writeH(Integer.decode(string));
  79. return true;
  80. }
  81. else if((b == 'F')||(b == 'f'))
  82. {
  83. writeF(Double.parseDouble(string));
  84. return true;
  85. }
  86. else if((b == 'S')||(b == 's'))
  87. {
  88. writeS(string);
  89. return true;
  90. }
  91. else if((b == 'B')||(b == 'b')||(b == 'X')||(b == 'x'))
  92. {
  93. writeB(new BigInteger(string).toByteArray());
  94. return true;
  95. }
  96. return false;
  97. }
  98. public void addPart(byte b, String string)
  99. {
  100. _parts.add(new Part(b, string));
  101. }
  102. }