AdminRepairChar.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 handlers.admincommandhandlers;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.logging.Level;
  20. import java.util.logging.Logger;
  21. import com.l2jserver.L2DatabaseFactory;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. /**
  25. * This class handles following admin commands: - delete = deletes target
  26. *
  27. * @version $Revision: 1.1.2.6.2.3 $ $Date: 2005/04/11 10:05:59 $
  28. */
  29. public class AdminRepairChar implements IAdminCommandHandler
  30. {
  31. private static Logger _log = Logger.getLogger(AdminRepairChar.class.getName());
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_restore",
  35. "admin_repair"
  36. };
  37. @Override
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. handleRepair(command);
  41. return true;
  42. }
  43. @Override
  44. public String[] getAdminCommandList()
  45. {
  46. return ADMIN_COMMANDS;
  47. }
  48. private void handleRepair(String command)
  49. {
  50. String[] parts = command.split(" ");
  51. if (parts.length != 2)
  52. {
  53. return;
  54. }
  55. String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
  56. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  57. {
  58. PreparedStatement statement = con.prepareStatement(cmd);
  59. statement.setString(1, parts[1]);
  60. statement.execute();
  61. statement.close();
  62. statement = con.prepareStatement("SELECT charId FROM characters where char_name=?");
  63. statement.setString(1, parts[1]);
  64. ResultSet rset = statement.executeQuery();
  65. int objId = 0;
  66. if (rset.next())
  67. {
  68. objId = rset.getInt(1);
  69. }
  70. rset.close();
  71. statement.close();
  72. if (objId == 0)
  73. {
  74. con.close();
  75. return;
  76. }
  77. //connection = L2DatabaseFactory.getInstance().getConnection();
  78. statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
  79. statement.setInt(1, objId);
  80. statement.execute();
  81. statement.close();
  82. //connection = L2DatabaseFactory.getInstance().getConnection();
  83. statement = con.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?");
  84. statement.setInt(1, objId);
  85. statement.execute();
  86. statement.close();
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.WARNING, "could not repair char:", e);
  91. }
  92. }
  93. }