Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
2
Indexable
Never
package ballistickemu.Lobby.handlers;

import ballistickemu.Tools.DatabaseTools;
import ballistickemu.Types.StickClient;
import ballistickemu.Types.StickItem;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.PreparedStatement;


public class SetActiveItemRequestHandler
{
  public static void HandlePacket(StickClient client, String packet)
  {
    try
    {
      if (packet.replaceAll("\000", "").equalsIgnoreCase("0d1"))
        return;
      if (packet.indexOf("undefined") != -1) {
        return;
      }
      int itemDBID = Integer.valueOf(packet.substring(2, packet.length() - 1)).intValue();
      StickItem toChange = client.getItemByID(itemDBID);
      if (toChange != null)
      {

        client.setSelectedItem(toChange.getitemType(), itemDBID);
        PreparedStatement ps = DatabaseTools.getDbConnection().prepareStatement("UPDATE `inventory` SET `selected` = 0 WHERE `itemtype` = ? AND `userid` = ?");
        ps.setInt(1, toChange.getitemType());
        ps.setInt(2, toChange.getUserDBID());
        ps.executeUpdate();
        ps = DatabaseTools.getDbConnection().prepareStatement("UPDATE `inventory` SET `selected` = 1 WHERE `id` = ? AND `userid` = ?");
        ps.setInt(1, toChange.getItemDBID());
        ps.setInt(2, toChange.getUserDBID());
        ps.executeUpdate();

      }
      else
      {
        System.out.println("Error setting active thingy as it was null or something.");
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}