AdminRepairChar.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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.sql.ResultSet;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import com.l2jserver.L2DatabaseFactory;
  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. String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
  59. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  60. {
  61. PreparedStatement statement = con.prepareStatement(cmd);
  62. statement.setString(1, parts[1]);
  63. statement.execute();
  64. statement.close();
  65. statement = con.prepareStatement("SELECT charId FROM characters where char_name=?");
  66. statement.setString(1, parts[1]);
  67. ResultSet rset = statement.executeQuery();
  68. int objId = 0;
  69. if (rset.next())
  70. {
  71. objId = rset.getInt(1);
  72. }
  73. rset.close();
  74. statement.close();
  75. if (objId == 0)
  76. {
  77. con.close();
  78. return;
  79. }
  80. // connection = L2DatabaseFactory.getInstance().getConnection();
  81. statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
  82. statement.setInt(1, objId);
  83. statement.execute();
  84. statement.close();
  85. // connection = L2DatabaseFactory.getInstance().getConnection();
  86. statement = con.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?");
  87. statement.setInt(1, objId);
  88. statement.execute();
  89. statement.close();
  90. }
  91. catch (Exception e)
  92. {
  93. _log.log(Level.WARNING, "could not repair char:", e);
  94. }
  95. }
  96. }