package commands.admin;
import l2p.database.DatabaseUtils;
import l2p.database.FiltredPreparedStatement;
import l2p.database.L2DatabaseFactory;
import l2p.database.ThreadConnection;
import l2p.extensions.scripts.ScriptFile;
import l2p.gameserver.handler.AdminCommandHandler;
import l2p.gameserver.handler.IAdminCommandHandler;
import l2p.gameserver.model.L2Player;
import java.sql.ResultSet;
@SuppressWarnings("unused")
public class AdminRepairChar implements IAdminCommandHandler, ScriptFile
{
private static enum Commands
{
admin_restore,
admin_repair
}
public boolean useAdminCommand(Enum comm, String[] wordList, String fullString, L2Player activeChar)
{
Commands command = (Commands) comm;
if(activeChar.getPlayerAccess() == null || !activeChar.getPlayerAccess().CanEditChar)
{
return false;
}
if(wordList.length != 2)
{
return false;
}
String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
ResultSet rset = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(cmd);
statement.setString(1, wordList[1]);
statement.execute();
DatabaseUtils.closeStatement(statement);
statement = con.prepareStatement("SELECT obj_id FROM characters where char_name=?");
statement.setString(1, wordList[1]);
rset = statement.executeQuery();
int objId = 0;
if(rset.next())
{
objId = rset.getInt(1);
}
DatabaseUtils.closeDatabaseSR(statement, rset);
if(objId == 0)
{
return false;
}
// con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("DELETE FROM character_shortcuts WHERE char_obj_id=?");
statement.setInt(1, objId);
statement.execute();
DatabaseUtils.closeStatement(statement);
// con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE items SET loc='INVENTORY' WHERE owner_id=? AND loc!='WAREHOUSE'");
statement.setInt(1, objId);
statement.execute();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DatabaseUtils.closeDatabaseCSR(con, statement, rset);
}
return true;
}
public Enum[] getAdminCommandEnum()
{
return Commands.values();
}
public void onLoad()
{
AdminCommandHandler.getInstance().registerAdminCommandHandler(this);
}
public void onReload()
{
}
public void onShutdown()
{
}
}