AdminRepairChar.java 3.5 KB

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