RequestChangePetName.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.network.clientpackets;
  16. import com.l2jserver.gameserver.datatables.PetNameTable;
  17. import com.l2jserver.gameserver.model.actor.L2Character;
  18. import com.l2jserver.gameserver.model.actor.L2Summon;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  21. /**
  22. * This class ...
  23. *
  24. * @version $Revision: 1.3.4.4 $ $Date: 2005/04/06 16:13:48 $
  25. */
  26. public final class RequestChangePetName extends L2GameClientPacket
  27. {
  28. private static final String REQUESTCHANGEPETNAME__C__89 = "[C] 89 RequestChangePetName";
  29. //private static Logger _log = Logger.getLogger(RequestChangePetName.class.getName());
  30. private String _name;
  31. @Override
  32. protected void readImpl()
  33. {
  34. _name = readS();
  35. }
  36. @Override
  37. protected void runImpl()
  38. {
  39. L2Character activeChar = getClient().getActiveChar();
  40. if (activeChar == null)
  41. return;
  42. final L2Summon pet = activeChar.getPet();
  43. if (pet == null)
  44. return;
  45. if (pet.getName() != null)
  46. {
  47. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_YOU_CANNOT_SET_NAME_OF_THE_PET));
  48. return;
  49. }
  50. else if (PetNameTable.getInstance().doesPetNameExist(_name, pet.getTemplate().npcId))
  51. {
  52. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_ALREADY_IN_USE_BY_ANOTHER_PET));
  53. return;
  54. }
  55. else if ((_name.length() < 3) || (_name.length() > 16))
  56. {
  57. // SystemMessage sm = new SystemMessage(SystemMessage.NAMING_PETNAME_UP_TO_8CHARS);
  58. activeChar.sendMessage("Your pet's name can be up to 16 characters.");
  59. return;
  60. }
  61. else if (!PetNameTable.getInstance().isValidPetName(_name))
  62. {
  63. activeChar.sendPacket(new SystemMessage(SystemMessageId.NAMING_PETNAME_CONTAINS_INVALID_CHARS));
  64. return;
  65. }
  66. pet.setName(_name);
  67. pet.updateAndBroadcastStatus(1);
  68. }
  69. @Override
  70. public String getType()
  71. {
  72. return REQUESTCHANGEPETNAME__C__89;
  73. }
  74. }