Exemplo n.º 1
0
 // create/split item stack
 private ItemStack getSplitItemStack(
     int itemRowId, int itemId, short itemDamage, int qty, String enchStr) {
   ItemStack stack = new ItemStack(itemId, qty, itemDamage);
   int maxSize = stack.getMaxStackSize();
   // split stack
   if (qty > maxSize) {
     Connection conn = WebAuctionPlus.dataQueries.getConnection();
     PreparedStatement st = null;
     while (qty > maxSize) {
       try {
         if (WebAuctionPlus.isDebug())
           WebAuctionPlus.log.info(
               "WA Query: getSplitItemStack  qty:"
                   + Integer.toString(qty)
                   + "  max:"
                   + Integer.toString(maxSize));
         st =
             conn.prepareStatement(
                 "INSERT INTO `"
                     + WebAuctionPlus.dataQueries.dbPrefix()
                     + "Items` ( "
                     + "`playerName`, `itemId`, `itemDamage`, `qty`, `enchantments` )VALUES( ?, ?, ?, ?, ? )");
         st.setString(1, playerName);
         st.setInt(2, itemId);
         st.setShort(3, itemDamage);
         st.setInt(4, maxSize);
         st.setString(5, enchStr);
         st.executeUpdate();
       } catch (SQLException e) {
         WebAuctionPlus.log.warning(
             WebAuctionPlus.logPrefix + "Unable to insert new item to inventory!");
         e.printStackTrace();
         return null;
       } finally {
         WebAuctionPlus.dataQueries.closeResources(st, null);
       }
       qty -= maxSize;
     }
     stack.setAmount(qty);
     WebAuctionPlus.dataQueries.closeResources(conn);
   }
   // add enchantments
   if (enchStr != null && !enchStr.isEmpty())
     DataQueries.decodeEnchantments(Bukkit.getPlayer(playerName), stack, enchStr);
   return stack;
 }