AdminRepairChar.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  25. import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
  26. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. /**
  29. * This class handles following admin commands: - delete = deletes target
  30. * @version $Revision: 1.1.2.6.2.3 $ $Date: 2005/04/11 10:05:59 $
  31. */
  32. public class AdminRepairChar implements IAdminCommandHandler
  33. {
  34. private static Logger _log = Logger.getLogger(AdminRepairChar.class.getName());
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_restore",
  38. "admin_repair"
  39. };
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. handleRepair(command);
  44. return true;
  45. }
  46. @Override
  47. public String[] getAdminCommandList()
  48. {
  49. return ADMIN_COMMANDS;
  50. }
  51. private void handleRepair(String command)
  52. {
  53. String[] parts = command.split(" ");
  54. if (parts.length != 2)
  55. {
  56. return;
  57. }
  58. final String playerName = parts[1];
  59. String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
  60. try (Connection con = ConnectionFactory.getInstance().getConnection())
  61. {
  62. try (PreparedStatement ps = con.prepareStatement(cmd))
  63. {
  64. ps.setString(1, playerName);
  65. ps.execute();
  66. }
  67. final int objId = CharNameTable.getInstance().getIdByName(playerName);
  68. if (objId != 0)
  69. {
  70. // Delete player's shortcuts.
  71. try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"))
  72. {
  73. ps.setInt(1, objId);
  74. ps.execute();
  75. }
  76. // Move all items to the inventory.
  77. try (PreparedStatement ps = con.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?"))
  78. {
  79. ps.setInt(1, objId);
  80. ps.execute();
  81. }
  82. }
  83. }
  84. catch (Exception e)
  85. {
  86. _log.log(Level.WARNING, "Could not repair char:", e);
  87. }
  88. }
  89. }